diff --git a/lib/models/mods/factionUpgrades/cef.dart b/lib/models/mods/factionUpgrades/cef.dart index a0fb5d55..af7c75ca 100644 --- a/lib/models/mods/factionUpgrades/cef.dart +++ b/lib/models/mods/factionUpgrades/cef.dart @@ -219,11 +219,11 @@ class CEFMods extends FactionModification { fm.addMod>( UnitAttribute.traits, (value) { - final newValue = Trait.ECMPlus(); + final newValue = Trait.ECM(); var newList = new List.from(value); - if (!newList - .any((t) => t.isSameType(newValue) || t.isSameType(Trait.ECM()))) { + if (!newList.any( + (t) => t.isSameType(newValue) || t.isSameType(Trait.ECMPlus()))) { newList.add(newValue); } @@ -234,7 +234,7 @@ class CEFMods extends FactionModification { fm.addMod>( UnitAttribute.traits, - createAddTraitToList(Trait.Sensors(36)), + createAddOrReplaceSameTraitInList(Trait.Sensors(36)), description: '+Sensors:36', ); diff --git a/lib/models/mods/mods.dart b/lib/models/mods/mods.dart index 6dc3aa04..82ce409c 100644 --- a/lib/models/mods/mods.dart +++ b/lib/models/mods/mods.dart @@ -84,6 +84,28 @@ List Function(List) createAddTraitToList(Trait newValue) { }; } +List Function(List) createAddOrReplaceSameTraitInList( + Trait newTrait) { + return (value) { + var newList = new List.from(value); + + final index = newList.indexWhere((trait) => trait.isSameType(newTrait)); + if (index >= 0) { + newList.removeAt(index); + } + + if (!newList.any((element) => element.name == newTrait.name)) { + if (index >= 0) { + newList.insert(index, newTrait); + } else { + newList.add(newTrait); + } + } + + return newList; + }; +} + /// Add the trait to the list if it does not already exist in the list. Otherwise /// combine the trait with the existing trait in the list by summing the levels. List Function(List) createAddOrCombineTraitToList( diff --git a/pubspec.yaml b/pubspec.yaml index bf2417f0..d1e2c4f4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.13.0 +version: 1.13.1 environment: sdk: ">=3.0.0"