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

@@ -9,6 +9,19 @@ import { cellKey, isOriginCell } from "./grid-utils.js";
import { getBlockKeysFromCell } from "./placement.js";
import { getDisplayBiome, getDisplayTemperature } from "./biome-rules.js";
import { addPendingBaby } from "./zoo.js";
import { getCurrentSeason, getSeasonReproductionBonus, getSeasonTemperatureModifier } from "./seasons.js";
/**
* Reproduction season bonus. In winter, cold-adapted biomes (Mountain) are exempt from the -50% malus (spec: sauf espèces adaptées).
* @param {string} season
* @param {import("./loot-tables.js").LootTables["Animals"][string]} def
* @returns {number}
*/
function getEffectiveReproductionSeasonBonus(season, def) {
const base = getSeasonReproductionBonus(season);
if (season === "winter" && base < 0 && def?.biome === "Mountain") return 0;
return base;
}
/**
* Zoo reproduction score (stub for phase 7). Higher = shorter delay until baby.
@@ -81,16 +94,17 @@ function blocksAreAdjacent(state, keyA, keyB) {
}
/**
* All eligible reproduction pairs: same animalId, at least one fromOtherZoo, adjacent.
* Returns unique pairs with keyA < keyB lexicographically.
* Collect origin animal entries (key, animalId, fromOtherZoo) from grid.
* @param {import("./types.js").GameState} state
* @returns {Array<{ keyA: string, keyB: string, animalId: string }>}
* @returns {Array<{ key: string, animalId: string, fromOtherZoo: boolean }>}
*/
export function findReproductionPairs(state) {
function collectOriginAnimals(state) {
const cells = state.grid.cells;
const origins = [];
for (const [key, cell] of Object.entries(cells)) {
if (cell !== null && cell !== undefined && cell.kind === "animal" && isOriginCell(key, cell)) {
if (cell === null || cell === undefined || cell.kind !== "animal" || !isOriginCell(key, cell)) {
// skip
} else {
const def = LootTables.Animals[cell.id];
if (def !== null && def !== undefined) {
origins.push({
@@ -101,6 +115,16 @@ export function findReproductionPairs(state) {
}
}
}
return origins;
}
/**
* Form unique pairs from origins (same animalId, at least one fromOtherZoo, adjacent).
* @param {import("./types.js").GameState} state
* @param {Array<{ key: string, animalId: string, fromOtherZoo: boolean }>} origins
* @returns {Array<{ keyA: string, keyB: string, animalId: string }>}
*/
function formReproductionPairs(state, origins) {
const pairs = [];
for (let i = 0; i < origins.length; i++) {
for (let j = i + 1; j < origins.length; j++) {
@@ -116,6 +140,17 @@ export function findReproductionPairs(state) {
return pairs;
}
/**
* All eligible reproduction pairs: same animalId, at least one fromOtherZoo, adjacent.
* Returns unique pairs with keyA < keyB lexicographically.
* @param {import("./types.js").GameState} state
* @returns {Array<{ keyA: string, keyB: string, animalId: string }>}
*/
export function findReproductionPairs(state) {
const origins = collectOriginAnimals(state);
return formReproductionPairs(state, origins);
}
/**
* Unique pair key for deduplication.
* @param {string} keyA
@@ -196,13 +231,16 @@ function addNewPairsToTimers(state, nowUnix, timers, existingSet) {
const m1 = keyA.match(/^(\d+)_(\d+)$/);
const m2 = keyB.match(/^(\d+)_(\d+)$/);
if (m1 && m2) {
const season = getCurrentSeason(state);
const seasonTempMod = getSeasonTemperatureModifier(season);
const biome1 = getDisplayBiome(Number(m1[1]), Number(m1[2]), grid);
const biome2 = getDisplayBiome(Number(m2[1]), Number(m2[2]), grid);
const temp1 = getDisplayTemperature(Number(m1[1]), Number(m1[2]), grid);
const temp2 = getDisplayTemperature(Number(m2[1]), Number(m2[2]), grid);
const temp1 = getDisplayTemperature(Number(m1[1]), Number(m1[2]), grid) + seasonTempMod;
const temp2 = getDisplayTemperature(Number(m2[1]), Number(m2[2]), grid) + seasonTempMod;
const biomeFactor = (getBiomeReproductionFactor(def, biome1) + getBiomeReproductionFactor(def, biome2)) / 2;
const tempFactor = (getTemperatureFactor(def, temp1) + getTemperatureFactor(def, temp2)) / 2;
const factor = Math.max(0.2, score * biomeFactor * tempFactor);
const seasonBonus = getEffectiveReproductionSeasonBonus(season, def);
const factor = Math.max(0.2, score * biomeFactor * tempFactor * (1 + seasonBonus));
const delay = Math.max(5, baseSeconds / factor);
timers.push({ keyA, keyB, animalId, dueAt: nowUnix + Math.floor(delay) });
existingSet.add(pk);