comment save.gd and add format version
This commit is contained in:
parent
e524faba5f
commit
1f77bc4513
1 changed files with 21 additions and 10 deletions
|
@ -1,23 +1,27 @@
|
|||
extends Node
|
||||
|
||||
## contains the save data for a single level
|
||||
class LevelSaveData:
|
||||
var save_id: String
|
||||
# currently-used compatible format version
|
||||
const FORMAT_VERSION: int = 1
|
||||
|
||||
# contains the save data for a single level
|
||||
class LevelSaveData:
|
||||
# save file category to use for this level
|
||||
var save_id: String
|
||||
# scores
|
||||
var score_any: int = 0
|
||||
var score_100: int = 0
|
||||
|
||||
# times
|
||||
var time_any: float = INF
|
||||
var time_100: float = INF
|
||||
|
||||
# times died in that level
|
||||
var deaths: int
|
||||
|
||||
# collectibles
|
||||
var keys_collected: int = 0
|
||||
var shards_collected: Array
|
||||
|
||||
|
||||
func _init(id: String) -> void:
|
||||
save_id = id
|
||||
# initialize shards array
|
||||
shards_collected = []
|
||||
shards_collected.resize(8)
|
||||
for i in 8:
|
||||
|
@ -55,9 +59,12 @@ class LevelSaveData:
|
|||
for i in 8:
|
||||
shards_collected[i] = file.get_value(save_id, "shard_%d" % i, false)
|
||||
|
||||
# contains data of one save file
|
||||
class SaveFile:
|
||||
# path of file to load/save from
|
||||
var file_path: String
|
||||
# version of save file format
|
||||
var version: int = FORMAT_VERSION
|
||||
# name of the save file
|
||||
var name: String = ""
|
||||
# difficulty chosen for the file
|
||||
|
@ -69,6 +76,7 @@ class SaveFile:
|
|||
|
||||
func _init(path: String) -> void:
|
||||
file_path = path
|
||||
# initialize level save data dictionary
|
||||
levels = {}
|
||||
for level in LevelData.levels:
|
||||
levels[level.save_id] = LevelSaveData.new(level.save_id)
|
||||
|
@ -94,9 +102,12 @@ class SaveFile:
|
|||
total += level.deaths
|
||||
return total
|
||||
|
||||
# loads data from the file at `path`
|
||||
func load_from_file() -> void:
|
||||
var file = ConfigFile.new()
|
||||
file.load(file_path)
|
||||
# get save format version
|
||||
version = file.get_value("options", "version", 0)
|
||||
# load name
|
||||
name = file.get_value("options", "name", "SG")
|
||||
# load difficulty
|
||||
|
@ -111,6 +122,8 @@ class SaveFile:
|
|||
|
||||
func save_to_file() -> void:
|
||||
var file = ConfigFile.new()
|
||||
# use current format version
|
||||
file.set_value("options", "version", FORMAT_VERSION)
|
||||
# save name
|
||||
file.set_value("options", "name", name)
|
||||
# save difficulty
|
||||
|
@ -124,6 +137,7 @@ class SaveFile:
|
|||
level.save_to_file(file)
|
||||
file.save(file_path)
|
||||
|
||||
## currently used save file
|
||||
var current_file: SaveFile = null
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -131,10 +145,7 @@ func _ready() -> void:
|
|||
current_file = load_file("user://file1.pr")
|
||||
Game.difficulty = current_file.difficulty
|
||||
|
||||
func _on_letter_chosen(glyph: String):
|
||||
if current_file != null:
|
||||
current_file.name += glyph
|
||||
|
||||
## shortcut for loading a save file from specific path
|
||||
func load_file(path: String) -> SaveFile:
|
||||
var file = SaveFile.new(path)
|
||||
file.load_from_file()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue