diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-23 15:38:13 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-23 15:38:13 +0100 |
| commit | 7ee14396b1f1f96ed0472b5949ce82a7f9313276 (patch) | |
| tree | cddf00fe4049908155a15e813bb8d226ad710f81 /server/lib/core/methods | |
| parent | 4a45fe143bd050d89183427443dedfd656f507bc (diff) | |
server: make local variables final (prefer_final_locals)
270 locals across 52 files. Six of them were declared with an
unnecessarily nullable type (ModifierDeck? / LootDeckModel?) although
the initializer is non-nullable; non-final locals were silently
flow-promoted to the initializer's type, but final locals are not, so
the nullability is dropped where it was wrong.
Diffstat (limited to 'server/lib/core/methods')
| -rw-r--r-- | server/lib/core/methods/character_methods.dart | 10 | ||||
| -rw-r--r-- | server/lib/core/methods/deck_methods.dart | 2 | ||||
| -rw-r--r-- | server/lib/core/methods/element_methods.dart | 2 | ||||
| -rw-r--r-- | server/lib/core/methods/monster_methods.dart | 24 | ||||
| -rw-r--r-- | server/lib/core/methods/round_methods.dart | 20 | ||||
| -rw-r--r-- | server/lib/core/methods/scenario_methods.dart | 10 |
6 files changed, 34 insertions, 34 deletions
diff --git a/server/lib/core/methods/character_methods.dart b/server/lib/core/methods/character_methods.dart index 9c2705a..6cd6c10 100644 --- a/server/lib/core/methods/character_methods.dart +++ b/server/lib/core/methods/character_methods.dart @@ -193,7 +193,7 @@ class CharacterMethods { final list = character.characterState.summonList; if (list.isNotEmpty && list.first.name == name) { - int hp = health + character.characterState.level * multiplier; + final int hp = health + character.characterState.level * multiplier; list.first.setMaxHealth(s, hp); list.first.setHealth(s, hp); } @@ -261,7 +261,7 @@ class CharacterMethods { } if (name.isNotEmpty) { - MonsterInstance summon = MonsterInstance.summon( + final MonsterInstance summon = MonsterInstance.summon( _kSpecialSummonStandeeNr, MonsterType.summon, name, @@ -282,7 +282,7 @@ class CharacterMethods { List<Character> characters, { GameState? gameState, }) { - List<ListItemData> newList = []; + final List<ListItemData> newList = []; final gs = gameState ?? getIt<GameState>(); for (final item in gs.currentList) { if (item is Character) { @@ -314,7 +314,7 @@ class CharacterMethods { GameData? gameData, }) { Character? character; - List<CharacterClass> characters = []; + final List<CharacterClass> characters = []; final gd = gameData ?? getIt<GameData>(); final modelData = gd.modelData; for (String key in modelData.keys) { @@ -371,7 +371,7 @@ class CharacterMethods { } if (name.isNotEmpty) { - MonsterInstance summon = MonsterInstance.summon( + final MonsterInstance summon = MonsterInstance.summon( _kSpecialSummonStandeeNr, MonsterType.summon, name, diff --git a/server/lib/core/methods/deck_methods.dart b/server/lib/core/methods/deck_methods.dart index 535324f..a501d23 100644 --- a/server/lib/core/methods/deck_methods.dart +++ b/server/lib/core/methods/deck_methods.dart @@ -35,7 +35,7 @@ class DeckMethods { for (final item in gs.currentList) { if (item is Monster) { if (item.type.deck == deck.name) { - bool specialInactive = GameMethods.isInactiveForRule( + final bool specialInactive = GameMethods.isInactiveForRule( item.type.name, ); if ((item.monsterInstances.isNotEmpty && !specialInactive) || diff --git a/server/lib/core/methods/element_methods.dart b/server/lib/core/methods/element_methods.dart index 5da97a3..c65d53c 100644 --- a/server/lib/core/methods/element_methods.dart +++ b/server/lib/core/methods/element_methods.dart @@ -13,7 +13,7 @@ class ElementMethods { static void updateElements(_StateModifier _, {GameState? gameState}) { //elementalist special: bool elementalistPerk = false; - Character? elementalist = GameMethods.getCharacterByName("Elementalist"); + final Character? elementalist = GameMethods.getCharacterByName("Elementalist"); if (elementalist != null && elementalist.characterState.perkList[15]) { if (elementalist.characterClass.edition == "Gloomhaven 2nd Edition") { elementalistPerk = true; diff --git a/server/lib/core/methods/monster_methods.dart b/server/lib/core/methods/monster_methods.dart index c0743b3..5ba936e 100644 --- a/server/lib/core/methods/monster_methods.dart +++ b/server/lib/core/methods/monster_methods.dart @@ -29,7 +29,7 @@ class MonsterMethods { GameData? gameData, }) { final gd = gameData ?? getIt<GameData>(); - Map<String, MonsterModel> monsters = {}; + final Map<String, MonsterModel> monsters = {}; final modelData = gd.modelData; for (String key in modelData.keys) { monsters.addAll(modelData[key]?.monsters ?? {}); @@ -43,8 +43,8 @@ class MonsterMethods { List<Monster> items, { GameState? gameState, }) { - List<String> deckIds = []; - List<ListItemData> newList = []; + final List<String> deckIds = []; + final List<ListItemData> newList = []; final gs = gameState ?? getIt<GameState>(); for (final item in gs.currentList) { if (item is Monster) { @@ -235,7 +235,7 @@ class MonsterMethods { GameState? gameState, }) { int levelAdjust = 0; - Set<String> alliedMonsters = {}; + final Set<String> alliedMonsters = {}; for (final rule in specialRules) { if (rule.name == monster || rule.name == "Enemies") { if (rule.type == "LevelAdjust") { @@ -285,7 +285,7 @@ class MonsterMethods { }) { final gs = gameState ?? getIt<GameState>(); //handle room data - int characterIndex = + final int characterIndex = GameMethods.getCurrentCharacterAmount().clamp( _kMinCharacters, _kMaxCharacters, @@ -295,7 +295,7 @@ class MonsterMethods { final roomMonsters = roomMonsterData[i]; addMonster(stateModifier, roomMonsters.name, gs._scenarioSpecialRules); } - bool addSorted = gs.currentCampaign == "Buttons and Bugs"; + final bool addSorted = gs.currentCampaign == "Buttons and Bugs"; final s = settings ?? getIt<Settings>(); if (!s.noStandees && s.autoAddStandees) { if (s.randomStandees || addSorted) { @@ -303,17 +303,17 @@ class MonsterMethods { initMessage += "\n"; } for (int i = 0; i < roomMonsterData.length; i++) { - List<int> normals = []; - List<int> elites = []; + final List<int> normals = []; + final List<int> elites = []; final roomMonsters = roomMonsterData[i]; - Monster data = + final Monster data = gs.currentList.firstWhereOrNull( (element) => element.id == roomMonsters.name, ) as Monster; - int eliteAmount = roomMonsters.elite[characterIndex]; - int normalAmount = roomMonsters.normal[characterIndex]; + final int eliteAmount = roomMonsters.elite[characterIndex]; + final int normalAmount = roomMonsters.normal[characterIndex]; bool isBoss = false; if (data.type.levels.first.boss != null) { @@ -321,7 +321,7 @@ class MonsterMethods { } for (int i = 0; i < eliteAmount; i++) { - int randomNr = GameMethods.getRandomStandee(data); + final int randomNr = GameMethods.getRandomStandee(data); if (randomNr != 0) { elites.add(randomNr); executeAddStandee( diff --git a/server/lib/core/methods/round_methods.dart b/server/lib/core/methods/round_methods.dart index 4ad146d..5102fb2 100644 --- a/server/lib/core/methods/round_methods.dart +++ b/server/lib/core/methods/round_methods.dart @@ -96,8 +96,8 @@ class RoundMethods { int init = 0; for (int i = 0; i < newList.length; i++) { - ListItemData currentItem = newList[i]; - int currentItemInitiative = GameMethods.getInitiative(currentItem); + final ListItemData currentItem = newList[i]; + final int currentItemInitiative = GameMethods.getInitiative(currentItem); if (currentItemInitiative > initiative && currentItemInitiative > init) { if (i > currentTurnItemIndex) { newList.insert(i, item); @@ -265,18 +265,18 @@ class RoundMethods { }) { final gs = gameState ?? getIt<GameState>(); final gd = gameData ?? getIt<GameData>(); - List<SpecialRule>? rules = + final List<SpecialRule>? rules = gd.modelData[gs.currentCampaign]?.scenarios[gs.scenario]?.specialRules; if (rules != null) { for (SpecialRule rule in rules) { if (rule.type == "Objective" || rule.type == "Escort") { - Character? character = + final Character? character = gs.currentList.firstWhereOrNull( (element) => element.id == rule.name, ) as Character?; if (character != null) { - int? newHealth = StatCalculator.calculateFormula( + final int? newHealth = StatCalculator.calculateFormula( rule.health.toString(), ); if (newHealth != character.characterState.maxHealth && @@ -286,14 +286,14 @@ class RoundMethods { } } } else if (rule.type == "LevelAdjust") { - Monster? monster = + final Monster? monster = gs.currentList.firstWhereOrNull( (element) => element.id == rule.name, ) as Monster?; if (monster != null) { if (gs.level == monster.level) { - int newLevel = (monster.level + rule.level).clamp( + final int newLevel = (monster.level + rule.level).clamp( _kMinLevel, _kMaxLevel, ); @@ -361,7 +361,7 @@ class RoundMethods { final conditions = figure._conditions; //handle chill separately - int nrOfChills = figure.conditions + final int nrOfChills = figure.conditions .where((a) => a == Condition.chill) .length; if (nrOfChills > 0) { @@ -380,7 +380,7 @@ class RoundMethods { .length; for (int i = conditions.length - 1; i >= 0; i--) { - Condition item = conditions[i]; + final Condition item = conditions[i]; if (GameMethods.canExpire(item)) { if (item != Condition.chill) { if (!figure.conditionsAddedThisTurn.contains(item)) { @@ -463,7 +463,7 @@ class RoundMethods { //get next active item and set to current for (; newIndex < gs.currentList.length; newIndex++) { - ListItemData data = gs.currentList[newIndex]; + final ListItemData data = gs.currentList[newIndex]; if (data is Monster) { if (data.isActive && !GameMethods.isInactiveForRule(data.type.name)) { if (data.turnState == TurnsState.done) { diff --git a/server/lib/core/methods/scenario_methods.dart b/server/lib/core/methods/scenario_methods.dart index 257d076..a75fc80 100644 --- a/server/lib/core/methods/scenario_methods.dart +++ b/server/lib/core/methods/scenario_methods.dart @@ -107,7 +107,7 @@ class ScenarioMethods { gs._scenario = scenario; gs._scenarioSectionsAdded = []; - List<ListItemData> newList = []; + final List<ListItemData> newList = []; for (final item in gs.currentList) { if (item is Character) { if (!GameMethods.isObjectiveOrEscort(item.characterClass)) { @@ -127,14 +127,14 @@ class ScenarioMethods { static void _initLootDeck(String scenario, GameState gs, GameData gd) { if (scenario != "custom") { final campaignModel = gd.modelData[gs.currentCampaign]; - LootDeckModel? lootDeckModel = + final LootDeckModel? lootDeckModel = campaignModel?.scenarios[scenario]?.lootDeck; lootDeckModel != null ? gs._lootDeck = LootDeck(lootDeckModel, gs.lootDeck) : gs._lootDeck = LootDeck.from(gs.lootDeck); } else { if (gs.currentCampaign == "Frosthaven") { - LootDeckModel? lootDeckModel = const LootDeckModel( + final LootDeckModel lootDeckModel = const LootDeckModel( 2, 2, 2, @@ -171,7 +171,7 @@ class ScenarioMethods { List<String> monsters = []; List<SpecialRule> specialRules = []; List<RoomMonsterData> roomMonsterData = []; - List<String> subSections = []; + final List<String> subSections = []; String initMessage = ""; if (section) { @@ -256,7 +256,7 @@ class ScenarioMethods { if (item.type == "Objective") { if (item.condition == "" || StatCalculator.evaluateCondition(item.condition as Object)) { - Character? objective = CharacterMethods.createCharacter( + final Character? objective = CharacterMethods.createCharacter( s, "Objective", null, |
