From 606d052e2c122836b2ce5bfd87011b2a8db8ca70 Mon Sep 17 00:00:00 2001 From: JiWoong Sul Date: Thu, 8 Jan 2026 16:05:08 +0900 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=EC=A7=84=ED=96=89=20?= =?UTF-8?q?=EB=A3=A8=ED=94=84,=20=EC=A0=80=EC=9E=A5=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0,=20=EC=A0=80=EC=9E=A5=20=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ProgressLoop 로직 정리 - SaveData 모델 확장 - SaveManager 개선 --- lib/src/core/engine/progress_loop.dart | 4 ++-- lib/src/core/model/save_data.dart | 7 ++++++- lib/src/core/storage/save_manager.dart | 16 ++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/src/core/engine/progress_loop.dart b/lib/src/core/engine/progress_loop.dart index 18111e3..036f32a 100644 --- a/lib/src/core/engine/progress_loop.dart +++ b/lib/src/core/engine/progress_loop.dart @@ -108,7 +108,7 @@ class ProgressLoop { _timer?.cancel(); _timer = null; if (saveOnStop && _autoSaveConfig.onStop && saveManager != null) { - await saveManager!.saveState(_state); + await saveManager!.saveState(_state, cheatsEnabled: cheatsEnabled); } } @@ -131,7 +131,7 @@ class ProgressLoop { _stateController.add(_state); if (saveManager != null && _autoSaveConfig.shouldSave(result)) { - saveManager!.saveState(_state); + saveManager!.saveState(_state, cheatsEnabled: cheatsEnabled); } // 사망 시 루프 정지 및 콜백 호출 (Phase 4) diff --git a/lib/src/core/model/save_data.dart b/lib/src/core/model/save_data.dart index 0f5e86a..9f3aaa5 100644 --- a/lib/src/core/model/save_data.dart +++ b/lib/src/core/model/save_data.dart @@ -16,9 +16,10 @@ class GameSave { required this.skillBook, required this.progress, required this.queue, + this.cheatsEnabled = false, }); - factory GameSave.fromState(GameState state) { + factory GameSave.fromState(GameState state, {bool cheatsEnabled = false}) { return GameSave( version: kSaveVersion, rngState: state.rng.state, @@ -29,6 +30,7 @@ class GameSave { skillBook: state.skillBook, progress: state.progress, queue: state.queue, + cheatsEnabled: cheatsEnabled, ); } @@ -41,10 +43,12 @@ class GameSave { final SkillBook skillBook; final ProgressState progress; final QueueState queue; + final bool cheatsEnabled; Map toJson() { return { 'version': version, + 'cheatsEnabled': cheatsEnabled, 'rng': rngState, 'traits': { 'name': traits.name, @@ -144,6 +148,7 @@ class GameSave { return GameSave( version: json['version'] as int? ?? kSaveVersion, + cheatsEnabled: json['cheatsEnabled'] as bool? ?? false, rngState: json['rng'] as int? ?? 0, traits: Traits( name: traitsJson['name'] as String? ?? '', diff --git a/lib/src/core/storage/save_manager.dart b/lib/src/core/storage/save_manager.dart index 8bea9c3..937712d 100644 --- a/lib/src/core/storage/save_manager.dart +++ b/lib/src/core/storage/save_manager.dart @@ -13,19 +13,23 @@ class SaveManager { /// Save current game state to disk. [fileName] may be absolute or relative. /// Returns outcome with error on failure. - Future saveState(GameState state, {String? fileName}) { - final save = GameSave.fromState(state); + Future saveState( + GameState state, { + String? fileName, + bool cheatsEnabled = false, + }) { + final save = GameSave.fromState(state, cheatsEnabled: cheatsEnabled); return _repo.save(save, fileName ?? defaultFileName); } /// Load game state from disk. [fileName] may be absolute (e.g., file picker). - /// Returns outcome + optional state. - Future<(SaveOutcome, GameState?)> loadState({String? fileName}) async { + /// Returns outcome + optional state + cheatsEnabled flag. + Future<(SaveOutcome, GameState?, bool)> loadState({String? fileName}) async { final (outcome, save) = await _repo.load(fileName ?? defaultFileName); if (!outcome.success || save == null) { - return (outcome, null); + return (outcome, null, false); } - return (outcome, save.toState()); + return (outcome, save.toState(), save.cheatsEnabled); } /// 저장 파일 목록 조회