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 0000000..5864933 Binary files /dev/null and b/Savegames/Storage.db differ diff --git a/Savegames/item.db b/Savegames/item.db new file mode 100644 index 0000000..5864933 Binary files /dev/null and b/Savegames/item.db differ diff --git a/Savegames/storage.db b/Savegames/storage.db new file mode 100644 index 0000000..ffab058 Binary files /dev/null and b/Savegames/storage.db differ 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