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

[#72] Add support for matching renders to diffs #73

Merged
merged 1 commit into from
Oct 16, 2024
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
5 changes: 5 additions & 0 deletions .changeset/heavy-shoes-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osrs-wiki/cache-mediawiki": patch
---

Fix combat achievement monster map enum id
5 changes: 5 additions & 0 deletions .changeset/wicked-adults-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osrs-wiki/cache-mediawiki": minor
---

Add support for matching renders to diffs
1 change: 1 addition & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type CacheMediaWikiContext = {
scenery?: { [key: string]: string };
};
infoboxes?: boolean;
renders?: boolean;
update?: string;
updateDate?: string;
};
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
examines,
examinesVersion,
infobox,
renders,
update,
updateDate,
},
Expand Down Expand Up @@ -53,6 +54,9 @@ const {
infobox: {
type: "string",
},
renders: {
type: "string",
},
update: {
type: "string",
},
Expand All @@ -63,6 +67,7 @@ const {
});

Context.infoboxes = infobox === "true";
Context.renders = renders === "true";
Context.update = update;
Context.updateDate = updateDate;

Expand Down
13 changes: 13 additions & 0 deletions src/scripts/combatAchievements/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { formatMonsterName } from "../utils";

describe("combatAchievements utils", () => {
test("formatMonsterName with comma", () => {
expect(formatMonsterName("Whisperer, The")).toEqual("The Whisperer");
});
test("formatMonsterName with no spaces", () => {
expect(formatMonsterName("Vorkath")).toEqual("Vorkath");
});
test("formatMonsterName with spaces", () => {
expect(formatMonsterName("DK: Rex")).toEqual("DK: Rex");
});
});
15 changes: 13 additions & 2 deletions src/scripts/combatAchievements/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { formatFileName } from "../../utils/files";
export const TIER_ENUM_ID = 3967;
export const TYPE_ENUM_ID = 3968;
export const TIER_MAP_ENUM_ID = 3980;
export const MONSTER_MAP_ENUM_ID = 3970;
export const MONSTER_MAP_ENUM_ID = 3971;
export const CA_TASKS = [3981, 3982, 3983, 3984, 3985, 3986];

/**
Expand Down Expand Up @@ -52,19 +52,30 @@ export const getCombatAchievement = (
const typeKey = struct.params.get(TYPE_PARAM_ID as ParamID) as number;

const monster = monsterMap.get(monsterKey) as string;
const monsterFormatted = monster ? formatMonsterName(monster) : "";
const tier = tierMap.get(tierKey) as CombatAchievementTier;
const type = typeMap.get(typeKey) as CombatAchievementType;

return {
id,
title,
description,
monster,
monster: monsterFormatted,
tier,
type,
};
};

/**
* Format a monster name from the enum.
* @param monster The monster name from the enum
* @returns
*/
export const formatMonsterName = (monster: string) => {
const split = monster.split(", ");
return split.reverse().join(" ");
};

/**
* Write a CombatAchievement to a file.
* The file name is the title of the achievement.
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/differences/file/content/items.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Context from "../../../../context";
import { Item, ItemID, Reader } from "../../../../utils/cache2";
import { buildItemInfobox } from "../../../infoboxGenernator/infoboxes/item";
import { renderItems } from "../../../renders";
import { CompareFn } from "../../differences.types";
import { getFileDifferences } from "../file.utils";

Expand Down Expand Up @@ -33,6 +34,10 @@ const compareItems: CompareFn = ({ oldFile, newFile }) => {
buildItemInfobox(newEntry);
}

if (Context.renders) {
renderItems(newEntry);
}

return getFileDifferences(oldEntry, newEntry);
};

Expand Down
5 changes: 5 additions & 0 deletions src/scripts/differences/file/content/npcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildMonsterInfobox,
buildNpcInfobox,
} from "../../../infoboxGenernator/infoboxes/npc/npc";
import { renderNpcs } from "../../../renders/npcs";
import { CompareFn } from "../../differences.types";
import { getFileDifferences } from "../file.utils";

Expand Down Expand Up @@ -40,6 +41,10 @@ const compareNpcs: CompareFn = ({ oldFile, newFile }) => {
}
}

if (Context.renders) {
renderNpcs(newEntry);
}

return getFileDifferences(oldEntry, newEntry);
};

Expand Down
1 change: 1 addition & 0 deletions src/scripts/renders/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./items";
26 changes: 26 additions & 0 deletions src/scripts/renders/items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { existsSync } from "fs";
import { copyFile, mkdir } from "fs/promises";

import Context from "../../context";
import { Item } from "../../utils/cache2";

export const renderItems = async (item: Item) => {
if (item.name.toLocaleLowerCase() === "null") {
return;
}
if (
Context.renders &&
existsSync("./data/renders/item/" + item.id + ".png")
) {
await mkdir("./out/renders/item", { recursive: true });
await mkdir("./out/renders/miniitems", { recursive: true });
copyFile(
"./data/renders/item/" + item.id + ".png",
"./out/renders/item/" + item.name + " detail.png"
);
copyFile(
"./data/renders/miniitems/" + item.id + ".png",
"./out/renders/miniitems/" + item.name + ".png"
);
}
};
25 changes: 25 additions & 0 deletions src/scripts/renders/npcs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { existsSync } from "fs";
import { copyFile, mkdir } from "fs/promises";

import Context from "../../context";
import { NPC } from "../../utils/cache2";

export const renderNpcs = async (npc: NPC) => {
if (npc.name.toLocaleLowerCase() === "null") {
return;
}
if (Context.renders && existsSync("./data/renders/npc/" + npc.id + ".png")) {
await mkdir("./out/renders/npc", { recursive: true });
copyFile(
"./data/renders/npc/" + npc.id + ".png",
"./out/renders/npc/" + npc.name + ".png"
);
if (existsSync("./data/renders/chathead/" + npc.id + ".png")) {
await mkdir("./out/renders/chathead", { recursive: true });
copyFile(
"./data/renders/chathead/" + npc.id + ".png",
"./out/renders/chathead/" + npc.name + ".png"
);
}
}
};
Loading