Ran into problems with saveing and loading of data. Need to decide how we are going to do the data storage.

This commit is contained in:
Luke Gebbink 2021-10-03 13:00:39 -06:00
parent 48ceaf73c3
commit 8eacdf1654
5 changed files with 138 additions and 9 deletions

View File

@ -35,25 +35,33 @@ custom_constants/separation = 30
alignment = 1 alignment = 1
[node name="Start Game" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"] [node name="Start Game" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"]
margin_top = 169.0 margin_top = 147.0
margin_right = 112.0 margin_right = 112.0
margin_bottom = 183.0 margin_bottom = 161.0
mouse_filter = 1 mouse_filter = 1
text = "Start Game" text = "Start Game"
script = ExtResource( 3 ) script = ExtResource( 3 )
[node name="HostAndJoinGame" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"] [node name="Load Game" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"]
margin_top = 213.0 margin_top = 191.0
margin_right = 112.0 margin_right = 112.0
margin_bottom = 227.0 margin_bottom = 205.0
mouse_filter = 1
text = "Load Game"
script = ExtResource( 3 )
[node name="HostAndJoinGame" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"]
margin_top = 235.0
margin_right = 112.0
margin_bottom = 249.0
mouse_filter = 1 mouse_filter = 1
text = "Host / Join Game" text = "Host / Join Game"
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="Player Settings" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"] [node name="Player Settings" type="Label" parent="HBoxContainer/VBoxContainer/MenuOptions"]
margin_top = 257.0 margin_top = 279.0
margin_right = 112.0 margin_right = 112.0
margin_bottom = 271.0 margin_bottom = 293.0
mouse_filter = 1 mouse_filter = 1
text = "Player Settings" text = "Player Settings"
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -72,5 +80,6 @@ margin_right = 367.0
margin_bottom = 227.0 margin_bottom = 227.0
text = "Test Menu" text = "Test Menu"
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/Start Game" to="HBoxContainer/VBoxContainer/MenuOptions/Start Game" method="_on_Start_Game_gui_input"] [connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/Start Game" to="HBoxContainer/VBoxContainer/MenuOptions/Start Game" method="_on_Start_Game_gui_input"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/Load Game" to="HBoxContainer/VBoxContainer/MenuOptions/Load Game" method="_on_Start_Game_gui_input"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/HostAndJoinGame" to="HBoxContainer/VBoxContainer/MenuOptions/HostAndJoinGame" method="_on_HostAndJoinGame_gui_input"] [connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/HostAndJoinGame" to="HBoxContainer/VBoxContainer/MenuOptions/HostAndJoinGame" method="_on_HostAndJoinGame_gui_input"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/Player Settings" to="HBoxContainer/VBoxContainer/MenuOptions/Player Settings" method="_on_Player_Settings_gui_input"] [connection signal="gui_input" from="HBoxContainer/VBoxContainer/MenuOptions/Player Settings" to="HBoxContainer/VBoxContainer/MenuOptions/Player Settings" method="_on_Player_Settings_gui_input"]

View File

@ -0,0 +1,21 @@
extends Resource
# Authors Luke Gebbink
# Last Changed 10/03/2021
# found
#
class_name SaveGame
export var game_version : String = ''
export var data : Dictionary = {}
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -0,0 +1,36 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var time_start = 0
var time_now = 0
class_name WorldObject
var Players: String = ''
var Scene: Scene
var History: = Array()
var decisions:
var totalTime:
# Called when the node enters the scene tree for the first time.
func _ready():
time_start = OS.get_unix_time()
set_process(true)
# Should we tie time to the save files or the application?
# I would think the save files.
func _process(delta):
time_now = OS.get_unix_time()
var elapsed = time_now - time_start
var minutes = elapsed / 60
var seconds = elapsed % 60
var str_elapsed = "%02d : %02d" % [minutes, seconds]
print("elapsed : ", str_elapsed)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -0,0 +1,43 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
const SaveGame = preload('res://SaveSystem/GameSave.gd')
var SAVE_FOLDER : String = "res://SaveSystem/SaveLocations"
var SAVE_NAME_TEMPLATE : String = "save_%03D.tres"
func save(id : int):
"""
Passes a save game resource to all nodes to save data from and writes it to the disk
Modfied from GDQuest's Godot Lesson Found Here: https://www.youtube.com/watch?v=ML-hiNytIqE
"""
var save_game := SaveGame.new()
save_game.game_version = ProjectSettings.get_setting("application/config/version")
for node in get_tree().get_nodes_in_group('save'):
node.save(save_game)
var directory : Directory = Directory.new()
if not directory.dir.exists(SAVE_FOLDER):
directory.make_dir_recursive(SAVE_FOLDER)
var save_path = SAVE_FOLDER.plus_file(SAVE_NAME_TEMPLATE % id)
var error : int = ResourceSaver.save(save_path, save_game)
if error != OK:
print('There was an issue writing the save %s to %s' % [id, save_path])
func load(id : int):
var save_file_path : String = SAVE_FOLDER.plus_file(SAVE_NAME_TEMPLATE % id)
var file : File = File.new()
if not file.file_exists(save_file_path):
print("Save file %s doesn't exist" % save_file_path)
return
var save_game : Resource = load(save_file_path)
for node in get_tree().get_nodes_in_group('save'):
node.load(save_game)

View File

@ -8,9 +8,20 @@
config_version=4 config_version=4
_global_script_classes=[ ] _global_script_classes=[ {
"base": "Resource",
"class": "SaveGame",
"language": "GDScript",
"path": "res://SaveSystem/GameSave.gd"
}, {
"base": "Node",
"class": "WorldObject",
"language": "GDScript",
"path": "res://SaveSystem/SceneObject.gd"
} ]
_global_script_class_icons={ _global_script_class_icons={
"SaveGame": "",
"WorldObject": ""
} }
[application] [application]
@ -18,6 +29,15 @@ _global_script_class_icons={
config/name="Godot Ui" config/name="Godot Ui"
run/main_scene="res://GUI.tscn" run/main_scene="res://GUI.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
config/Version="0.001"
[config]
description=""
[global]
description=""
[rendering] [rendering]