2022-09-07 13:25:56 -06:00
|
|
|
import 'package:wonders/common_libs.dart';
|
2022-11-05 02:06:51 -06:00
|
|
|
import 'package:wonders/logic/common/platform_info.dart';
|
2022-08-29 20:38:28 -06:00
|
|
|
import 'package:wonders/logic/common/save_load_mixin.dart';
|
|
|
|
|
|
|
|
class SettingsLogic with ThrottledSaveLoadMixin {
|
|
|
|
@override
|
|
|
|
String get fileName => 'settings.dat';
|
|
|
|
|
|
|
|
late final hasCompletedOnboarding = ValueNotifier<bool>(false)..addListener(scheduleSave);
|
|
|
|
late final hasDismissedSearchMessage = ValueNotifier<bool>(false)..addListener(scheduleSave);
|
2023-02-28 10:05:51 -07:00
|
|
|
late final isSearchPanelOpen = ValueNotifier<bool>(true)..addListener(scheduleSave);
|
2022-09-08 12:14:28 -06:00
|
|
|
late final currentLocale = ValueNotifier<String?>(null)..addListener(scheduleSave);
|
2024-01-11 10:12:40 -07:00
|
|
|
late final prevWonderIndex = ValueNotifier<int?>(null)..addListener(scheduleSave);
|
2022-08-29 20:38:28 -06:00
|
|
|
|
2022-11-05 02:06:51 -06:00
|
|
|
final bool useBlurs = !PlatformInfo.isAndroid;
|
2022-08-29 20:38:28 -06:00
|
|
|
|
2024-01-11 10:12:40 -07:00
|
|
|
Future<void> changeLocale(Locale value) async {
|
|
|
|
currentLocale.value = value.languageCode;
|
|
|
|
await localeLogic.loadIfChanged(value);
|
|
|
|
// Re-init controllers that have some cached data that is localized
|
|
|
|
wondersLogic.init();
|
|
|
|
timelineLogic.init();
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:38:28 -06:00
|
|
|
@override
|
|
|
|
void copyFromJson(Map<String, dynamic> value) {
|
|
|
|
hasCompletedOnboarding.value = value['hasCompletedOnboarding'] ?? false;
|
|
|
|
hasDismissedSearchMessage.value = value['hasDismissedSearchMessage'] ?? false;
|
2022-09-08 12:14:28 -06:00
|
|
|
currentLocale.value = value['currentLocale'];
|
2023-02-28 10:05:51 -07:00
|
|
|
isSearchPanelOpen.value = value['isSearchPanelOpen'] ?? false;
|
2024-01-11 10:12:40 -07:00
|
|
|
prevWonderIndex.value = value['lastWonderIndex'];
|
2022-08-29 20:38:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return {
|
|
|
|
'hasCompletedOnboarding': hasCompletedOnboarding.value,
|
|
|
|
'hasDismissedSearchMessage': hasDismissedSearchMessage.value,
|
2022-09-08 12:14:28 -06:00
|
|
|
'currentLocale': currentLocale.value,
|
2023-02-28 10:05:51 -07:00
|
|
|
'isSearchPanelOpen': isSearchPanelOpen.value,
|
2024-01-11 10:12:40 -07:00
|
|
|
'lastWonderIndex': prevWonderIndex.value,
|
2022-08-29 20:38:28 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|