@@ -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 )
0 commit comments