Skip to content

Commit b043375

Browse files
committed
Only show compatible moves (triggers) and persist glowtip/rgb status
1 parent 9733e46 commit b043375

File tree

5 files changed

+136
-44
lines changed

5 files changed

+136
-44
lines changed

lib/Backend/Definitions/Device/device_definition.dart

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,25 @@ enum ConnectivityState { connected, disconnected, connecting }
127127

128128
enum DeviceState { standby, runAction, busy }
129129

130-
enum GlowtipStatus { glowtip, noGlowtip, unknown }
130+
@HiveType(typeId: 15)
131+
enum GlowtipStatus {
132+
@HiveField(1)
133+
glowtip,
134+
@HiveField(2)
135+
noGlowtip,
136+
@HiveField(3)
137+
unknown,
138+
}
131139

132-
enum RGBStatus { rgb, noRGB, unknown }
140+
@HiveType(typeId: 16)
141+
enum RGBStatus {
142+
@HiveField(1)
143+
rgb,
144+
@HiveField(2)
145+
noRGB,
146+
@HiveField(3)
147+
unknown,
148+
}
133149

134150
enum TailControlStatus { tailControl, legacy, unknown }
135151

@@ -253,6 +269,22 @@ class BaseStatefulDevice {
253269
deviceStateWatchdogTimer = null;
254270
}
255271
});
272+
273+
// Store glowtip/rgb status
274+
hasGlowtip.value = baseStoredDevice.hasGlowtip;
275+
hasGlowtip.addListener(() {
276+
if (hasGlowtip.value != GlowtipStatus.unknown) {
277+
baseStoredDevice.hasGlowtip = hasGlowtip.value;
278+
KnownDevices.instance.store();
279+
}
280+
});
281+
hasRGB.value = baseStoredDevice.hasRGB;
282+
hasRGB.addListener(() {
283+
if (hasRGB.value != RGBStatus.unknown) {
284+
baseStoredDevice.hasRGB = hasRGB.value;
285+
KnownDevices.instance.store();
286+
}
287+
});
256288
}
257289

258290
@override
@@ -370,6 +402,11 @@ class BaseStoredDevice extends ChangeNotifier {
370402
@HiveField(13, defaultValue: false)
371403
bool conModeEnabled = false;
372404

405+
@HiveField(14, defaultValue: GlowtipStatus.unknown)
406+
GlowtipStatus hasGlowtip = GlowtipStatus.unknown;
407+
@HiveField(15, defaultValue: RGBStatus.unknown)
408+
RGBStatus hasRGB = RGBStatus.unknown;
409+
373410
int get color => _color;
374411

375412
set color(int value) {

lib/Backend/action_registry.dart

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,29 +262,59 @@ class GetAvailableActions extends _$GetAvailableActions {
262262
}
263263
}
264264

265+
// Technically not all moves
266+
// only return moves that would be available if all gear was connected
265267
@Riverpod(keepAlive: true)
266-
BuiltMap<String, BuiltSet<BaseAction>> getAllActions(Ref ref) {
267-
ref.watch(initLocaleProvider); // to rebuild category names
268-
Map<String, Set<BaseAction>> sortedActions = {};
269-
final BuiltList<MoveList> moveLists = ref.watch(moveListsProvider);
270-
final BuiltList<AudioAction> audioActions = ref.watch(userAudioActionsProvider);
271-
for (BaseAction baseAction
272-
in List.from(ActionRegistry.allCommands)
273-
..addAll(moveLists)
274-
..addAll(audioActions)) {
275-
Set<BaseAction>? baseActions = {};
276-
// get category if it exists
277-
if (sortedActions.containsKey(baseAction.getCategoryName())) {
278-
baseActions = sortedActions[baseAction.getCategoryName()];
268+
class GetAllActions extends _$GetAllActions {
269+
@override
270+
BuiltMap<String, BuiltSet<BaseAction>> build() {
271+
ref.watch(initLocaleProvider); // to rebuild category names
272+
KnownDevices.instance
273+
..removeListener(onDeviceConnect)
274+
..addListener(onDeviceConnect);
275+
Map<String, Set<BaseAction>> sortedActions = {};
276+
final BuiltList<MoveList> moveLists = ref.watch(moveListsProvider);
277+
final BuiltList<AudioAction> audioActions = ref.watch(userAudioActionsProvider);
278+
for (BaseStatefulDevice baseStatefulDevice in KnownDevices.instance.state.values) {
279+
baseStatefulDevice.hasRGB
280+
..removeListener(onDeviceConnect)
281+
..addListener(onDeviceConnect);
282+
baseStatefulDevice.hasGlowtip
283+
..removeListener(onDeviceConnect)
284+
..addListener(onDeviceConnect);
279285
}
280-
// add action to category
281-
baseActions?.add(baseAction);
282-
// store result
283-
if (baseActions != null && baseActions.isNotEmpty) {
284-
sortedActions[baseAction.getCategoryName()] = baseActions;
286+
// Filter out moves from unpaired gear
287+
Set<DeviceType> pairedDeviceTypes = KnownDevices.instance.state.values.map((e) => e.baseDeviceDefinition.deviceType).toSet();
288+
bool hasRGB = KnownDevices.instance.state.values.map((e) => e.baseStoredDevice.hasRGB).any((element) => element == RGBStatus.rgb);
289+
bool hasGlowTip = KnownDevices.instance.state.values.map((e) => e.baseStoredDevice.hasGlowtip).any((element) => element == GlowtipStatus.glowtip);
290+
291+
for (BaseAction baseAction
292+
in List.from(
293+
ActionRegistry.allCommands
294+
.where((element) => pairedDeviceTypes.intersection(element.deviceCategory.toSet()).isNotEmpty)
295+
.whereNot((element) => element.actionCategory == ActionCategory.rgb && !hasRGB)
296+
.whereNot((element) => element.actionCategory == ActionCategory.glowtip && !hasGlowTip),
297+
)
298+
..addAll(moveLists)
299+
..addAll(audioActions)) {
300+
Set<BaseAction>? baseActions = {};
301+
// get category if it exists
302+
if (sortedActions.containsKey(baseAction.getCategoryName())) {
303+
baseActions = sortedActions[baseAction.getCategoryName()];
304+
}
305+
// add action to category
306+
baseActions?.add(baseAction);
307+
// store result
308+
if (baseActions != null && baseActions.isNotEmpty) {
309+
sortedActions[baseAction.getCategoryName()] = baseActions;
310+
}
285311
}
312+
return BuiltMap(sortedActions.map((key, value) => MapEntry(key, value.build())));
313+
}
314+
315+
void onDeviceConnect() {
316+
ref.invalidateSelf();
286317
}
287-
return BuiltMap(sortedActions.map((key, value) => MapEntry(key, value.build())));
288318
}
289319

290320
@Riverpod(keepAlive: true)

lib/Frontend/pages/triggers.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,24 @@ class _TriggerEditState extends ConsumerState<TriggerEdit> {
267267
),
268268
firstChild: Builder(
269269
builder: (context) {
270-
String text = "";
271-
Iterable<BaseStatefulDevice> knownDevices = KnownDevices.instance.state.values;
272-
for (String actionUUID in e.actions) {
273-
BaseAction? baseAction = ref.watch(getActionFromUUIDProvider(actionUUID));
274-
if (baseAction != null &&
275-
(knownDevices.isEmpty || knownDevices.where((element) => baseAction.deviceCategory.contains(element.baseDeviceDefinition.deviceType)).isNotEmpty)) {
276-
if (text.isNotEmpty) {
277-
text += ', ';
270+
return ListenableBuilder(
271+
listenable: KnownDevices.instance,
272+
builder: (context, child) {
273+
String text = "";
274+
Iterable<BaseStatefulDevice> knownDevices = KnownDevices.instance.state.values;
275+
for (String actionUUID in e.actions) {
276+
BaseAction? baseAction = ref.watch(getActionFromUUIDProvider(actionUUID));
277+
if (baseAction != null &&
278+
(knownDevices.isEmpty || knownDevices.where((element) => baseAction.deviceCategory.contains(element.baseDeviceDefinition.deviceType)).isNotEmpty)) {
279+
if (text.isNotEmpty) {
280+
text += ', ';
281+
}
282+
text += baseAction.name;
283+
}
278284
}
279-
text += baseAction.name;
280-
}
281-
}
282-
return Text(convertToUwU(text.isNotEmpty ? text : triggerActionNotSet()));
285+
return Text(convertToUwU(text.isNotEmpty ? text : triggerActionNotSet()));
286+
},
287+
);
283288
},
284289
),
285290
crossFadeState: !value ? CrossFadeState.showFirst : CrossFadeState.showSecond,

lib/Frontend/translation_string_definitions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ String scanDemoGearTip() => Intl.message(
451451
);
452452

453453
String triggerActionSelectorTutorialLabel() => Intl.message(
454-
"Select as many actions as you want. An action will be randomly selected that is compatible with connected gear. GlowTip and Sound actions will trigger alongside Move actions. Don't forget to save.",
454+
"Select as many actions as you want. An action will be randomly selected that is compatible with connected gear. GlowTip and Sound actions will trigger alongside Move actions. Only actions compatible with paired gear are shown. Don't forget to save.",
455455
name: 'triggerActionSelectorTutorialLabel',
456456
desc: 'Label for the tutorial card on the Action selector for triggers',
457457
);

lib/main.dart

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,42 +162,62 @@ Future<void> initHive() async {
162162
final Directory appDir = await getApplicationSupportDirectory();
163163
Hive.init(appDir.path);
164164

165+
//Hive Type ID 1
165166
if (!Hive.isAdapterRegistered(BaseStoredDeviceAdapter().typeId)) {
166167
Hive.registerAdapter(BaseStoredDeviceAdapter());
167168
}
169+
//Hive Type ID 2
170+
if (!Hive.isAdapterRegistered(TriggerAdapter().typeId)) {
171+
Hive.registerAdapter(TriggerAdapter());
172+
}
173+
//Hive Type ID 3
168174
if (!Hive.isAdapterRegistered(MoveListAdapter().typeId)) {
169175
Hive.registerAdapter(MoveListAdapter());
170176
}
177+
//Hive Type ID 5
171178
if (!Hive.isAdapterRegistered(MoveAdapter().typeId)) {
172179
Hive.registerAdapter(MoveAdapter());
173180
}
174-
if (!Hive.isAdapterRegistered(TriggerActionAdapter().typeId)) {
175-
Hive.registerAdapter(TriggerActionAdapter());
176-
}
177-
if (!Hive.isAdapterRegistered(TriggerAdapter().typeId)) {
178-
Hive.registerAdapter(TriggerAdapter());
181+
//Hive Type ID 6
182+
if (!Hive.isAdapterRegistered(DeviceTypeAdapter().typeId)) {
183+
Hive.registerAdapter(DeviceTypeAdapter());
179184
}
185+
//Hive Type ID 7
180186
if (!Hive.isAdapterRegistered(ActionCategoryAdapter().typeId)) {
181187
Hive.registerAdapter(ActionCategoryAdapter());
182188
}
183-
if (!Hive.isAdapterRegistered(DeviceTypeAdapter().typeId)) {
184-
Hive.registerAdapter(DeviceTypeAdapter());
185-
}
186-
if (!Hive.isAdapterRegistered(MoveTypeAdapter().typeId)) {
187-
Hive.registerAdapter(MoveTypeAdapter());
189+
//Hive Type ID 8
190+
if (!Hive.isAdapterRegistered(TriggerActionAdapter().typeId)) {
191+
Hive.registerAdapter(TriggerActionAdapter());
188192
}
193+
//Hive Type ID 10
189194
if (!Hive.isAdapterRegistered(EasingTypeAdapter().typeId)) {
190195
Hive.registerAdapter(EasingTypeAdapter());
191196
}
197+
//Hive Type ID 11
198+
if (!Hive.isAdapterRegistered(MoveTypeAdapter().typeId)) {
199+
Hive.registerAdapter(MoveTypeAdapter());
200+
}
201+
//Hive Type ID 12
192202
if (!Hive.isAdapterRegistered(AudioActionAdapter().typeId)) {
193203
Hive.registerAdapter(AudioActionAdapter());
194204
}
205+
//Hive Type ID 13
195206
if (!Hive.isAdapterRegistered(FavoriteActionAdapter().typeId)) {
196207
Hive.registerAdapter(FavoriteActionAdapter());
197208
}
209+
//Hive Type ID 14
198210
if (!Hive.isAdapterRegistered(EarSpeedAdapter().typeId)) {
199211
Hive.registerAdapter(EarSpeedAdapter());
200212
}
213+
//Hive Type ID 15
214+
if (!Hive.isAdapterRegistered(GlowtipStatusAdapter().typeId)) {
215+
Hive.registerAdapter(GlowtipStatusAdapter());
216+
}
217+
//Hive Type ID 16
218+
if (!Hive.isAdapterRegistered(RGBStatusAdapter().typeId)) {
219+
Hive.registerAdapter(RGBStatusAdapter());
220+
}
201221
await Hive.openBox(settings); // Do not set type here
202222
await Hive.openBox<Trigger>(triggerBox);
203223
await Hive.openBox<FavoriteAction>(favoriteActionsBox);

0 commit comments

Comments
 (0)