diff --git a/.changeset/heavy-shoes-sleep.md b/.changeset/heavy-shoes-sleep.md new file mode 100644 index 0000000..2cc45fe --- /dev/null +++ b/.changeset/heavy-shoes-sleep.md @@ -0,0 +1,5 @@ +--- +"@osrs-wiki/cache-mediawiki": patch +--- + +Fix combat achievement monster map enum id diff --git a/.changeset/wicked-adults-speak.md b/.changeset/wicked-adults-speak.md new file mode 100644 index 0000000..d59c1fd --- /dev/null +++ b/.changeset/wicked-adults-speak.md @@ -0,0 +1,5 @@ +--- +"@osrs-wiki/cache-mediawiki": minor +--- + +Add support for matching renders to diffs diff --git a/src/context.ts b/src/context.ts index 80734a5..0887a78 100644 --- a/src/context.ts +++ b/src/context.ts @@ -4,6 +4,7 @@ type CacheMediaWikiContext = { scenery?: { [key: string]: string }; }; infoboxes?: boolean; + renders?: boolean; update?: string; updateDate?: string; }; diff --git a/src/index.ts b/src/index.ts index 657863c..1b16b0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ const { examines, examinesVersion, infobox, + renders, update, updateDate, }, @@ -53,6 +54,9 @@ const { infobox: { type: "string", }, + renders: { + type: "string", + }, update: { type: "string", }, @@ -63,6 +67,7 @@ const { }); Context.infoboxes = infobox === "true"; +Context.renders = renders === "true"; Context.update = update; Context.updateDate = updateDate; diff --git a/src/scripts/combatAchievements/__tests__/utils.test.ts b/src/scripts/combatAchievements/__tests__/utils.test.ts new file mode 100644 index 0000000..e49dc5f --- /dev/null +++ b/src/scripts/combatAchievements/__tests__/utils.test.ts @@ -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"); + }); +}); diff --git a/src/scripts/combatAchievements/utils.ts b/src/scripts/combatAchievements/utils.ts index 4b5fd1d..023cff3 100644 --- a/src/scripts/combatAchievements/utils.ts +++ b/src/scripts/combatAchievements/utils.ts @@ -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]; /** @@ -52,6 +52,7 @@ 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; @@ -59,12 +60,22 @@ export const getCombatAchievement = ( 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. diff --git a/src/scripts/differences/file/content/items.ts b/src/scripts/differences/file/content/items.ts index 6890a22..311659a 100644 --- a/src/scripts/differences/file/content/items.ts +++ b/src/scripts/differences/file/content/items.ts @@ -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"; @@ -33,6 +34,10 @@ const compareItems: CompareFn = ({ oldFile, newFile }) => { buildItemInfobox(newEntry); } + if (Context.renders) { + renderItems(newEntry); + } + return getFileDifferences(oldEntry, newEntry); }; diff --git a/src/scripts/differences/file/content/npcs.ts b/src/scripts/differences/file/content/npcs.ts index a910211..1c4502c 100644 --- a/src/scripts/differences/file/content/npcs.ts +++ b/src/scripts/differences/file/content/npcs.ts @@ -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"; @@ -40,6 +41,10 @@ const compareNpcs: CompareFn = ({ oldFile, newFile }) => { } } + if (Context.renders) { + renderNpcs(newEntry); + } + return getFileDifferences(oldEntry, newEntry); }; diff --git a/src/scripts/renders/index.ts b/src/scripts/renders/index.ts new file mode 100644 index 0000000..780fb80 --- /dev/null +++ b/src/scripts/renders/index.ts @@ -0,0 +1 @@ +export * from "./items"; diff --git a/src/scripts/renders/items.ts b/src/scripts/renders/items.ts new file mode 100644 index 0000000..5a29058 --- /dev/null +++ b/src/scripts/renders/items.ts @@ -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" + ); + } +}; diff --git a/src/scripts/renders/npcs.ts b/src/scripts/renders/npcs.ts new file mode 100644 index 0000000..e1b2fc8 --- /dev/null +++ b/src/scripts/renders/npcs.ts @@ -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" + ); + } + } +};