#EDITOR
#gradient
Gradient.SetColour1(100,HashTable("gradC1"))
Gradient.SetColour2(100,HashTable("gradC2"))
Gradient.SetGradientDirection(HashTable("gradDir"))

###################################################
#Rules
###################################################

if HashTable.KeyExists("GameMode") == 1:
    if HashTable("GameMode") == "Reactor":
    	CGUI.ComboBoxSetIndexSelected("gamemode",1)
    else:
    	CGUI.ComboBoxSetIndexSelected("gamemode",0)
else:
    System.SetGlobalVar("gamemode", "")

CGUI.TextBoxSetCaption("linelimit", HashTable("LineCountLimit"))
CGUI.TextBoxSetCaption("linewidthlimit", HashTable("LineWidthLimit"))
CGUI.TextBoxSetCaption("gravity", int(HashTable("GravityChangeTime")))

if HashTable.KeyExists("GravityStartDirection"):
	btn_GravDown = HashTable("GravityStartDirection")

###################################################
#
###################################################
if HashTable("music") != "":
		System.SetGlobalVar('music', HashTable("music"))
		
if HashTable("SpriteList") != "":
		loadSpriteList = eval(HashTable("SpriteList"))

if len(loadSpriteList) == 0:
	loadSpriteList.append("1")
	
createBg(HashTable("SpriteCount"))

bg.SetWidth(bg.OriginalWidth)
bg.SetHeight(bg.OriginalHeight)
bg.LoadFrameFromFile(System.AppPath + "bg/" + str(HashTable("bg")))
bg.SetWidth(System.LayoutWidth * 2)
bg.SetHeight(System.LayoutHeight * 2)
bg.SetOpacity(HashTable("bg_opacity"))

System.SetGlobalVar('bg', str(HashTable("bg")))

################################################
# TiledBackground - tb
################################################

tb.SetWidth(100)
tb.SetHeight(100)
tb.LoadFromFile(System.AppPath + "bg/" + str(HashTable("bg")))
tb.SetWidth(2200)
tb.SetHeight(1400)
tb.SetOpacity(int(HashTable("bg_opacity")))

################################################

Audiere.LoadMusic(HashTable("music"), "music", 1, 100, 0.0, 1.0, 1)

#System.globalvar("var")
if System.globalvar("csap") > 0:
	HashTable.InsertKey("csapCount", csap.Count)

if System.globalvar("elevator") > 0:
	HashTable.InsertKey("liftCount", lift.Count)

if System.globalvar("hinge") > 0:	
	HashTable.InsertKey("hinge", hinge.Count)

if System.globalvar("rotating") > 0:	
	HashTable.InsertKey("rotating", rotating.Count)


################################################
#	gravity
################################################
if HashTable.KeyExists("gravity") == 1:
	if HashTable("gravity") < 0:
		#up
		for i in SpriteButton:
			if i.CompareButtonIdentifier("gravity") ==1:
				i.TickButton(1)
#down or not set
else:
	for i in SpriteButton:
		if i.CompareButtonIdentifier("gravity") ==1:
			i.TickButton(0)

################################################
#	enviorment
################################################

txt = ""
for i in range(HashTable("csapCount")):
	Text.SetText(Text.Text + str(HashTable("csapPos"+ str(i))) + " - - - ")
	l = eval(HashTable("csapPos" + str(i)))
	l2 = eval(HashTable("uvegPos" + str(i)))
	System.CreateByName("csap", 2, l[0], l[1])
	
	SOL.csap.SetAngle(l[2])
	SOL.csap.SetFilter(int(l[3]))
	
	if len(l) > 4:
		if l[4] == 0:
			SOL.lock.SetValue('state', -1)
		else:
			SOL.lock.SetValue('state', 1)
	
	SOL.uveg.SetAngle(l2[2])
	SOL.uveg.SetPosition(l2[0], l2[1])
	SOL.uveg.SetFilter(int(l[3]))
	
for i in range(HashTable("liftCount")):
	Text.SetText(Text.Text + str(HashTable("liftPos"+ str(i))) + " - - - ")
	l = eval(HashTable("liftPos" + str(i)))
	l2 = eval(HashTable("lift_ePos" + str(i)))
	System.CreateByName("lift", 2, l[0], l[1])
	
	SOL.lift.SetAngle(l[2])
	SOL.lift_e.SetPosition(l2[0], l2[1])
	
for i in range(HashTable("hingeCount")):
	Text.SetText(Text.Text + str(HashTable("hingePos"+ str(i))) + " - - - ")
	l = eval(HashTable("hingePos" + str(i)))
	l2 = eval(HashTable("hinge_start" + str(i)))
	System.CreateByName("hinge", 2, l[0], l[1])
	
	SOL.hinge.SetAngle(l[2])
	SOL.hinge_start.SetPosition(l2[0], l2[1])
	
for i in range(HashTable("platCount")):
	l = eval(HashTable("p_obstacle" + str(i)))
	System.CreateByName("plat", 2, l[0], l[1])
	
	SOL.plat.SetAngle(l[2])
	SOL.plat.SetWidth(l[3])
	
for i in range(HashTable("rotatingCount")):
	Text.SetText(Text.Text + str(HashTable("hingePos"+ str(i))) + " - - - ")
	l = eval(HashTable("rotating" + str(i)))
	System.CreateByName("rotating", 2, l[0], l[1])
	
	SOL.rotating.SetAngle(l[2])
	
for i in range(HashTable("obj_textCount")):
	Text.SetText(Text.Text + str(HashTable("obj_textCount"+ str(i))) + " - - - ")
	l = eval(HashTable("obj_text" + str(i)))
	System.CreateByName("obj_text", 2, l[0], l[1])
	
	SOL.obj_text.SetText(l[2])
	SOL.obj_text.SetTextColour(l[3])
	SOL.obj_text.SetWidth(l[4])
	SOL.obj_text.SetHeight(l[5])
	
for i in range(HashTable("arrowCount")):
	l = eval(HashTable("arrow" + str(i)))
	System.CreateByName("arrow", 2, 0, 0)
	
	SOL.arrowstart.SetPosition(l[0], l[1])
	SOL.arrowdest.SetPosition(l[2], l[3])
	SOL.Arrow.SetPosition(l[0], l[1])
	SOL.Arrow.SetAngle(System.angle(SOL.arrowstart.Y, SOL.arrowstart.Y, SOL.arrowdest.Y, SOL.arrowdest.Y))
	
	#path movement setup
	SOL.ArrowPathMovement.ClearNodes()
	SOL.ArrowPathMovement.AddNode(SOL.arrowstart.X,SOL.arrowstart.Y)
	SOL.ArrowPathMovement.AddNode(SOL.arrowdest.X, SOL.arrowdest.Y)
	
for i in range(HashTable("pushbtnCount")):
	l = eval(HashTable("pushbtn" + str(i)))
	System.CreateByName("pushbtn", 2, l[0], l[1])
	
	SOL.pushbtn.SetFilter(int(l[2]))
	
for i in range(HashTable("unlockerCount")):
	l = eval(HashTable("unlocker" + str(i)))
	System.CreateByName("unlocker", 2, l[0], l[1])
	
	SOL.unlocker.SetFilter(int(l[2]))

#portals
for i in range(HashTable("portalRedCount")):
	l = eval(HashTable("portalRed" + str(i)))
	System.CreateByName("PortalRed", 2, l[0], l[1])

	SOL.PortalRed.SetAngle(l[2])
	SOL.PortalRed.SetFilter(l[3])

for i in range(HashTable("portalBlueCount")):
	l = eval(HashTable("portalBlue" + str(i)))
	System.CreateByName("PortalBlue", 2, l[0], l[1])

	SOL.PortalBlue.SetAngle(l[2])
	SOL.PortalBlue.SetFilter(l[3])

#electric in
for i in range(HashTable("electric1Count")):
	l = eval(HashTable("p_elect" + str(i)))
	System.CreateByName("p_elect", 2, l[0], l[1])

	SOL.p_elect.SetAngle(l[2])

#electric out
for i in range(HashTable("electric2Count")):
	l = eval(HashTable("p_elect2" + str(i)))
	System.CreateByName("p_elect2", 2, l[0], l[1])

	SOL.p_elect2.SetAngle(l[2])

#saw
for i in range(HashTable("sawCount")):
	l = eval(HashTable("p_saw" + str(i)))
	System.CreateByName("p_saw", 2, l[0], l[1])
	SOL.saw_path.SetPosition(l[2],l[3])
	SOL.saw_path2.SetPosition(l[4],l[5])
	
	
	if len(l)> 6:
		SOL.saw_lock.SetValue('state', l[6])

#trapdoor
for i in range(HashTable("trapdoorCount")):
	l = eval(HashTable("trapdoor" + str(i)))
	System.CreateByName("p_trapdoor", 2, l[0], l[1])

	SOL.p_trapdoor.SetAngle(l[2])
	SOL.BoxTrapdoor.SetPosition(l[3], l[4])

###############################################################################################################################################
#													REACTOR
#reactor zone
###############################################################################################################################################
for i in range(HashTable("reactorCount")):
	l = eval(HashTable("reactor" + str(i)))
	System.CreateByName("reactor_zone", 2, l[0], l[1])

	SOL.reactor_zone.SetAngle(l[2])
	SOL.reactor_zone.SetWidth(l[3])
	SOL.reactor_zone.SetHeight(l[4])