added way to load savegames

This commit is contained in:
Eljakim Herrewijnen 2021-04-15 22:14:31 +02:00
parent bbc1e6f24e
commit 7a89f57ee5
9 changed files with 99 additions and 5 deletions

View File

@ -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):

View File

@ -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"]

View File

@ -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)

View File

@ -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

View File

@ -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")

BIN
Savegames/Storage.db Normal file

Binary file not shown.

BIN
Savegames/item.db Normal file

Binary file not shown.

BIN
Savegames/storage.db Normal file

Binary file not shown.

View File

@ -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