**Motivations:** - Ensure lint config is not degraded and fix all lint errors for pousse workflow. **Root causes:** - Unused variables kept with _ prefix instead of removed (_row, _questReward, _i). - getAnimalBlockOrigin had 5 parameters (max 4). - use of continue statement (no-continue rule). **Correctifs:** - ESLint config verified; no eslint-disable in codebase. - Removed unused variable _row (biome-rules); removed dead function _questReward (quests); removed unused map param _i (state.js). - getAnimalBlockOrigin refactored to 4 params (pos object instead of x, y). - Replaced continue with if (cell) block in normalizeLoadedCells (state.js). - JSDoc param names aligned with _height, _y (biome-rules). **Evolutions:** - (none) **Pages affectées:** - web/js/biome-rules.js - web/js/quests.js - web/js/state.js - web/js/placement.js
62 lines
2.5 KiB
JavaScript
62 lines
2.5 KiB
JavaScript
import { getTimePhase } from "./time-weather.js";
|
|
import { buildUIDOM } from "./ui-render-dom.js";
|
|
|
|
const EMOJI_BY_COLOR = ["🐰", "🦌", "🐸", "🦎", "🐢", "🐬", "🦭", "🐟", "🦈", "🐳", "🦅", "🐺", "🐻", "🦊", "🐗"];
|
|
const animalEmoji = {};
|
|
for (let c = 0; c < 15; c++) {
|
|
for (let r = 0; r < 5; r++) {
|
|
animalEmoji[`c${c}_r${r}`] = EMOJI_BY_COLOR[c] ?? "🐾";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {{ state: import("./types.js").GameState, setState: () => void, getLastHatched: () => Array<{ x: number, y: number }>, onRestart?: () => void, updateState?: (partial: Partial<import("./types.js").GameState>) => void }} opts
|
|
* @returns {object}
|
|
*/
|
|
function buildRenderSetup(opts) {
|
|
const { state, setState, getLastHatched, onRestart, updateState } = opts;
|
|
const getHatched = getLastHatched ?? (() => []);
|
|
const selected = { x: 1, y: 1 };
|
|
const pendingTokenByEggType = {};
|
|
const selectedTokenIdRef = { current: null };
|
|
const emptyCellChoiceRef = { current: null };
|
|
const errorMsg = { current: "" };
|
|
const lastActionWasDropRef = { current: false };
|
|
const sellZoneJustDroppedRef = { current: false };
|
|
const clampSelection = () => {
|
|
selected.x = Math.max(1, Math.min(state.grid.width, selected.x));
|
|
selected.y = Math.max(1, Math.min(state.grid.height, selected.y));
|
|
};
|
|
const errEl = document.createElement("div");
|
|
errEl.className = "error-msg";
|
|
errEl.hidden = true;
|
|
const setError = (msg) => {
|
|
errorMsg.current = msg;
|
|
if (errEl) {
|
|
errEl.textContent = msg;
|
|
errEl.hidden = !msg;
|
|
}
|
|
};
|
|
return {
|
|
state, setState, getHatched, updateState, onRestart,
|
|
selected, pendingTokenByEggType, selectedTokenIdRef, emptyCellChoiceRef,
|
|
errorMsg, lastActionWasDropRef, sellZoneJustDroppedRef,
|
|
clampSelection, setError, errEl, animalEmoji,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @param {HTMLElement} root
|
|
* @param {{ state: import("./types.js").GameState, setState: () => void, getLastHatched: () => Array<{ x: number, y: number }>, onRestart?: () => void, updateState?: (partial: Partial<import("./types.js").GameState>) => void }} opts
|
|
* @returns {() => void}
|
|
*/
|
|
export function render(root, opts) {
|
|
const phase = getTimePhase(opts.state.timeOfDay ?? 6);
|
|
const weather = opts.state.weather || "sun";
|
|
document.body.classList.remove("bg-phase-dawn", "bg-phase-day", "bg-phase-dusk", "bg-phase-night", "bg-weather-sun", "bg-weather-cloudy", "bg-weather-rain");
|
|
document.body.classList.add(`bg-phase-${phase.phase}`, `bg-weather-${weather}`);
|
|
root.innerHTML = "";
|
|
const setup = buildRenderSetup(opts);
|
|
return buildUIDOM(root, setup);
|
|
}
|