| 123456789101112131415161718192021222324252627282930313233 |
- extends Node
- ## Saved level, which drops by one for every Params.LOSE_HOURS the player stays away.
- const PATH := "user://progress.cfg"
- ## Level the next game scene starts at.
- var current_level := 0
- func save_level(level: int) -> void:
- var config := ConfigFile.new()
- config.set_value("progress", "level", level)
- config.set_value("progress", "time", Time.get_unix_time_from_system())
- config.save(PATH)
- ## Applies any decay since the last save and returns [level, hours until the next decay].
- func load_level() -> Array:
- var config := ConfigFile.new()
- config.load(PATH)
- var level: int = config.get_value("progress", "level", 0)
- var last: float = config.get_value("progress", "time", 0.0)
- var now := Time.get_unix_time_from_system()
- var period := 3600.0 * Params.LOSE_HOURS
- var remaining := period + last - now
- while remaining < 0.0 and level > 0:
- last += period
- level -= 1
- remaining = period + last - now
- config.set_value("progress", "level", level)
- config.set_value("progress", "time", last)
- config.save(PATH)
- return [level, remaining / 3600.0]
|