From 7a89f57ee5131f088622d90ccf9a6e9f40a30c00 Mon Sep 17 00:00:00 2001 From: Eljakim Herrewijnen Date: Thu, 15 Apr 2021 22:14:31 +0200 Subject: [PATCH] added way to load savegames --- Global.gd | 13 +++++++++--- Menu.tscn | 14 +++++++++++++ MenuScenes/LoadGame_Menu.gd | 33 +++++++++++++++++++++++++++++++ MenuScenes/LoadGame_Menu.tscn | 36 ++++++++++++++++++++++++++++++++++ MiscCodes/Menu.gd | 3 +++ Savegames/Storage.db | Bin 0 -> 8192 bytes Savegames/item.db | Bin 0 -> 8192 bytes Savegames/storage.db | Bin 0 -> 8192 bytes Storage/Database.gd | 5 +++-- 9 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 MenuScenes/LoadGame_Menu.gd create mode 100644 MenuScenes/LoadGame_Menu.tscn create mode 100644 Savegames/Storage.db create mode 100644 Savegames/item.db create mode 100644 Savegames/storage.db diff --git a/Global.gd b/Global.gd index 7443a30..5a0dc52 100644 --- a/Global.gd +++ b/Global.gd @@ -5,9 +5,11 @@ var LeftClick = 0 var player_inventory_items = [] var river_intersection_home_2 = preload("res://river_intersection_home2.tscn").instance() var inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance() +var loadgame_screen = null var current_scene = null var current_camera = null var dev_stats = true +var dbname = "storage.db" func AddInventoryItem(itemid, amount): for x in range(40): @@ -37,8 +39,13 @@ func GoToScene(scene): inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance() current_scene = inventory_screen get_tree().get_root().add_child(inventory_screen) + "loadgame_screen": + loadgame_screen = preload("res://MenuScenes/LoadGame_Menu.tscn").instance() + current_scene = loadgame_screen + get_tree().get_root().add_child(loadgame_screen) -func LoadSave(): +func LoadSave(target="Storage.db"): + dbname = target Database.OpenConnection() #Save everything @@ -50,8 +57,8 @@ func _input(event): pass func _ready(): - get_tree().get_root().add_child(river_intersection_home_2) - get_tree().get_root().add_child(inventory_screen) +# get_tree().get_root().add_child(river_intersection_home_2) +# get_tree().get_root().add_child(inventory_screen) pass func Log(msg, level=1): diff --git a/Menu.tscn b/Menu.tscn index dcb5e87..13d8317 100644 --- a/Menu.tscn +++ b/Menu.tscn @@ -36,9 +36,23 @@ margin_left = 484.204 margin_top = 100.226 margin_right = 679.204 margin_bottom = 153.226 +rect_pivot_offset = Vector2( 46.6684, 19.1049 ) custom_fonts/font = SubResource( 2 ) text = "Play Game" __meta__ = { "_edit_use_anchors_": false } + +[node name="Btn_LoadGame" type="Button" parent="."] +margin_left = 484.01 +margin_top = 158.594 +margin_right = 679.01 +margin_bottom = 211.594 +rect_pivot_offset = Vector2( 46.6684, 19.1049 ) +custom_fonts/font = SubResource( 2 ) +text = "Load Game" +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="pressed" from="Btn_PlayGame" to="." method="_on_Btn_PlayGame_pressed"] +[connection signal="pressed" from="Btn_LoadGame" to="." method="_on_Btn_LoadGame_pressed"] diff --git a/MenuScenes/LoadGame_Menu.gd b/MenuScenes/LoadGame_Menu.gd new file mode 100644 index 0000000..61e1586 --- /dev/null +++ b/MenuScenes/LoadGame_Menu.gd @@ -0,0 +1,33 @@ +extends Node2D + +var savegames = [] +var savegamepath = "res://Savegames" + +func getsave_games(path): + var dir = Directory.new() + dir.open(path) + dir.list_dir_begin() + + while true: + var file = dir.get_next() + if file == "": + break + elif file.ends_with(".db"): + savegames.append(file) + dir.list_dir_end() + +func load_and_play(name): + Global.LoadSave(name) + Global.GoToScene("river_intersection_home_2") + +func _ready(): + if(OS.get_name() == "Android"): + savegamepath = "user://Savegames" + getsave_games(savegamepath) + for item in savegames: + var button1 = Button.new() + button1.text = item + button1.connect("pressed", self, "load_and_play", ["item"]) + button1.show() + get_node("ScrollContainer/VBoxContainer").add_child(button1) + diff --git a/MenuScenes/LoadGame_Menu.tscn b/MenuScenes/LoadGame_Menu.tscn new file mode 100644 index 0000000..994501d --- /dev/null +++ b/MenuScenes/LoadGame_Menu.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://MenuScenes/LoadGame_Menu.gd" type="Script" id=1] +[ext_resource path="res://pictures/gui/backgrounds/treesbackground1.png" type="Texture" id=5] + +[sub_resource type="Theme" id=1] + +[node name="Loading Games Menu" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Background" type="TextureRect" parent="."] +margin_right = 1234.0 +margin_bottom = 768.0 +texture = ExtResource( 5 ) +stretch_mode = 2 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ScrollContainer" type="ScrollContainer" parent="."] +margin_left = 123.0 +margin_top = 162.0 +margin_right = 1113.0 +margin_bottom = 690.0 +theme = SubResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"] +margin_right = 990.0 +margin_bottom = 528.0 +grow_horizontal = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +custom_constants/separation = 2 diff --git a/MiscCodes/Menu.gd b/MiscCodes/Menu.gd index 41fc6a5..e64fd6b 100644 --- a/MiscCodes/Menu.gd +++ b/MiscCodes/Menu.gd @@ -7,3 +7,6 @@ func _on_Btn_PlayGame_pressed(): Global.LoadSave() Global.GoToScene("river_intersection_home_2") +func _on_Btn_LoadGame_pressed(): + Global.GoToScene("loadgame_screen") + diff --git a/Savegames/Storage.db b/Savegames/Storage.db new file mode 100644 index 0000000000000000000000000000000000000000..5864933d2fdcb59110f62b1513f7f66638af5a96 GIT binary patch literal 8192 zcmeI#O-~a+9LMq5icsu4fTCCs{mX;22@n%8@n~r_rm+;L<-kG60%KaGU9&8P9yP%? zpf5n*fW81ZaZ+9Yz5w9`=nGJ%2MUt>;>pCrf3lO^$!B&B-`hM|DAr<2Pr|4k#B@jW z2+tGuiG&bYHxq6i56^vc9539vwf@`4imCjba=Sb;A>6}*3vdB0zy-Jf7vKV1fD3Q| zF2Du2z<*!h<$~AMKRM~WT8x9$4f}i}XxeC{)_7qXaTqnvt`qsPpR4#($;}jfI;)ha zty7^?@gMkQnlBe-bLAy^=r2)eu0o~7VsXOV%j+wrHvI{Wpl&I)+wsW{K|S1R#O*`d z`!}m$6tCOOHCn3%QRd$5Z2O;V>u#P&eHP}(?3<6~t!bKNlQ$Wo^bh@2@9OvZwSK1O z^<6!neyKzCMSW0j)V6x8X4JTn^1D2cpX58aBcIASIW5zvpQ&%|KptFx3vdB0zy-Jf z7vKV1fD8Py0_pKiksM5pl|m}GdxLwmt`AhTkxk#iG=^yu(+H+vOgAwRrW=^9V;aJA z4bvc|0ZeI3S26Wtx`OF4ranxUFkQsdi>U{b!K5)MOcGNH(*;c3n39;fFm+-&kEsLG MIZO#m9wq_lH)P9)h5!Hn literal 0 HcmV?d00001 diff --git a/Savegames/item.db b/Savegames/item.db new file mode 100644 index 0000000000000000000000000000000000000000..5864933d2fdcb59110f62b1513f7f66638af5a96 GIT binary patch literal 8192 zcmeI#O-~a+9LMq5icsu4fTCCs{mX;22@n%8@n~r_rm+;L<-kG60%KaGU9&8P9yP%? zpf5n*fW81ZaZ+9Yz5w9`=nGJ%2MUt>;>pCrf3lO^$!B&B-`hM|DAr<2Pr|4k#B@jW z2+tGuiG&bYHxq6i56^vc9539vwf@`4imCjba=Sb;A>6}*3vdB0zy-Jf7vKV1fD3Q| zF2Du2z<*!h<$~AMKRM~WT8x9$4f}i}XxeC{)_7qXaTqnvt`qsPpR4#($;}jfI;)ha zty7^?@gMkQnlBe-bLAy^=r2)eu0o~7VsXOV%j+wrHvI{Wpl&I)+wsW{K|S1R#O*`d z`!}m$6tCOOHCn3%QRd$5Z2O;V>u#P&eHP}(?3<6~t!bKNlQ$Wo^bh@2@9OvZwSK1O z^<6!neyKzCMSW0j)V6x8X4JTn^1D2cpX58aBcIASIW5zvpQ&%|KptFx3vdB0zy-Jf z7vKV1fD8Py0_pKiksM5pl|m}GdxLwmt`AhTkxk#iG=^yu(+H+vOgAwRrW=^9V;aJA z4bvc|0ZeI3S26Wtx`OF4ranxUFkQsdi>U{b!K5)MOcGNH(*;c3n39;fFm+-&kEsLG MIZO#m9wq_lH)P9)h5!Hn literal 0 HcmV?d00001 diff --git a/Savegames/storage.db b/Savegames/storage.db new file mode 100644 index 0000000000000000000000000000000000000000..ffab058213dd0f1658a1618273d02653571f55fd GIT binary patch literal 8192 zcmeI$O-~a+9LMq5f~C-T0JLJkhrb9?5-=ue;)z(AjcKd}YB_Kavci}aXxA*Op+`;h z4d@HdH=r*-PoC5lATK~Y8+`%lG=_pCzi=Y)@Sp5vck-Ft!}qYs?45;DJ+^c|j2b~q zS46+?JaL0a2r=W%ggbYK=We=pC+^ywA2w#hrNVpVR(WPhxPu25-~wEL3vdB0zy-Jf z7vKV1fD3Se|GvQE1+QmldfI!k7zg(@?SsvrWuujP^O0@FVbnS}PZTPCzUosoKU?zY zpi-{BM#XZ~zv)+KzEZrMuPo6me~HR-RVpu*N>grM-dNeU=wE0C4NI}zj`to28sWoc z+<9qd{Z=iE;x)UqN~^UX%3Z%a*?DGCnQtPO{vgbE^U1t1FHFlUn}W$1rGM%j{Z7Bq z&-8|#*Vpv0`mMgIkLtC0uC~=(HLE6+lt1KW`BuJ^PvyFtlUHRn{VV;&y^seN-~wEL z3vdB0zy-Jf7vKU%Rv6IHo~N1DN_T8B7|J!Xz=JG4)~U#gxL-gDHvW i7^ZGaU6>M>JV@@V)A#q|U_?^%X1q-M??I;hOW+S!O@=rC literal 0 HcmV?d00001 diff --git a/Storage/Database.gd b/Storage/Database.gd index 04a2f72..03d5178 100644 --- a/Storage/Database.gd +++ b/Storage/Database.gd @@ -1,7 +1,7 @@ extends Node const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns") -var path = "res://storage.db" +var path = "res://Savegames/" var db_name = "RingOfRaces" var db = null var verbose = true @@ -52,7 +52,8 @@ func CreateWorldDatabase(): func OpenConnection(): if(str(OS.get_name()) == "Android"): - path = "user://storage.db" + path = "user://Savegames/" + path += Global.dbname self.db = SQLite.new() var file = File.new() self.db.path = path