Lint: fix errors and remove unused variables

**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
This commit is contained in:
ncantu
2026-03-04 15:32:27 +01:00
parent d8a55daf3f
commit c7d389ecbb
57 changed files with 4664 additions and 3049 deletions

View File

@@ -12,18 +12,17 @@ import {
import { GameConfig } from "./config.js";
/**
* All keys that belong to the same animal block as the cell at (x, y). If not an animal or single-cell, returns [cellKey(x,y)].
* Origin and dimensions for an animal cell (possibly from originKey). Returns null if not animal.
* @param {import("./types.js").GameState} state
* @param {number} x
* @param {number} y
* @returns {string[]}
* @param {import("./types.js").Cell} cell
* @param {string} key
* @param {{ x: number, y: number }} pos
* @returns {{ ox: number, oy: number, w: number, h: number } | null}
*/
export function getBlockKeysFromCell(state, x, y) {
const key = cellKey(x, y);
const cell = state.grid.cells[key];
if (cell === null || cell === undefined || cell.kind !== "animal") return [key];
let ox = x;
let oy = y;
function getAnimalBlockOrigin(state, cell, key, pos) {
if (cell === null || cell === undefined || cell.kind !== "animal") return null;
let ox = pos.x;
let oy = pos.y;
let w = cell.cellsWide ?? 1;
let h = cell.cellsHigh ?? 1;
if (cell.originKey !== null && cell.originKey !== undefined) {
@@ -38,7 +37,41 @@ export function getBlockKeysFromCell(state, x, y) {
}
}
}
return getBlockKeys(ox, oy, w, h);
return { ox, oy, w, h };
}
/**
* All keys that belong to the same animal block as the cell at (x, y). If not an animal or single-cell, returns [cellKey(x,y)].
* @param {import("./types.js").GameState} state
* @param {number} x
* @param {number} y
* @returns {string[]}
*/
export function getBlockKeysFromCell(state, x, y) {
const key = cellKey(x, y);
const cell = state.grid.cells[key];
const origin = getAnimalBlockOrigin(state, cell, key, { x, y });
if (origin === null) return [key];
return getBlockKeys(origin.ox, origin.oy, origin.w, origin.h);
}
/**
* Build set of cell keys to exclude when placing (block at excludeOriginKey).
* @param {import("./types.js").GameState} state
* @param {string} [excludeOriginKey]
* @returns {Set<string>}
*/
function buildExcludeSet(state, excludeOriginKey) {
const excludeSet = new Set();
if (excludeOriginKey === null || excludeOriginKey === undefined) return excludeSet;
const orig = state.grid.cells[excludeOriginKey];
if (orig && orig.kind === "animal") {
const [ox, oy] = excludeOriginKey.split("_").map(Number);
const ow = orig.cellsWide ?? 1;
const oh = orig.cellsHigh ?? 1;
getBlockKeys(ox, oy, ow, oh).forEach((k) => excludeSet.add(k));
}
return excludeSet;
}
/**
@@ -49,16 +82,7 @@ export function getBlockKeysFromCell(state, x, y) {
*/
export function canPlaceMultiCell(state, opts) {
const { originX, originY, w, h, excludeOriginKey } = opts;
const excludeSet = new Set();
if (excludeOriginKey !== null && excludeOriginKey !== undefined) {
const orig = state.grid.cells[excludeOriginKey];
if (orig && orig.kind === "animal") {
const [ox, oy] = excludeOriginKey.split("_").map(Number);
const ow = orig.cellsWide ?? 1;
const oh = orig.cellsHigh ?? 1;
getBlockKeys(ox, oy, ow, oh).forEach((k) => excludeSet.add(k));
}
}
const excludeSet = buildExcludeSet(state, excludeOriginKey);
for (let dy = 0; dy < h; dy++) {
for (let dx = 0; dx < w; dx++) {
const nx = originX + dx;
@@ -124,6 +148,25 @@ export function placeEgg(state, opts) {
return [true, undefined];
}
/**
* Move an animal block from (ox,oy) to (toX, toY). Caller ensures source is animal and keys differ.
* @param {import("./types.js").GameState} state
* @param {{ blockKeys: string[], ox: number, oy: number, toX: number, toY: number, source: import("./types.js").AnimalCell }} opts
* @returns {[boolean, string?]}
*/
function moveAnimalBlock(state, opts) {
const { blockKeys, ox, oy, toX, toY, source } = opts;
const w = source.cellsWide ?? 1;
const h = source.cellsHigh ?? 1;
const originKey = cellKey(ox, oy);
const [ok, reason] = canPlaceMultiCell(state, { originX: toX, originY: toY, w, h, excludeOriginKey: originKey });
if (!ok) return [false, reason];
const animalData = { ...source, originKey: cellKey(toX, toY), cellsWide: w, cellsHigh: h };
for (const k of blockKeys) delete state.grid.cells[k];
fillAnimalBlock(state, toX, toY, animalData);
return [true, undefined];
}
/**
* Déplace le contenu d'une case vers une case vide (œuf ou animal). For multi-cell animals, moves the whole block.
* @param {import("./types.js").GameState} state
@@ -139,29 +182,9 @@ export function moveCell(state, opts) {
if (source === null || source === undefined) return [false, "NoSource"];
if (source.kind === "animal") {
const blockKeys = getBlockKeysFromCell(state, fromX, fromY);
let ox = fromX;
let oy = fromY;
let w = source.cellsWide ?? 1;
let h = source.cellsHigh ?? 1;
if (source.originKey !== null && source.originKey !== undefined) {
const m = source.originKey.match(/^(\d+)_(\d+)$/);
if (m) {
ox = Number(m[1]);
oy = Number(m[2]);
const origin = state.grid.cells[source.originKey];
if (origin && origin.kind === "animal") {
w = origin.cellsWide ?? 1;
h = origin.cellsHigh ?? 1;
}
}
}
const originKey = cellKey(ox, oy);
const [ok, reason] = canPlaceMultiCell(state, { originX: toX, originY: toY, w, h, excludeOriginKey: originKey });
if (!ok) return [false, reason];
const animalData = { ...source, originKey: toKey, cellsWide: w, cellsHigh: h };
for (const k of blockKeys) delete state.grid.cells[k];
fillAnimalBlock(state, toX, toY, animalData);
return [true, undefined];
const origin = getAnimalBlockOrigin(state, source, fromKey, { x: fromX, y: fromY });
if (origin === null) return [false, "NoSource"];
return moveAnimalBlock(state, { blockKeys, ox: origin.ox, oy: origin.oy, toX, toY, source });
}
const [ok, reason] = canPlace(state, toX, toY);
if (!ok) return [false, reason];