add list page and multiples optis
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s
This commit is contained in:
parent
d9d22683dc
commit
959fa42454
30 changed files with 1015 additions and 45 deletions
|
|
@ -5,6 +5,7 @@ export const INITIAL_MHWILDS_STATE = {
|
|||
translations: {},
|
||||
monsters: [],
|
||||
endemic: [],
|
||||
lists: [],
|
||||
filterOptions: { monsters: [], endemic: [] },
|
||||
filterOptionKeys: { monsters: "", endemic: "" }
|
||||
};
|
||||
|
|
@ -20,21 +21,24 @@ export const INITIAL_DIABLO4_STATE = {
|
|||
};
|
||||
|
||||
export async function loadMhwildsData() {
|
||||
const [monstersResponse, endemicResponse, translationsResponse] = await Promise.all([
|
||||
const [monstersResponse, endemicResponse, listIndexResponse, translationsResponse] = await Promise.all([
|
||||
fetch("/data/mhwilds/monsters.json"),
|
||||
fetch("/data/mhwilds/endemic_life.json"),
|
||||
fetch("/data/mhwilds/lists/index.json"),
|
||||
fetch("/data/mhwilds/i18n/fr.json")
|
||||
]);
|
||||
|
||||
if (!monstersResponse.ok || !endemicResponse.ok || !translationsResponse.ok) {
|
||||
if (!monstersResponse.ok || !endemicResponse.ok || !listIndexResponse.ok || !translationsResponse.ok) {
|
||||
throw new Error("Impossible de charger les données Monster Hunter Wilds.");
|
||||
}
|
||||
|
||||
const [monstersJson, endemicJson, translations] = await Promise.all([
|
||||
const [monstersJson, endemicJson, listIndexJson, translations] = await Promise.all([
|
||||
monstersResponse.json(),
|
||||
endemicResponse.json(),
|
||||
listIndexResponse.json(),
|
||||
translationsResponse.json()
|
||||
]);
|
||||
const lists = await loadGameLists("mhwilds", listIndexJson);
|
||||
const monsterFilterKey = Object.keys(monstersJson).find((key) => key !== "monsters") || "";
|
||||
const endemicFilterKey = Object.keys(endemicJson).find((key) => key !== "endemicLife" && key !== "aquaticLife") || "";
|
||||
|
||||
|
|
@ -45,6 +49,7 @@ export async function loadMhwildsData() {
|
|||
translations,
|
||||
monsters: monstersJson.monsters || [],
|
||||
endemic: [...(endemicJson.endemicLife || []), ...(endemicJson.aquaticLife || [])],
|
||||
lists,
|
||||
filterOptions: {
|
||||
monsters: monstersJson[monsterFilterKey] || [],
|
||||
endemic: endemicJson[endemicFilterKey] || []
|
||||
|
|
@ -56,6 +61,51 @@ export async function loadMhwildsData() {
|
|||
};
|
||||
}
|
||||
|
||||
async function loadGameLists(gameId, indexPayload) {
|
||||
const entries = Array.isArray(indexPayload?.lists) ? indexPayload.lists : [];
|
||||
const results = await Promise.all(entries.map(async (entry) => {
|
||||
const response = await fetch(`/data/${gameId}/lists/${entry.file}`);
|
||||
if (!response.ok) throw new Error(`Impossible de charger la liste ${entry.file}.`);
|
||||
const payload = await response.json();
|
||||
return normalizeGameListFile(entry, payload);
|
||||
}));
|
||||
return results;
|
||||
}
|
||||
|
||||
function normalizeGameListFile(entry, payload) {
|
||||
const id = String(entry?.id || entry?.file || "").replace(/\.json$/i, "");
|
||||
const categories = Object.entries(payload || {}).filter(([, items]) => Array.isArray(items)).map(([categoryId, items]) => ({
|
||||
id: categoryId,
|
||||
title: formatListTitle(categoryId),
|
||||
items: Array.isArray(items) ? items.map(normalizeGameListItem).filter((item) => item.name) : []
|
||||
})).filter((category) => category.items.length);
|
||||
|
||||
return {
|
||||
id,
|
||||
title: payload?.titre || entry?.title || formatListTitle(id),
|
||||
file: entry?.file || `${id}.json`,
|
||||
categories,
|
||||
itemCount: categories.reduce((count, category) => count + category.items.length, 0)
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeGameListItem(item) {
|
||||
const hasQuantity = item?.quantite !== undefined || item?.quantity !== undefined;
|
||||
const quantity = Number.parseInt(item?.quantite ?? item?.quantity ?? 1, 10);
|
||||
return {
|
||||
name: String(item?.nom || item?.name || item?.label || "").trim(),
|
||||
description: String(item?.description || item?.quete || item?.quest || item?.source || "").trim(),
|
||||
quantity: Number.isFinite(quantity) ? quantity : 1,
|
||||
hasQuantity
|
||||
};
|
||||
}
|
||||
|
||||
function formatListTitle(value) {
|
||||
return String(value || "")
|
||||
.replace(/_/g, " ")
|
||||
.replace(/\b\p{L}/gu, (letter) => letter.toUpperCase());
|
||||
}
|
||||
|
||||
export async function loadDiablo4Data() {
|
||||
const response = await fetch("/data/diablo4/affixes_types.json");
|
||||
if (!response.ok) throw new Error("Impossible de charger les données Diablo IV.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue