diff options
author | metamuffin <metamuffin@disroot.org> | 2025-09-16 22:28:24 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-09-16 22:28:24 +0200 |
commit | 3f98582f903e579d9f47aba48f3976345eabe123 (patch) | |
tree | 5124f087056171ccf0196169a4b3c4e992183fa3 /client/system/profile.gd | |
parent | e86637eade79ed5fef5ca2e9c169f5c40a314400 (diff) | |
download | hurrycurry-3f98582f903e579d9f47aba48f3976345eabe123.tar hurrycurry-3f98582f903e579d9f47aba48f3976345eabe123.tar.bz2 hurrycurry-3f98582f903e579d9f47aba48f3976345eabe123.tar.zst |
Move some scripts to new "system" dir, add argument parser
Diffstat (limited to 'client/system/profile.gd')
-rw-r--r-- | client/system/profile.gd | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/client/system/profile.gd b/client/system/profile.gd new file mode 100644 index 00000000..438e8e66 --- /dev/null +++ b/client/system/profile.gd @@ -0,0 +1,91 @@ +# Hurry Curry! - a game about cooking +# Copyright (C) 2025 Hurry Curry! contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +extends Node +class_name Profile + +static var default_profile := { + "username": "", + "character_style": { + "color": 0, + "headwear": 0, + "hairstyle": 0 + }, + "last_server_url": "", + "tutorial_ingredients_played": [], + "registry_asked": false, + "hints": { + "has_moved": false, + "has_boosted": false, + "has_interacted": false, + "has_rotated": false, + "has_reset": false, + "has_zoomed": false, + "has_seen_performance": false, + "has_seen_join_while_running": false + } +} + +# profile is stored in a Dictionary[String, Any] +static var values: Dictionary +static var loaded_path: String + +static func load(path: String): + # TOCTOU here. Godot docs says its fine. + if not FileAccess.file_exists(path): + print("Skip profile load") + return default_profile + var f = FileAccess.open(path, FileAccess.READ) + + values = f.get_var(true) + if values != null and values is Dictionary: + G.add_missing_keys(values, default_profile) + loaded_path = path + +static func save(): + var f = FileAccess.open(loaded_path, FileAccess.WRITE) + var to_save = values.duplicate(true) + f.store_var(to_save, true) + +static func read(key: String): + if values.has(key): + return values[key] + else: + push_error("Tried to access profile setting \"%s\", which does not exist (missing key)" % key) + return null + +static func write(key: String, value): + if !values.has(key): + push_error("Tried to set profile setting \"%s\", which does not yet exist (missing key)" % key) + return + if values[key] != value: + values[key] = value + +static func set_hint(key: String, value: bool): + if !values["hints"].has(key): + push_error("Tried to set hint \"%s\", which does not yet exist (missing key)" % key) + if values["hints"][key] != value: + if value: + Settings.write("gameplay.hints_started", true) + Settings.save() + values["hints"][key] = value + save() # TODO avoid this call when bulk-unsetting hints + +static func get_hint(key: String): + if values["hints"].has(key): + return values["hints"][key] + else: + push_error("Tried to access hint \"%s\", which does not exist (missing key)" % key) + return null |