Compare commits

...

3 Commits

Author SHA1 Message Date
JiWoong Sul
4af3830bb5 test: 테스트 코드 업데이트
- 변경된 API에 맞게 테스트 수정
2026-01-08 16:05:20 +09:00
JiWoong Sul
cfc1537af2 refactor(game): 앱 및 게임 세션 개선
- App 초기화 로직 정리
- GamePlayScreen 개선
- GameSessionController 확장
2026-01-08 16:05:14 +09:00
JiWoong Sul
606d052e2c refactor(core): 진행 루프, 저장 데이터, 저장 관리자 개선
- ProgressLoop 로직 정리
- SaveData 모델 확장
- SaveManager 개선
2026-01-08 16:05:08 +09:00
9 changed files with 67 additions and 36 deletions

View File

@@ -116,7 +116,7 @@ class _AskiiNeverDieAppState extends State<AskiiNeverDieApp> {
if (exists) {
// 세이브 파일에서 미리보기 정보 추출
final (outcome, state) = await _controller.saveManager.loadState();
final (outcome, state, _) = await _controller.saveManager.loadState();
if (outcome.success && state != null) {
final actName = _getActName(state.progress.plotStageCount);
preview = SavedGamePreview(
@@ -477,7 +477,10 @@ class _AskiiNeverDieAppState extends State<AskiiNeverDieApp> {
},
),
),
);
).then((_) {
// 새 게임 후 돌아오면 세이브 정보 갱신
_checkForExistingSave();
});
}
Future<void> _loadSave(BuildContext context) async {
@@ -502,11 +505,8 @@ class _AskiiNeverDieAppState extends State<AskiiNeverDieApp> {
if (selectedFileName == null || !context.mounted) return;
// 선택된 파일 로드
await _controller.loadAndStart(
fileName: selectedFileName,
cheatsEnabled: false,
);
// 선택된 파일 로드 (치트 모드는 저장된 상태에서 복원)
await _controller.loadAndStart(fileName: selectedFileName);
if (_controller.status == GameSessionStatus.running) {
if (context.mounted) {
@@ -553,7 +553,10 @@ class _AskiiNeverDieAppState extends State<AskiiNeverDieApp> {
onThemeModeChange: _changeThemeMode,
),
),
);
).then((_) {
// 게임에서 돌아오면 세이브 정보 갱신
_checkForExistingSave();
});
}
/// Phase 10: 명예의 전당 화면으로 이동

View File

@@ -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)

View File

@@ -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<String, dynamic> 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? ?? '',

View File

@@ -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<SaveOutcome> saveState(GameState state, {String? fileName}) {
final save = GameSave.fromState(state);
Future<SaveOutcome> 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);
}
/// 저장 파일 목록 조회

View File

@@ -528,8 +528,8 @@ class _GamePlayScreenState extends State<GamePlayScreen>
/// 모바일 재진입 시 전체 화면 재로드
Future<void> _reloadGameScreen() async {
// 세이브 파일에서 다시 로드
await widget.controller.loadAndStart(cheatsEnabled: widget.controller.cheatsEnabled);
// 세이브 파일에서 다시 로드 (치트 모드는 저장된 상태에서 복원)
await widget.controller.loadAndStart();
if (!mounted) return;
@@ -550,7 +550,10 @@ class _GamePlayScreenState extends State<GamePlayScreen>
final currentState = widget.controller.state;
if (currentState == null || !widget.controller.isRunning) return;
await widget.controller.saveManager.saveState(currentState);
await widget.controller.saveManager.saveState(
currentState,
cheatsEnabled: widget.controller.cheatsEnabled,
);
}
/// 뒤로가기 시 저장 확인 다이얼로그

View File

@@ -225,13 +225,13 @@ class GameSessionController extends ChangeNotifier {
Future<void> loadAndStart({
String? fileName,
bool cheatsEnabled = false,
}) async {
_status = GameSessionStatus.loading;
_error = null;
notifyListeners();
final (outcome, loaded) = await saveManager.loadState(fileName: fileName);
final (outcome, loaded, savedCheatsEnabled) =
await saveManager.loadState(fileName: fileName);
if (!outcome.success || loaded == null) {
_status = GameSessionStatus.error;
_error = outcome.error ?? 'Unknown error';
@@ -239,7 +239,8 @@ class GameSessionController extends ChangeNotifier {
return;
}
await startNew(loaded, cheatsEnabled: cheatsEnabled, isNewGame: false);
// 저장된 치트 모드 상태 복원
await startNew(loaded, cheatsEnabled: savedCheatsEnabled, isNewGame: false);
}
Future<void> pause({bool saveOnStop = false}) async {
@@ -382,8 +383,11 @@ class GameSessionController extends ChangeNotifier {
_state = resurrectedState;
_status = GameSessionStatus.idle; // 사망 상태 해제
// 저장
await saveManager.saveState(resurrectedState);
// 저장 (치트 모드 상태 유지)
await saveManager.saveState(
resurrectedState,
cheatsEnabled: _cheatsEnabled,
);
notifyListeners();
}

View File

@@ -13,14 +13,18 @@ class _FakeSaveManager implements SaveManager {
final List<GameState> savedStates = [];
@override
Future<SaveOutcome> saveState(GameState state, {String? fileName}) async {
Future<SaveOutcome> saveState(
GameState state, {
String? fileName,
bool cheatsEnabled = false,
}) async {
savedStates.add(state);
return const SaveOutcome.success();
}
@override
Future<(SaveOutcome, GameState?)> loadState({String? fileName}) async {
return (const SaveOutcome.success(), null);
Future<(SaveOutcome, GameState?, bool)> loadState({String? fileName}) async {
return (const SaveOutcome.success(), null, false);
}
@override

View File

@@ -23,13 +23,17 @@ Widget _buildTestApp(Widget child) {
class _FakeSaveManager implements SaveManager {
@override
Future<SaveOutcome> saveState(GameState state, {String? fileName}) async {
Future<SaveOutcome> saveState(
GameState state, {
String? fileName,
bool cheatsEnabled = false,
}) async {
return const SaveOutcome.success();
}
@override
Future<(SaveOutcome, GameState?)> loadState({String? fileName}) async {
return (const SaveOutcome.success(), null);
Future<(SaveOutcome, GameState?, bool)> loadState({String? fileName}) async {
return (const SaveOutcome.success(), null, false);
}
@override

View File

@@ -12,21 +12,25 @@ import 'package:flutter_test/flutter_test.dart';
class FakeSaveManager implements SaveManager {
final List<GameState> savedStates = [];
(SaveOutcome, GameState?) Function(String?)? onLoad;
(SaveOutcome, GameState?, bool) Function(String?)? onLoad;
SaveOutcome saveOutcome = const SaveOutcome.success();
@override
Future<SaveOutcome> saveState(GameState state, {String? fileName}) async {
Future<SaveOutcome> saveState(
GameState state, {
String? fileName,
bool cheatsEnabled = false,
}) async {
savedStates.add(state);
return saveOutcome;
}
@override
Future<(SaveOutcome, GameState?)> loadState({String? fileName}) async {
Future<(SaveOutcome, GameState?, bool)> loadState({String? fileName}) async {
if (onLoad != null) {
return onLoad!(fileName);
}
return (const SaveOutcome.success(), null);
return (const SaveOutcome.success(), null, false);
}
@override
@@ -122,7 +126,7 @@ void main() {
test('loadAndStart surfaces save load errors', () {
fakeAsync((async) {
final saveManager = FakeSaveManager()
..onLoad = (_) => (const SaveOutcome.failure('boom'), null);
..onLoad = (_) => (const SaveOutcome.failure('boom'), null, false);
final controller = buildController(async, saveManager);
controller.loadAndStart(fileName: 'bad.pqf');