Skip to content

Commit

Permalink
feat: saver
Browse files Browse the repository at this point in the history
  • Loading branch information
Arenukvern committed Sep 1, 2024
1 parent cf70a1c commit a39aca4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/pack_core/global_states/global_game/global_game_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class GlobalGameBloc extends Cubit<GlobalGameBlocState> {
dto.statesStatusesCubit.stream.listen(_onStatusChanged);
}
final _log = Logger();
late final _saver = GameSaver(onSave: onSaveCurrentLevel);
final GlobalGameBlocDiDto dto;
GameTutorialEventListener? _tutorialEventsListener;
StreamSubscription<StatesStatusesCubitState>?
Expand Down Expand Up @@ -426,6 +427,7 @@ class GlobalGameBloc extends Cubit<GlobalGameBlocState> {
);
emit(newState);
_shareNewDateTime(newState);
if (!dto.mechanics.worldTime.paused) _saver.onTick();
}

Future<void> onLevelEnd({
Expand Down Expand Up @@ -624,7 +626,24 @@ class GlobalGameBloc extends Cubit<GlobalGameBlocState> {
}
}

// ignore: one_member_abstracts
abstract interface class WorldTickConsumable {
WorldTickConsumable._();
void onConsumeTickEvent();
}

class GameSaver {
GameSaver({
required this.onSave,
});
final VoidCallback onSave;
DateTime _lastSaveDate = DateTime.now();
void onTick() {
final now = DateTime.now();
if (now.difference(_lastSaveDate).inSeconds > 3) {
debugPrint('game_saver onTick');
_lastSaveDate = now;
onSave();
}
}
}

0 comments on commit a39aca4

Please sign in to comment.