From df12b43830bc16ee2d265edb7f18cdb734c68779 Mon Sep 17 00:00:00 2001 From: narumi Date: Mon, 30 Sep 2024 19:25:08 +0800 Subject: [PATCH] Support custom AP --- lib/app/modules/faker/faker.dart | 38 ++++++++++++++++ lib/generated/intl/messages_en.dart | 2 +- lib/generated/l10n.dart | 4 +- .../models/userdata/autologin.g.dart | 3 ++ lib/l10n/intl_en.arb | 2 +- lib/models/faker/shared/network.dart | 44 ++++++++++++++----- lib/models/userdata/autologin.dart | 5 ++- lib/utils/notification.dart | 14 +++--- 8 files changed, 90 insertions(+), 22 deletions(-) diff --git a/lib/app/modules/faker/faker.dart b/lib/app/modules/faker/faker.dart index 9c10beb20..37bd228b8 100644 --- a/lib/app/modules/faker/faker.dart +++ b/lib/app/modules/faker/faker.dart @@ -12,6 +12,7 @@ import 'package:chaldea/app/api/atlas.dart'; import 'package:chaldea/app/app.dart'; import 'package:chaldea/app/modules/battle/formation/formation_card.dart'; import 'package:chaldea/app/modules/common/builders.dart'; +import 'package:chaldea/app/modules/common/filter_group.dart'; import 'package:chaldea/app/modules/craft_essence/craft_list.dart'; import 'package:chaldea/app/modules/servant/servant_list.dart'; import 'package:chaldea/generated/l10n.dart'; @@ -1142,6 +1143,42 @@ class _FakeGrandOrderState extends State { } }, ), + ListTile( + dense: true, + title: const Text('Notify when AP recovered at'), + subtitle: FilterGroup( + padding: const EdgeInsets.only(top: 4), + options: [...fakerSettings.recoveredAps.toList()..sort(), 0], + values: FilterGroupData(), + optionBuilder: (v) => v == 0 ? Text(agent.user.userGame?.actMax.toString() ?? 'Full') : Text(v.toString()), + onFilterChanged: (_, lastChanged) { + setState(() { + if (lastChanged != null) { + fakerSettings.recoveredAps.remove(lastChanged); + agent.network.setLocalNotification(); + } + }); + }, + ), + trailing: IconButton( + onPressed: () { + InputCancelOkDialog( + title: 'AP', + keyboardType: TextInputType.number, + validate: (s) { + int v = int.tryParse(s) ?? -1; + return v > 0 && v < 200 && v < Maths.max(ConstData.userLevel.values.map((e) => e.maxAp)); + }, + onSubmit: (s) { + fakerSettings.recoveredAps.add(int.parse(s)); + agent.network.setLocalNotification(); + if (mounted) setState(() {}); + }, + ).showDialog(context); + }, + icon: const Icon(Icons.add), + ), + ), ListTile( dense: true, title: const Text('Max refresh count of Support list'), @@ -1160,6 +1197,7 @@ class _FakeGrandOrderState extends State { }, child: Text(fakerSettings.maxFollowerListRetryCount.toString())), ), + const Divider(), SwitchListTile( dense: true, value: fakerSettings.dumpResponse, diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index a435fb108..c38d2e8c2 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -120,7 +120,7 @@ class MessageLookup extends MessageLookupByLibrary { "ap_campaign_time_mismatch_hint": MessageLookupByLibrary.simpleMessage("Quest Campaigns\' start time of non-JP regions may be incorrect"), "ap_efficiency": MessageLookupByLibrary.simpleMessage("AP rate"), - "ap_fully_recovered": MessageLookupByLibrary.simpleMessage("All AP Recovered"), + "ap_fully_recovered": MessageLookupByLibrary.simpleMessage("All AP Restored"), "app_data_folder": MessageLookupByLibrary.simpleMessage("Data Folder"), "app_data_use_external_storage": MessageLookupByLibrary.simpleMessage("Use External Storage (SD card)"), "appearance": MessageLookupByLibrary.simpleMessage("Appearance"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 3a344d583..840e0d714 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -305,10 +305,10 @@ class S { ); } - /// `All AP Recovered` + /// `All AP Restored` String get ap_fully_recovered { return Intl.message( - 'All AP Recovered', + 'All AP Restored', name: 'ap_fully_recovered', desc: '', locale: localeName, diff --git a/lib/generated/models/userdata/autologin.g.dart b/lib/generated/models/userdata/autologin.g.dart index cf4d0d2a6..cf8ad399f 100644 --- a/lib/generated/models/userdata/autologin.g.dart +++ b/lib/generated/models/userdata/autologin.g.dart @@ -13,6 +13,8 @@ FakerSettings _$FakerSettingsFromJson(Map json) => $checkedCreate( final val = FakerSettings( dumpResponse: $checkedConvert('dumpResponse', (v) => v as bool? ?? false), apRecoveredNotification: $checkedConvert('apRecoveredNotification', (v) => v as bool? ?? false), + recoveredAps: + $checkedConvert('recoveredAps', (v) => (v as List?)?.map((e) => (e as num).toInt()).toSet()), maxFollowerListRetryCount: $checkedConvert('maxFollowerListRetryCount', (v) => (v as num?)?.toInt() ?? 20), jpAutoLogins: $checkedConvert( 'jpAutoLogins', @@ -32,6 +34,7 @@ FakerSettings _$FakerSettingsFromJson(Map json) => $checkedCreate( Map _$FakerSettingsToJson(FakerSettings instance) => { 'dumpResponse': instance.dumpResponse, 'apRecoveredNotification': instance.apRecoveredNotification, + 'recoveredAps': instance.recoveredAps.toList(), 'maxFollowerListRetryCount': instance.maxFollowerListRetryCount, 'jpAutoLogins': instance.jpAutoLogins.map((e) => e.toJson()).toList(), 'cnAutoLogins': instance.cnAutoLogins.map((e) => e.toJson()).toList(), diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 102884d67..9306072f8 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -22,7 +22,7 @@ "ap": "AP", "ap_campaign_time_mismatch_hint": "Quest Campaigns' start time of non-JP regions may be incorrect", "ap_efficiency": "AP rate", - "ap_fully_recovered": "All AP Recovered", + "ap_fully_recovered": "All AP Restored", "app_data_folder": "Data Folder", "app_data_use_external_storage": "Use External Storage (SD card)", "appearance": "Appearance", diff --git a/lib/models/faker/shared/network.dart b/lib/models/faker/shared/network.dart index 5a508a513..d90b5c010 100644 --- a/lib/models/faker/shared/network.dart +++ b/lib/models/faker/shared/network.dart @@ -233,18 +233,38 @@ abstract class NetworkManagerBase recoveredAps; int maxFollowerListRetryCount; List jpAutoLogins; List cnAutoLogins; @@ -17,10 +18,12 @@ class FakerSettings { FakerSettings({ this.dumpResponse = false, this.apRecoveredNotification = false, + Set? recoveredAps, this.maxFollowerListRetryCount = 20, List? jpAutoLogins, List? cnAutoLogins, - }) : jpAutoLogins = jpAutoLogins ?? [], + }) : recoveredAps = recoveredAps ?? {}, + jpAutoLogins = jpAutoLogins ?? [], cnAutoLogins = cnAutoLogins ?? []; factory FakerSettings.fromJson(Map json) => _$FakerSettingsFromJson(json); diff --git a/lib/utils/notification.dart b/lib/utils/notification.dart index 23a8074bd..418bdc8d9 100644 --- a/lib/utils/notification.dart +++ b/lib/utils/notification.dart @@ -129,13 +129,17 @@ abstract class LocalNotificationUtil { } } - // - static int generateUserApFullId(int region, int userId) { - // 8 digits - return (10 + region + 1) * 1000000 + userId % 1000000; + static const int _kUserIdMod = 10 ^ 5; + static int generateUserApRecoverId(int region, int userId, int ap) { + // 1+3+17+8=29 bits + int v = 1; + v = (v << 3) + region; + v = (v << 17) + userId % _kUserIdMod; + v = (v << 8) + ap; + return v; } static bool isUserApFullId(int id) { - return id ~/ 10000000 == 1; + return (id >> (3 + 17 + 8)) == 1; } }