[gd_scene load_steps=11 format=1]

[ext_resource path="res://Energy.tscn" type="PackedScene" id=1]
[ext_resource path="res://bubbles_counter.tscn" type="PackedScene" id=2]
[ext_resource path="res://font/titilium-bold.fnt" type="BitmapFont" id=3]
[ext_resource path="res://store.tscn" type="PackedScene" id=4]
[ext_resource path="res://misc/Brand New World.ogg" type="AudioStream" id=5]

[sub_resource type="GDScript" id=1]

script/source = "extends Control\n\nvar currMap;\n\nfunc _enter_tree():\n\tGlobals.set(\"map_control\", self);\n\nfunc _ready():\n\tload_map();\n\t\n\tpass;\nfunc next_map():\n\tGlobals.get(\"game_saver\").savedict.currLevel += 1;\n\tGlobals.get(\"game_saver\").saveData();\n\tget_tree().reload_current_scene();\n\t\nfunc load_map():\n\tif(currMap):\n\t\tremove_child(currMap);\n\t\n\tvar map = load((\"res://maps/map%d\"%Globals.get(\"game_saver\").savedict.currLevel)+\".tscn\");\n\tif(!map): \n\t\tget_node(\"CanvasLayer/reset1\").set_hidden(false);\n\t\treturn;\n\t\n\tcurrMap = map.instance();\n\tadd_child(currMap);"

[sub_resource type="GDScript" id=2]

script/source = "extends Camera2D\n\nvar mouseHolded = false;\n\nfunc _ready():\n\tset_process_input(true)\n\tset_process(true);\n\t\nfunc _process(delta):\n\tif(Input.is_mouse_button_pressed(BUTTON_RIGHT)):\n\t\tmouseHolded = true;\n\telse:\n\t\tmouseHolded = false;\n\nfunc _input( ev ):\n\tif (ev.type == InputEvent.MOUSE_BUTTON):\n\t\tif(ev.button_index == BUTTON_WHEEL_UP && get_zoom().x > 0.5):\n\t\t\tset_zoom(get_zoom()-Vector2(0.3,0.3));\n\t\telif(ev.button_index == BUTTON_WHEEL_DOWN && get_zoom().x < 5):\n\t\t\tset_zoom(get_zoom()+Vector2(0.3,0.3));\n\tif(ev.type == InputEvent.MOUSE_MOTION && mouseHolded):\n\t\tset_pos(get_pos()-ev.relative_pos*get_scale().x*2);\n\tpass # replace with function body\n"

[sub_resource type="GDScript" id=3]

script/source = "\nvar hidden = true;\n\nfunc _on_restartButton_pressed():\n\thidden = !hidden;\n\tget_node(\"../store\").set_hidden(hidden);\n\tpass # replace with function body\n"

[sub_resource type="GDScript" id=4]

script/source = "\n\n\nfunc _on_Button_pressed():\n\tGlobals.get(\"game_saver\").saveData();\n\tget_tree().reload_current_scene();\n\tpass # replace with function body\n"

[sub_resource type="GDScript" id=5]

script/source = "extends Node\n\nvar savedict = {\n        money=0,\n        explodeForce=200,\n        dumping=4, #Vector2 is not supported by json\n        infectPower=200,\n\t\tmaxEnergy = 100,\n\t\tcurrLevel = 2,\n\t\texplodeUpgradeLevel=0,\n\t\tdumpingUpgradeLevel=0,\n\t\tinfectUpgradeLevel=0,\n\t\tenergyUpgradeLevel=0,\n}\n\nfunc _resetAll():\n\tvar dir = Directory.new(); dir.remove(\"user://savegame.save\");\n\tget_tree().reload_current_scene();\n\nfunc _enter_tree():\n\tGlobals.set(\"game_saver\", self);\n\tloadData();\n\n\nfunc loadData():\n\tvar savegame = File.new()\n\tif !savegame.file_exists(\"user://savegame.save\"):\n\t\treturn #Error!  We don\'t have a save to load\n\t\n\tvar currentline = {} # dict.parse_json() requires a declared dict.\n\tsavegame.open(\"user://savegame.save\", File.READ)\n\twhile (!savegame.eof_reached()):\n\t\tcurrentline.parse_json(savegame.get_line())\n\t\t\n\t\tsavedict.money = currentline[\"money\"];\n\t\tsavedict.explodeForce = currentline[\"explodeForce\"];\n\t\tsavedict.dumping = currentline[\"dumping\"];\n\t\tsavedict.infectPower = currentline[\"infectPower\"];\n\t\tsavedict.maxEnergy = currentline[\"maxEnergy\"];\n\t\tsavedict.currLevel = currentline[\"currLevel\"];\n\t\tsavedict.explodeUpgradeLevel = currentline[\"explodeUpgradeLevel\"];\n\t\tsavedict.dumpingUpgradeLevel = currentline[\"dumpingUpgradeLevel\"];\n\t\tsavedict.infectUpgradeLevel = currentline[\"infectUpgradeLevel\"];\n\t\tsavedict.energyUpgradeLevel = currentline[\"energyUpgradeLevel\"];\n\tpass;\n\nfunc saveData():\n\tprint(savedict);\n\tvar savegame = File.new();\n\tsavegame.open(\"user://savegame.save\", File.WRITE);\n\tsavegame.store_line(savedict.to_json())\n\tsavegame.close();\n\tpass;"

[node name="Control" type="Control"]

focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 0.0
margin/right = 40.0
margin/bottom = 40.0
script/script = SubResource( 1 )

[node name="Camera2D" type="Camera2D" parent="."]

transform/pos = Vector2( 1445.98, 915.546 )
anchor_mode = 1
rotating = false
current = true
zoom = Vector2( 3, 3 )
limit/left = -10000
limit/top = -10000
limit/right = 10000
limit/bottom = 10000
drag_margin/h_enabled = false
drag_margin/v_enabled = false
smoothing/enable = true
smoothing/speed = 5.0
drag_margin/left = 0.1
drag_margin/top = 0.1
drag_margin/right = 0.1
drag_margin/bottom = 0.1
script/script = SubResource( 2 )

[node name="CanvasLayer" type="CanvasLayer" parent="."]

layer = 1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )

[node name="Energy" parent="CanvasLayer" instance=ExtResource( 1 )]

anchor/top = 1
anchor/bottom = 1
rect/rotation = 90.0
size_flags/horizontal = 3
size_flags/vertical = 3
margin/left = 12.0
margin/top = 9.0
margin/right = 215.0
margin/bottom = -15.0

[node name="bubbles_counter" parent="CanvasLayer" instance=ExtResource( 2 )]

[node name="restartButton" type="Button" parent="CanvasLayer"]

visibility/visible = false
anchor/left = 1
anchor/top = 1
anchor/right = 1
anchor/bottom = 1
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 186.0
margin/top = 83.0
margin/right = 17.0
margin/bottom = 15.0
custom_fonts/font = ExtResource( 3 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
text = "shop"
flat = false
script/script = SubResource( 3 )

[node name="store" parent="CanvasLayer" instance=ExtResource( 4 )]

visibility/visible = false
anchor/left = 3
anchor/top = 3
anchor/right = 3
anchor/bottom = 3
margin/left = 579.0
margin/top = 364.0
margin/right = 579.0
margin/bottom = 364.0

[node name="reset" type="Button" parent="CanvasLayer"]

visibility/opacity = 0.1
anchor/left = 1
anchor/right = 1
hint/tooltip = "discard all saves"
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 47.0
margin/top = 2.0
margin/right = 2.0
margin/bottom = 22.0
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
text = "reset"
flat = false

[node name="reset1" type="Button" parent="CanvasLayer"]

visibility/visible = false
anchor/right = 1
anchor/bottom = 1
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 534.0
margin/top = 294.0
margin/right = 547.0
margin/bottom = 326.0
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
text = "reset game\?"
flat = false

[node name="restart" type="Button" parent="CanvasLayer"]

visibility/opacity = 0.7
anchor/left = 1
anchor/right = 1
hint/tooltip = "restart current level"
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 56.0
margin/top = 35.0
margin/right = 2.0
margin/bottom = 55.0
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
text = "restart"
flat = false
script/script = SubResource( 4 )

[node name="saver" type="Node" parent="."]

script/script = SubResource( 5 )

[node name="StreamPlayer" type="StreamPlayer" parent="."]

stream/stream = ExtResource( 5 )
stream/play = true
stream/loop = true
stream/volume_db = 0.0
stream/autoplay = true
stream/paused = false
stream/loop_restart_time = 0.0
stream/buffering_ms = 500

[connection signal="pressed" from="CanvasLayer/restartButton" to="CanvasLayer/restartButton" method="_on_restartButton_pressed"]

[connection signal="pressed" from="CanvasLayer/reset" to="saver" method="_resetAll"]

[connection signal="pressed" from="CanvasLayer/reset1" to="saver" method="_resetAll"]

[connection signal="pressed" from="CanvasLayer/restart" to="CanvasLayer/restart" method="_on_Button_pressed"]


