Game #3: Space Shooter
This commit is contained in:
parent
a00e9b59c9
commit
f785a24c14
45 changed files with 927 additions and 0 deletions
28
space-shooter/Scenes/SaveLoad.gd
Normal file
28
space-shooter/Scenes/SaveLoad.gd
Normal file
|
@ -0,0 +1,28 @@
|
|||
extends Node
|
||||
|
||||
# Use user://save.json to automatically use user app config folders
|
||||
# Leaving as res to avoid storing json files for test games
|
||||
const SAVE_DATA_PATH = "res://save.json"
|
||||
|
||||
var default_save_data = {
|
||||
"hi_score": 0
|
||||
}
|
||||
|
||||
func store_save_data(data):
|
||||
var save_file = File.new()
|
||||
save_file.open(SAVE_DATA_PATH, File.WRITE)
|
||||
save_file.store_line(to_json(data))
|
||||
save_file.close()
|
||||
|
||||
func load_save_data():
|
||||
var save_file = File.new()
|
||||
|
||||
if not save_file.file_exists(SAVE_DATA_PATH):
|
||||
store_save_data(default_save_data)
|
||||
return default_save_data
|
||||
|
||||
save_file.open(SAVE_DATA_PATH, File.READ)
|
||||
var save_data = parse_json(save_file.get_as_text())
|
||||
save_file.close()
|
||||
|
||||
return save_data
|
Loading…
Add table
Add a link
Reference in a new issue