Add Aniimo elemental matchup calculator
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 18m14s
Validate and deploy Sokko G / deploy (push) Successful in 10s

This commit is contained in:
Shinuwa 2026-10-31 09:43:04 +01:00
parent 72b3b15c7e
commit 243465720f
15 changed files with 518 additions and 10 deletions

View file

@ -0,0 +1,59 @@
// Rôle : valide la table des éléments Aniimo et les calculs directionnels simples et doubles.
import { readFile, access } from "node:fs/promises";
import { test } from "node:test";
import assert from "node:assert/strict";
import { calculateElementMatchups } from "../website/src/features/games/aniimo/elementMatchups.js";
const readJson = async (file) => JSON.parse(await readFile(`website/public/data/aniimo/${file}`, "utf8"));
const chart = await readJson("elements.json");
test("element chart covers every catalogue element, translation and icon without implicit neutral cells", async () => {
const catalogue = await readJson("aniimos.json");
const elements = [...new Set(catalogue.flatMap((aniimo) => aniimo.variations.flatMap((variant) => variant.elements)))].sort();
assert.deepEqual([...chart.elements].sort(), elements);
assert.equal(chart.elements.length, 9);
assert.deepEqual(Object.keys(chart.matchups).sort(), elements);
assert.equal(chart.dualDefenseRule, "multiply");
assert.equal(new URL(chart.source.url).protocol, "https:");
assert.match(chart.source.checkedOn, /^\d{4}-\d{2}-\d{2}$/);
for (const language of ["fr", "en"]) {
const dictionary = await readJson(`i18n/${language}.json`);
for (const element of elements) assert.ok(dictionary[element]?.trim());
}
for (const element of elements) {
await access(`website/public/static/img/aniimo/${element}.webp`);
assert.deepEqual(Object.keys(chart.matchups[element]).sort(), elements);
assert.ok(Object.values(chart.matchups[element]).every((value) => [0.625, 1, 1.6].includes(value)));
}
});
const row = (selected, element) => calculateElementMatchups(chart, selected).find((result) => result.element === element);
test("single elements preserve directional matchups and Dark's neutral mirror", () => {
assert.equal(row(["electric"], "water").attack[0].multiplier, 1.6);
assert.equal(row(["electric"], "water").defense, 1);
assert.equal(row(["dark"], "dark").defense, 1);
assert.equal(row(["fire"], "fire").defense, 0.625);
});
test("dual defense combines weaknesses, resistances and cancellation without floating point noise", () => {
assert.equal(row(["dark", "grass"], "wind").defense, 2.56);
assert.equal(row(["fire", "rock"], "ice").defense, 0.390625);
assert.equal(row(["water", "ice"], "fire").defense, 1);
assert.equal(row(["water", "ice"], "grass").defense, 1.6);
assert.equal(row(["water", "ice"], "dark").defense, 0.625);
assert.deepEqual(row(["ice", "water"], "fire").defense, row(["water", "ice"], "fire").defense);
});
test("dual offense keeps each skill's element separate instead of multiplying them", () => {
assert.deepEqual(row(["water", "ice"], "fire").attack, [
{ element: "water", multiplier: 1.6 }, { element: "ice", multiplier: 0.625 }
]);
});
test("empty and invalid selections cannot produce misleading multipliers", () => {
assert.equal(calculateElementMatchups(chart, []), null);
assert.deepEqual(calculateElementMatchups(chart, ["fire", "fire"]), calculateElementMatchups(chart, ["fire"]));
assert.throws(() => calculateElementMatchups(chart, ["unknown"]), RangeError);
assert.throws(() => calculateElementMatchups(chart, ["fire", "water", "ice"]), RangeError);
});

View file

@ -172,7 +172,8 @@ test("loader passes cancellation to all requests and reports failed responses",
const controller = new AbortController();
const listIndex = await readJson("aniimo/lists/index.json");
const regions = await readJson("aniimo/lists/regions.json");
const bodies = [aniimos, fr, en, listIndex, regions];
const elementChart = await readJson("aniimo/elements.json");
const bodies = [aniimos, fr, en, listIndex, elementChart, regions];
context.mock.method(globalThis, "fetch", async (url, options) => {
calls.push({ url, options });
const body = bodies[calls.length - 1];
@ -183,7 +184,8 @@ test("loader passes cancellation to all requests and reports failed responses",
assert.equal(result.lists.length, 1);
assert.equal(result.lists[0].id, "regions");
assert.equal(result.lists[0].itemCount, 14);
assert.equal(calls.length, 5);
assert.deepEqual(result.elementChart, elementChart);
assert.equal(calls.length, 6);
assert.ok(calls.every((call) => call.options.signal === controller.signal));
globalThis.fetch.mock.mockImplementation(async () => ({ ok: false }));
await assert.rejects(loadAniimoData(controller.signal), /indisponibles/);

View file

@ -141,6 +141,27 @@ export function validateSiteContent(site) {
"aniimo.stats.m_def",
"aniimo.stats.break",
"aniimo.stats.regen",
"aniimo.elementCalculator.title",
"aniimo.elementCalculator.homeDescription",
"aniimo.elementCalculator.description",
"aniimo.elementCalculator.selection",
"aniimo.elementCalculator.reset",
"aniimo.elementCalculator.hint",
"aniimo.elementCalculator.limit",
"aniimo.elementCalculator.empty",
"aniimo.elementCalculator.attack",
"aniimo.elementCalculator.defense",
"aniimo.elementCalculator.attackHelp",
"aniimo.elementCalculator.defenseHelp",
"aniimo.elementCalculator.skill",
"aniimo.elementCalculator.attackBands.low",
"aniimo.elementCalculator.attackBands.normal",
"aniimo.elementCalculator.attackBands.high",
"aniimo.elementCalculator.defenseBands.veryLow",
"aniimo.elementCalculator.defenseBands.low",
"aniimo.elementCalculator.defenseBands.normal",
"aniimo.elementCalculator.defenseBands.high",
"aniimo.elementCalculator.defenseBands.veryHigh",
"aniimo.title",
"aniimo.description",
"aniimo.homeDescription",