Skip to content

Commit 1151170

Browse files
committed
EG legacy filtering && move definition fixes
1 parent 8d32199 commit 1151170

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

lib/Backend/Definitions/Action/base_action.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@ extension ActionCategoryExtension on ActionCategory {
5353
}
5454
}
5555

56-
@HiveType(typeId: 4)
57-
class BaseAction {
58-
@HiveField(1)
59-
String name = "";
60-
@HiveField(2)
61-
List<DeviceType> deviceCategory = DeviceType.values;
62-
@HiveField(3)
63-
final ActionCategory actionCategory = ActionCategory.hidden;
64-
@HiveField(4)
65-
final String uuid = "";
66-
final Map<DeviceType, String> nameAlias = {};
56+
abstract class BaseAction {
57+
String get name;
58+
59+
List<DeviceType> get deviceCategory;
60+
61+
ActionCategory get actionCategory;
62+
63+
String get uuid;
64+
65+
Map<DeviceType, String> get nameAlias;
6766

6867
// Priority is Wings -> Ears -> Tail -> default
6968
String getName(BuiltSet<DeviceType> connectedDeviceTypes) {
@@ -84,10 +83,10 @@ class CommandAction extends BaseAction with _$CommandAction {
8483

8584
@Implements<BaseAction>()
8685
factory CommandAction({
87-
required String command,
88-
required String name,
86+
required final String command,
87+
required final String name,
8988
required final String uuid,
90-
required List<DeviceType> deviceCategory,
89+
required final List<DeviceType> deviceCategory,
9190
required final ActionCategory actionCategory,
9291
final String? response,
9392
@Default({}) final Map<DeviceType, String> nameAlias,
@@ -133,6 +132,7 @@ class MoveList extends BaseAction with _$MoveList {
133132
@HiveField(3) @Default(ActionCategory.sequence) final ActionCategory actionCategory,
134133
@HiveField(5) @Default([]) List<Move> moves,
135134
@HiveField(6) @Default(1) double repeat,
135+
@Default({}) final Map<DeviceType, String> nameAlias,
136136
}) = _MoveList;
137137
}
138138

@@ -142,11 +142,11 @@ class EarsMoveList extends BaseAction with _$EarsMoveList {
142142

143143
@Implements<BaseAction>()
144144
factory EarsMoveList({
145-
@HiveField(1) required String name,
146-
@HiveField(4) required final String uuid,
145+
required final String name,
146+
required final String uuid,
147147
required final List<Object> commandMoves,
148-
@HiveField(2) @Default([DeviceType.ears]) List<DeviceType> deviceCategory,
149-
@HiveField(3) @Default(ActionCategory.ears) final ActionCategory actionCategory,
148+
required final List<DeviceType> deviceCategory,
149+
required final ActionCategory actionCategory,
150150
@Default({}) final Map<DeviceType, String> nameAlias,
151151
}) = _EarsMoveList;
152152
}

lib/Backend/action_registry.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class ActionRegistry {
193193
EarsMoveList(
194194
name: "Ears Wide",
195195
uuid: "d8384bcf-31ed-4b5d-a25a-da3a2f96e406",
196+
deviceCategory: [DeviceType.ears],
197+
actionCategory: ActionCategory.ears,
196198
commandMoves: [
197199
CommandAction.hiddenEars("BOTWIST 30", "BOTWIST END"),
198200
Move.delay(100),
@@ -202,6 +204,8 @@ class ActionRegistry {
202204
EarsMoveList(
203205
name: "Double Right",
204206
uuid: "0d5a9dfa-38f2-4b09-9be1-cd36236a03b0",
207+
deviceCategory: [DeviceType.ears],
208+
actionCategory: ActionCategory.ears,
205209
commandMoves: [
206210
CommandAction.hiddenEars("LETWIST 20", "LETWIST END"),
207211
Move.delay(25),
@@ -214,6 +218,8 @@ class ActionRegistry {
214218
EarsMoveList(
215219
name: "Double Left",
216220
uuid: "9a6be63e-36f5-4f50-88b6-7adf2680aa5c",
221+
deviceCategory: [DeviceType.ears],
222+
actionCategory: ActionCategory.ears,
217223
commandMoves: [
218224
CommandAction.hiddenEars("RITWIST 20", "RITWIST END"),
219225
Move.delay(25),
@@ -226,6 +232,8 @@ class ActionRegistry {
226232
EarsMoveList(
227233
name: "Right Listen",
228234
uuid: "83590dc9-f9de-4134-bcc7-8157a62a33ef",
235+
deviceCategory: [DeviceType.ears],
236+
actionCategory: ActionCategory.ears,
229237
commandMoves: [
230238
CommandAction.hiddenEars("LETWIST 20", "LETWIST END"),
231239
CommandAction.hiddenEars("RITWIST 100", "RITWIST END"),
@@ -236,6 +244,8 @@ class ActionRegistry {
236244
EarsMoveList(
237245
name: "Left Listen",
238246
uuid: "007c52d3-242a-4e27-bccc-b4b737502bfb",
247+
deviceCategory: [DeviceType.ears],
248+
actionCategory: ActionCategory.ears,
239249
commandMoves: [
240250
CommandAction.hiddenEars("RITWIST 20", "RITWIST END"),
241251
CommandAction.hiddenEars("LETWIST 100", "LETWIST END"),
@@ -246,6 +256,8 @@ class ActionRegistry {
246256
EarsMoveList(
247257
name: "Flick Left",
248258
uuid: "769dbe84-3a6e-440d-8b20-234983d36cb6",
259+
deviceCategory: [DeviceType.ears],
260+
actionCategory: ActionCategory.ears,
249261
commandMoves: [
250262
CommandAction.hiddenEars("RITWIST 30", "RITWIST END"),
251263
Move.delay(100),
@@ -255,6 +267,8 @@ class ActionRegistry {
255267
EarsMoveList(
256268
name: "Flick Right",
257269
uuid: "23144b42-6d3c-4822-8510-ec03c63c7808",
270+
deviceCategory: [DeviceType.ears],
271+
actionCategory: ActionCategory.ears,
258272
commandMoves: [
259273
CommandAction.hiddenEars("LETWIST 30", "LETWIST END"),
260274
Move.delay(100),
@@ -264,6 +278,8 @@ class ActionRegistry {
264278
EarsMoveList(
265279
name: "Hewo",
266280
uuid: "fdaff205-0a51-46a0-a5fc-4ea283dce079",
281+
deviceCategory: [DeviceType.ears],
282+
actionCategory: ActionCategory.ears,
267283
commandMoves: [
268284
CommandAction.hiddenEars("LETWIST 30", "LETWIST END"),
269285
Move.delay(50),

lib/Backend/sensors.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,18 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
259259
if (baseAction != null && moveActions.length > 1 && ((baseAction is CommandAction && hasLegacyEars) || !baseAction.deviceCategory.toSet().containsAll(flattenedDeviceTypes))) {
260260
// find the missing device type
261261
// The goal here is if a user selects multiple moves, send a move to all gear
262-
final Set<DeviceType> missingGearAction = baseAction.deviceCategory
263-
.whereNot(
264-
// filtering out the first actions ears entry if its a unified move but legacy gear is connected
265-
(element) => (DeviceType.ears == element && (baseAction is CommandAction && hasLegacyEars)),
266-
)
267-
.toSet()
268-
.difference(flattenedDeviceTypes);
262+
final Set<DeviceType> baseActionDeviceCategories = baseAction.deviceCategory.where(
263+
// filtering out the first actions ears entry if its a unified move but legacy gear is connected
264+
(element) {
265+
if (element == DeviceType.ears) {
266+
if (baseAction is CommandAction) {
267+
return hasLegacyEars;
268+
}
269+
}
270+
return true;
271+
},
272+
).toSet();
273+
final Set<DeviceType> missingGearAction = flattenedDeviceTypes.difference(baseActionDeviceCategories);
269274
final List<BaseAction> remainingActions = moveActions.where(
270275
// Check if any actions contain the device type of the gear the first action is missing
271276
(element) {
@@ -305,7 +310,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
305310

306311
// tailcontrol migration
307312
if (element.baseDeviceDefinition.deviceType == DeviceType.ears) {
308-
if (baseAction is CommandAction && element.baseDeviceDefinition.deviceType == DeviceType.ears && element.isTailCoNTROL.value == TailControlStatus.legacy) {
313+
if (baseAction is CommandAction && baseAction.actionCategory != ActionCategory.glowtip && element.baseDeviceDefinition.deviceType == DeviceType.ears && element.isTailCoNTROL.value == TailControlStatus.legacy) {
309314
return false;
310315
} else if (baseAction is EarsMoveList && element.baseDeviceDefinition.deviceType == DeviceType.ears && element.isTailCoNTROL.value == TailControlStatus.tailControl) {
311316
return false;

lib/main.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ Future<void> initHive() async {
232232
if (!SentryHive.isAdapterRegistered(FavoriteActionAdapter().typeId)) {
233233
SentryHive.registerAdapter(FavoriteActionAdapter());
234234
}
235-
if (!SentryHive.isAdapterRegistered(BaseActionAdapter().typeId)) {
236-
SentryHive.registerAdapter(BaseActionAdapter());
237-
}
238235
if (!SentryHive.isAdapterRegistered(EarSpeedAdapter().typeId)) {
239236
SentryHive.registerAdapter(EarSpeedAdapter());
240237
}

0 commit comments

Comments
 (0)