Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply small fixes to USF via workarounds. #285

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/unitStats/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
27 changes: 25 additions & 2 deletions src/unitStats/workarounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function bgWorkaround(description: string, override: Override) {

const bgWorkarounds = new Map<string, Override>();

function ebpsWorkaround(description: string, override: Override) {
ebpsWorkarounds.set(description, override);
}

const ebpsWorkarounds = new Map<string, Override>();

// --------------------- BATTLEGROUPS --------------------- //

function setBattlegroupsWorkarounds() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw I am wondering how come that this is wrong in the source files.

},
});
}

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 };