sokko-g/services/cards/expedition-content.js
Shinuwa 89eee7ce2a Add destination cards, starting with Le Cœur du Nuage Cosmique for the Primordial Nebula
A destination card is a rare that unlocks an expedition destination: it never joins a team (no tags, profile or equipment) and always shows as a full-art card. The catalog checks that it is rare and names an existing destination, and that no two cards unlock the same one.

Le Cœur du Nuage Cosmique is the first one: a new destination at the heart of the cosmic dust cloud, where a new sun may be about to form, with its landscape and its card in the Primordial Nebula packs. Full-art names at large size now keep clear of the rarity symbol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:45:17 +01:00

88 lines
6.9 KiB
JavaScript

// Rôle : charge et valide les destinations des Expéditions Sokko TCG, définies dans un fichier du serveur pour garder secrètes les destinations cachées.
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { cardExpeditionData, isExpeditionCard, STAT_IDS } from "./expedition-rules.js";
export const DEFAULT_DESTINATIONS_PATH = fileURLToPath(new URL("./content/expedition-destinations.json", import.meta.url));
const ID_PATTERN = /^[a-z0-9-]+$/;
export const DESTINATION_IMAGE_PATTERN = /^\/static\/img\/expeditions\/destinations\/[a-z0-9_-]+\.webp$/;
// Une condition ou un danger doit pouvoir être rempli par au moins ce nombre de cartes rare ou mieux.
export const MIN_MATCHING_CARDS = 3;
function fail(destination, message) {
throw new TypeError(`Expedition destination ${destination?.id ?? "?"}: ${message}`);
}
// Cartes rare ou mieux qui portent une des étiquettes, ou qui appartiennent à la collection.
function matchingCards(catalog, { tags = [], collectionId = null }) {
return catalog.cards.filter((card) => {
if (!isExpeditionCard(catalog, card.id)) return false;
const data = cardExpeditionData(catalog, card.id);
return collectionId ? data.collectionId === collectionId : data.tags.some((tag) => tags.includes(tag));
});
}
export function validateExpeditionDestinations(destinations, catalog) {
if (!Array.isArray(destinations) || !destinations.length) throw new TypeError("Expedition destinations must be a non-empty array.");
const tagIds = new Set(catalog.expeditionTags.map((tag) => tag.id));
const collectionIds = new Set(catalog.collections.map((collection) => collection.id));
const cardIds = new Set(catalog.cards.map((card) => card.id));
const ids = new Set();
for (const destination of destinations) {
if (!ID_PATTERN.test(destination?.id ?? "")) fail(destination, "needs a lowercase id.");
if (ids.has(destination.id)) fail(destination, "duplicate id.");
ids.add(destination.id);
if (typeof destination.name !== "string" || !destination.name || destination.name.length > 60) fail(destination, "name must contain 1 to 60 characters.");
if (typeof destination.description !== "string" || !destination.description || destination.description.length > 200) fail(destination, "description must contain 1 to 200 characters.");
if (destination.coverCardId != null && !cardIds.has(destination.coverCardId)) fail(destination, "unknown cover card.");
// Paysage de la destination (facultatif) : affiché dans la forme du coup de pinceau ; sinon, l'image de sa carte de couverture.
if (destination.image != null && !DESTINATION_IMAGE_PATTERN.test(destination.image)) fail(destination, "image must be a /static/img/expeditions/destinations/*.webp path.");
if (typeof destination.hidden !== "boolean") fail(destination, "hidden must be a boolean.");
if (!Array.isArray(destination.stats) || destination.stats.length !== STAT_IDS.length || new Set(destination.stats).size !== STAT_IDS.length
|| destination.stats.some((stat) => !STAT_IDS.includes(stat))) {
fail(destination, "stats must order the four stats.");
}
// Thème de la destination : une carte qui porte l'une de ces étiquettes donne l'Affinité à l'équipe.
if (!Array.isArray(destination.themeTags) || !destination.themeTags.length || destination.themeTags.some((tag) => !tagIds.has(tag))) fail(destination, "needs known theme tags.");
if (matchingCards(catalog, { tags: destination.themeTags }).length < MIN_MATCHING_CARDS) fail(destination, `theme matches fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
// Cartes des Carnets des Veilleurs que la destination peut rapporter : rare ou mieux, d'une collection des Expéditions.
const expeditionCollections = new Set(catalog.collections.filter((collection) => collection.packCategory === "expedition").map((collection) => collection.id));
if (!Array.isArray(destination.logbookCards) || destination.logbookCards.some((cardId) => {
const card = catalog.cards.find((item) => item.id === cardId);
return !card || !expeditionCollections.has(card.collectionId) || !isExpeditionCard(catalog, cardId);
})) fail(destination, "logbookCards must list rare or better cards of an expedition collection.");
if (!Array.isArray(destination.conditions) || !destination.conditions.length) fail(destination, "needs at least one condition.");
for (const condition of destination.conditions) {
if (condition?.type === "tag") {
if (!tagIds.has(condition.tag)) fail(destination, `unknown condition tag ${condition.tag}.`);
if (matchingCards(catalog, { tags: [condition.tag] }).length < MIN_MATCHING_CARDS) fail(destination, `condition ${condition.tag} matches fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
} else if (condition?.type === "collection") {
if (!collectionIds.has(condition.collectionId)) fail(destination, `unknown condition collection ${condition.collectionId}.`);
if (matchingCards(catalog, { collectionId: condition.collectionId }).length < MIN_MATCHING_CARDS) fail(destination, `condition ${condition.collectionId} matches fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
} else {
fail(destination, "condition type must be tag or collection.");
}
}
if (!Array.isArray(destination.dangers) || !destination.dangers.length) fail(destination, "needs at least one danger.");
const dangerIds = new Set();
for (const danger of destination.dangers) {
if (!ID_PATTERN.test(danger?.id ?? "") || dangerIds.has(danger.id)) fail(destination, "every danger needs a unique lowercase id.");
dangerIds.add(danger.id);
if (typeof danger.label !== "string" || !danger.label || danger.label.length > 40) fail(destination, `danger ${danger.id} label must contain 1 to 40 characters.`);
if (!STAT_IDS.includes(danger.stat)) fail(destination, `danger ${danger.id} needs a known stat.`);
if (!Array.isArray(danger.unlessTags) || !danger.unlessTags.length || danger.unlessTags.some((tag) => !tagIds.has(tag))) fail(destination, `danger ${danger.id} needs known counter tags.`);
if (matchingCards(catalog, { tags: danger.unlessTags }).length < MIN_MATCHING_CARDS) fail(destination, `danger ${danger.id} can be countered by fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
}
}
if (!destinations.some((destination) => !destination.hidden)) throw new TypeError("Expedition destinations need at least one visible destination.");
// Une carte de destination débloque une destination qui existe.
for (const card of catalog.cards.filter((item) => item.kind === "destination")) {
if (!ids.has(card.destinationId)) throw new TypeError(`Destination card ${card.id} names unknown destination ${card.destinationId}.`);
}
return destinations;
}
export function loadExpeditionDestinations(path, catalog) {
return validateExpeditionDestinations(JSON.parse(readFileSync(path, "utf8")), catalog);
}