From e8d0c064402779bdd0af671fe3df3973fd7dcd87 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Tue, 21 Jul 2026 11:42:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(meta):=20MetaProgress=20autoload=EF=BC=88?= =?UTF-8?q?=E7=A2=8E=E7=89=87+=E5=B7=B2=E8=A7=A3=E9=94=81+=E6=8C=81?= =?UTF-8?q?=E4=B9=85=E5=8C=96=20user://meta.json=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 1 + scripts/autoloads/meta_progress.gd | 55 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 scripts/autoloads/meta_progress.gd diff --git a/project.godot b/project.godot index a2b2449..5fd7194 100644 --- a/project.godot +++ b/project.godot @@ -50,6 +50,7 @@ DpsTracker="*res://scripts/autoloads/dps_tracker.gd" ZoneManager="*res://scripts/autoloads/zone_manager.gd" MinionManager="*res://scripts/autoloads/minion_manager.gd" EndlessRecords="*res://scripts/autoloads/endless_records.gd" +MetaProgress="*res://scripts/autoloads/meta_progress.gd" Locale="*res://scripts/autoloads/locale_manager.gd" SettingsManager="*res://scripts/autoloads/settings_manager.gd" AudioManager="*res://scripts/autoloads/audio_manager.gd" diff --git a/scripts/autoloads/meta_progress.gd b/scripts/autoloads/meta_progress.gd new file mode 100644 index 0000000..23517d0 --- /dev/null +++ b/scripts/autoloads/meta_progress.gd @@ -0,0 +1,55 @@ +## MetaProgress — 全局元进展(Autoload: MetaProgress) +## 以太碎片 + 已解锁法术,持久化 user://meta.json(死亡不重置)。 +extends Node + +const PATH: String = "user://meta.json" + +var aether: int = 0 +var unlocked: Array = [] # 已解锁法术 id (String) + +func _ready() -> void: + load_meta() + +func add_aether(n: int) -> void: + if n <= 0: + return + aether += n + save_meta() + +func is_unlocked(id: String) -> bool: + return id in unlocked + +## 已解锁 或 碎片不足 → false(不扣费);否则扣费+记录+存档 → true +func unlock(id: String, cost: int) -> bool: + if is_unlocked(id) or aether < cost: + return false + aether -= cost + unlocked.append(id) + save_meta() + return true + +func clear() -> void: + aether = 0 + unlocked = [] + if FileAccess.file_exists(PATH): + DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH)) + +func save_meta() -> void: + var f := FileAccess.open(PATH, FileAccess.WRITE) + if f: + f.store_string(JSON.stringify({"aether": aether, "unlocked": unlocked})) + f.close() + +func load_meta() -> void: + aether = 0 + unlocked = [] + if not FileAccess.file_exists(PATH): + return + var parsed = JSON.parse_string(FileAccess.get_file_as_string(PATH)) + if not (parsed is Dictionary): + return + aether = int(parsed.get("aether", 0)) + var u = parsed.get("unlocked", []) + if u is Array: + for id in u: + unlocked.append(String(id))