sokko-g/services/cards/mirror-settings.js
Shinuwa ebb220d532
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 23m41s
Validate and deploy Sokko G / deploy (push) Successful in 16s
Add an Easy mirror before Normal and let every companion help
Easy is a square 4 x 4 picture drawn for each player, with green
outlines, where any two pieces swap; it is scored against the free
minimum and pays 5 plus 1 per move left. The three mirrors open one
after another (Easy, Normal, Hard) and the Guild quest is done with all
three. Migration 31 rebuilds mirror_games to accept the new mode. The
mirror page shows three illustrated cards, Easy painted with Codex.

Bravery now places a misplaced piece for free, since swapping anywhere
means nothing in Easy. Each of the five companions can help once per
game instead of two in all. Mirror styles now win over the global
button hover, so placed pieces keep their green outline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 18:27:02 +01:00

48 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rôle : réglages du Miroir brisé (ouverture, gains, marges d'échanges) : valeurs par défaut, validation et lecture tolérante.
import { MIRROR_MODE_IDS } from "./mirror-rules.js";
const MAX_REWARD = 100_000;
const MAX_MARGIN = 30;
// Gains : base d'une image reconstituée et part par échange restant. Repères : la Carte du jour rapporte 20 en production et la
// Course 20 / 15 / 10 / 5 ; le Facile rapporte la moitié du Normal. Marges : échanges permis au-delà de la référence (le minimum
// d'échanges libres en Facile, le meilleur résultat de l'ordinateur sinon) ; en Normal, un joueur attentif réussit environ 9 fois
// sur 10 avec 3 (simulation, docs/miroir-brise.md).
export const DEFAULT_MIRROR_SETTINGS = Object.freeze({
enabled: false,
rewards: Object.freeze({ easy: Object.freeze({ base: 5, perSwap: 1 }), normal: Object.freeze({ base: 10, perSwap: 1 }), hard: Object.freeze({ base: 20, perSwap: 2 }) }),
margins: Object.freeze({ easy: 4, normal: 3, hard: 6 })
});
export function mirrorSettingsError(settings) {
const integer = (value, max) => Number.isInteger(value) && value >= 0 && value <= max;
if (!settings || typeof settings !== "object" || Array.isArray(settings)) return "Réglages du Miroir brisé invalides.";
if (typeof settings.enabled !== "boolean") return "L’ouverture du Miroir brisé doit être vraie ou fausse.";
for (const mode of MIRROR_MODE_IDS) {
const reward = settings.rewards?.[mode];
if (!reward || !integer(reward.base, MAX_REWARD) || !integer(reward.perSwap, MAX_REWARD)) return `Gains du Miroir brisé : des entiers entre 0 et ${MAX_REWARD.toLocaleString("fr-FR")}.`;
if (!integer(settings.margins?.[mode], MAX_MARGIN)) return `Marges d’échanges : des entiers entre 0 et ${MAX_MARGIN}.`;
}
return null;
}
// Garde seulement les champs connus.
export const normalizeMirrorSettings = ({ enabled, rewards, margins }) => ({
enabled,
rewards: Object.fromEntries(MIRROR_MODE_IDS.map((mode) => [mode, { base: rewards[mode].base, perSwap: rewards[mode].perSwap }])),
margins: Object.fromEntries(MIRROR_MODE_IDS.map((mode) => [mode, margins[mode]]))
});
// Réglages enregistrés : des valeurs invalides laissent la place aux valeurs par défaut, pour que le jeu reste jouable.
export function readMirrorSettings(stored, onInvalid = () => {}) {
const defaults = DEFAULT_MIRROR_SETTINGS;
const merged = {
...defaults, ...stored,
rewards: Object.fromEntries(MIRROR_MODE_IDS.map((mode) => [mode, { ...defaults.rewards[mode], ...stored?.rewards?.[mode] }])),
margins: { ...defaults.margins, ...stored?.margins }
};
const error = mirrorSettingsError(merged);
if (!error) return normalizeMirrorSettings(merged);
onInvalid(error);
return normalizeMirrorSettings({ ...defaults, enabled: stored?.enabled === true });
}