38 lines
1.3 KiB
GDScript
38 lines
1.3 KiB
GDScript
class_name GameSettings
|
|
## The player's settings, kept in user://settings.cfg between runs. The game scene only reads them
|
|
## when it's entered from the menu (see SceneRouter), so tests that open it directly always start
|
|
## from DEFAULTS.
|
|
|
|
const PATH := "user://settings.cfg"
|
|
const DEFAULTS := {"stops": "combat", "autoSkip": true, "checkInvariants": false, "botDelay": 0.45, "anim": "normal"}
|
|
## Animation speeds: `scale` multiplies every animation's length; 0 is instant.
|
|
const ANIM_SPEEDS := {
|
|
"slow": {"label": "Slow", "scale": 1.6},
|
|
"normal": {"label": "Normal", "scale": 1.0},
|
|
"fast": {"label": "Fast", "scale": 0.5},
|
|
"instant": {"label": "Instant", "scale": 0.0},
|
|
}
|
|
|
|
|
|
static func load_saved() -> Dictionary:
|
|
var out := DEFAULTS.duplicate()
|
|
var cfg := ConfigFile.new()
|
|
if cfg.load(PATH) == OK:
|
|
for k in DEFAULTS:
|
|
var v = cfg.get_value("game", k, DEFAULTS[k])
|
|
if typeof(v) == typeof(DEFAULTS[k]) or (DEFAULTS[k] is float and v is int):
|
|
out[k] = v
|
|
if not ANIM_SPEEDS.has(out.anim):
|
|
out.anim = DEFAULTS.anim
|
|
return out
|
|
|
|
|
|
static func save(settings: Dictionary) -> void:
|
|
var cfg := ConfigFile.new()
|
|
for k in DEFAULTS:
|
|
cfg.set_value("game", k, settings.get(k, DEFAULTS[k]))
|
|
cfg.save(PATH)
|
|
|
|
|
|
static func anim_scale(settings: Dictionary) -> float:
|
|
return ANIM_SPEEDS.get(settings.get("anim", "normal"), ANIM_SPEEDS.normal).scale
|