Skip to content

Commit

Permalink
Merge pull request #414 from Ariemeth/fix_cefff_ew_duelists_mod
Browse files Browse the repository at this point in the history
EW Duelists mod now correctly adds ECM and replaces existing sensors …
  • Loading branch information
Ariemeth authored Sep 28, 2024
2 parents ef98382 + 16db3c3 commit 9a5d2d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/models/mods/factionUpgrades/cef.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ class CEFMods extends FactionModification {
fm.addMod<List<Trait>>(
UnitAttribute.traits,
(value) {
final newValue = Trait.ECMPlus();
final newValue = Trait.ECM();
var newList = new List<Trait>.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);
}

Expand All @@ -234,7 +234,7 @@ class CEFMods extends FactionModification {

fm.addMod<List<Trait>>(
UnitAttribute.traits,
createAddTraitToList(Trait.Sensors(36)),
createAddOrReplaceSameTraitInList(Trait.Sensors(36)),
description: '+Sensors:36',
);

Expand Down
22 changes: 22 additions & 0 deletions lib/models/mods/mods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ List<Trait> Function(List<Trait>) createAddTraitToList(Trait newValue) {
};
}

List<Trait> Function(List<Trait>) createAddOrReplaceSameTraitInList(
Trait newTrait) {
return (value) {
var newList = new List<Trait>.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<Trait> Function(List<Trait>) createAddOrCombineTraitToList(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 9a5d2d5

Please sign in to comment.