Add Aniimo guides and link game cards to toolbox checklists
Some checks failed
Deploy Sokko G / deploy (push) Failing after 3s

This commit is contained in:
Shinuwa 2026-09-23 20:05:19 +02:00
parent f0797ccf14
commit 13434f72f6
278 changed files with 10025 additions and 57 deletions

View file

@ -0,0 +1,58 @@
// Rôle : reconnaît les lignes de checklist et valide les associations temporaires des guides.
export const GUIDE_CHECKLIST_SESSION_KEY = "sokkog:guide-checklists";
const GUIDES = new Set(["aniimo/aniimos", "mhwilds/monsters", "mhwilds/endemic", "diablo4/affixes"]);
export function normalizeGuideLabel(value) {
return String(value || "").normalize("NFD").replace(/[\u0300-\u036f]/g, "")
.toLocaleLowerCase("fr").replace(/œ/g, "oe").replace(/æ/g, "ae").trim().replace(/\s+/g, " ");
}
export function matchGuideChecklist(entries, data) {
const rows = Array.isArray(data?.sections) ? data.sections.flatMap((section) => section.items || []) : data?.items || [];
const byLabel = new Map();
for (const row of rows) {
const label = normalizeGuideLabel(row.label);
if (!label) continue;
if (!byLabel.has(label)) byLabel.set(label, []);
byLabel.get(label).push(row);
}
const findRows = (labels = []) => [...new Set(labels.map(normalizeGuideLabel))].flatMap((label) => byLabel.get(label) || []);
const matched = new Set();
const completed = new Set();
for (const entry of entries) {
const specific = findRows(entry.labels);
const matches = specific.length ? specific : findRows(entry.fallbackLabels);
if (!matches.length) continue;
matched.add(entry.key);
if (matches.every((row) => Number(row.qtyCurrent || 0) >= Math.max(1, Number(row.qtyTarget || 1)))) completed.add(entry.key);
}
return { count: matched.size, completed };
}
export function validGuideAssociations(value, toolboxes, links) {
return Object.fromEntries(Object.entries(value || {}).filter(([guideId, association]) => {
if (!GUIDES.has(guideId) || !association || typeof association !== "object") return false;
const toolbox = toolboxes.find((item) => item.id === association.toolboxId && item.id === links[guideId.split("/")[0]]);
return toolbox?.modules.some((module) => module.id === association.moduleId && module.type === "checklist");
}).map(([key, association]) => [key, {
toolboxId: association.toolboxId, moduleId: association.moduleId, hideCompleted: association.hideCompleted === true
}]));
}
export function aniimoChecklistEntries(variants, translations, englishTranslations) {
return variants.map((variant) => {
const names = [translations[variant.name], englishTranslations[variant.name]].filter(Boolean);
const forms = [translations[variant.form], englishTranslations[variant.form]].filter(Boolean);
return { key: variant.key, labels: names.flatMap((name) => forms.map((form) => `${name} — ${form}`)), fallbackLabels: names };
});
}
export function getGuideChecklistEntries(guideId, { aniimo, mhwilds, diablo4 }) {
if (!GUIDES.has(guideId)) return null;
if (guideId === "aniimo/aniimos") return aniimo.loaded ? aniimoChecklistEntries(aniimo.variants, aniimo.translations, aniimo.englishTranslations) : null;
if (guideId === "diablo4/affixes") return diablo4.loaded ? diablo4.affixes.map((affix) => ({ key: affix.id, labels: [affix.label] })) : null;
if (!mhwilds.loaded) return null;
return (guideId === "mhwilds/monsters" ? mhwilds.monsters : mhwilds.endemic).map((item) => ({
key: item.name, labels: [mhwilds.translations[item.name] || item.name.replace(/_/g, " ")]
}));
}