From a5f4fd2eed31582957b228cd233630e859f450a8 Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Tue, 31 Oct 2023 16:36:52 -0500 Subject: [PATCH] Apply barrack_us icon workaround --- src/unitStats/mappings.ts | 18 ++++++++++++++++++ src/unitStats/workarounds.ts | 27 +++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/unitStats/mappings.ts b/src/unitStats/mappings.ts index 5b4057d3..9435604b 100644 --- a/src/unitStats/mappings.ts +++ b/src/unitStats/mappings.ts @@ -5,6 +5,7 @@ import { getSbpsStats } from "./mappingSbps"; import { getUpgradesStats } from "./mappingUpgrades"; import { getAbilitiesStats } from "./mappingAbilities"; import { getBattlegroupStats } from "./mappingBattlegroups"; +import { ebpsWorkarounds } from "./workarounds"; const getMappings = async () => { // Locstring needs to be fetched first because it's used by the other mappings. @@ -20,6 +21,23 @@ const getMappings = async () => { getBattlegroupStats(), ]); + for (const ebpsItem of ebpsData) { + for (const [override, { predicate, mutator, validator }] of ebpsWorkarounds) { + if (predicate(ebpsItem)) { + mutator(ebpsItem); + console.info(`Overriding ${ebpsItem.id} with ${override}`); + if (validator && !validator(ebpsItem)) { + console.error(`Invalid item ${ebpsItem.id} after override ${override}`, ebpsItem); + // throw new Error("Error during ebps workarounds"); + } + } + } + } + console.log( + "🚀 ~ file: mappings.ts:15 ~ getMappings ~ ebpsData:", + ebpsData.find((x) => x.id === "barracks_us"), + ); + return { locstring, weaponData, diff --git a/src/unitStats/workarounds.ts b/src/unitStats/workarounds.ts index 4609513e..5911a1db 100644 --- a/src/unitStats/workarounds.ts +++ b/src/unitStats/workarounds.ts @@ -19,6 +19,12 @@ function bgWorkaround(description: string, override: Override) { const bgWorkarounds = new Map(); +function ebpsWorkaround(description: string, override: Override) { + ebpsWorkarounds.set(description, override); +} + +const ebpsWorkarounds = new Map(); + // --------------------- BATTLEGROUPS --------------------- // function setBattlegroupsWorkarounds() { @@ -222,6 +228,9 @@ function setBattlegroupsWorkarounds() { // Paradropped Infantry Branch. item.branches.RIGHT.upgrades.forEach((upg) => { switch (upg.ability.id) { + case "airborne_right_1a_pathfinders_us": + upg.spawnItems = ["pathfinder_us"]; + break; case "airborne_right_1b_paradrop_hmg_us": upg.spawnItems = ["hmg_30cal_paradrop_us"]; break; @@ -379,8 +388,22 @@ function setBattlegroupsWorkarounds() { }); } +// --------------------- EBPS --------------------- // + +function setEbpsWorkarounds() { + ebpsWorkaround("Modify American - Barracks Icon", { + predicate: (item) => item.faction === "american" && item.id === "barracks_us", + mutator: (item) => { + item = item as EbpsType; + item.ui.iconName = "races/american/buildings/barracks_us"; + }, + }); +} + setBattlegroupsWorkarounds(); +setEbpsWorkarounds(); -console.log(`Total BG workarounds: ${bgWorkarounds.size}`); +// console.log(`Total BG workarounds: ${bgWorkarounds.size}`); +// console.log(`Total Ebps workarounds: ${ebpsWorkarounds.size}`); -export { bgWorkarounds }; +export { bgWorkarounds, ebpsWorkarounds };