Files
builazoo/web/js/zoo-placement.js
ncantu c7d389ecbb 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
2026-03-04 15:32:27 +01:00

91 lines
3.3 KiB
JavaScript

import { LootTables } from "./loot-tables.js";
import { canPlaceMultiCell } from "./placement.js";
/**
* @param {import("./types.js").GameState} state
* @param {string} nurseryCellKey
* @param {number} nowUnix
* @returns {[false, string] | [true, import("./types.js").PendingBaby]}
*/
function getMatureBabyReady(state, nurseryCellKey, nowUnix) {
const baby = (state.pendingBabies ?? []).find((p) => p.nurseryCellKey === nurseryCellKey);
if (baby === null || baby === undefined) return [false, "NoBaby"];
if (nowUnix < baby.readyAt) return [false, "BabyNotReady"];
return [true, baby];
}
/**
* @param {import("./types.js").GameState} state
* @param {{ nurseryCellKey: string, toX: number, toY: number, nowUnix: number }} opts
* @returns {[false, string] | [true, import("./types.js").AnimalCell]}
*/
export function getMatureBabyPlacementData(state, opts) {
const { nurseryCellKey, toX, toY, nowUnix } = opts;
const babyResult = getMatureBabyReady(state, nurseryCellKey, nowUnix);
if (babyResult[0] === false) return [false, babyResult[1]];
const baby = babyResult[1];
const def = LootTables.Animals[baby.animalId];
if (def === null || def === undefined) return [false, "UnknownAnimal"];
const w = def.cellsWide ?? 1;
const h = def.cellsHigh ?? 1;
const [ok, reason] = canPlaceMultiCell(state, { originX: toX, originY: toY, w, h });
if (!ok) return [false, reason ?? "NoPlace"];
const animalData = {
kind: "animal",
id: baby.animalId,
mutation: "none",
level: 1,
placedAt: nowUnix,
lastVisitedAt: nowUnix,
lastFedAt: nowUnix,
cellsWide: w,
cellsHigh: h,
fromOtherZoo: baby.fromOtherZoo === true,
};
return [true, animalData];
}
/**
* @param {import("./types.js").GameState} state
* @param {string} receptionCellKey
* @param {number} nowUnix
* @returns {[false, string] | [true, import("./types.js").ReceptionAnimal]}
*/
function getReceptionAnimalReady(state, receptionCellKey, nowUnix) {
const rec = (state.receptionAnimals ?? []).find((r) => r.receptionCellKey === receptionCellKey);
if (rec === null || rec === undefined) return [false, "NoReceptionAnimal"];
if (nowUnix < rec.readyAt) return [false, "AnimalNotReady"];
return [true, rec];
}
/**
* @param {import("./types.js").GameState} state
* @param {{ receptionCellKey: string, toX: number, toY: number, nowUnix: number }} opts
* @returns {[false, string] | [true, import("./types.js").AnimalCell]}
*/
export function getReceptionAnimalPlacementData(state, opts) {
const { receptionCellKey, toX, toY, nowUnix } = opts;
const recResult = getReceptionAnimalReady(state, receptionCellKey, nowUnix);
if (recResult[0] === false) return [false, recResult[1]];
const rec = recResult[1];
const def = LootTables.Animals[rec.animalId];
if (def === null || def === undefined) return [false, "UnknownAnimal"];
const w = def.cellsWide ?? 1;
const h = def.cellsHigh ?? 1;
const [ok, reason] = canPlaceMultiCell(state, { originX: toX, originY: toY, w, h });
if (!ok) return [false, reason ?? "NoPlace"];
const animalData = {
kind: "animal",
id: rec.animalId,
mutation: "none",
level: 1,
placedAt: nowUnix,
lastVisitedAt: nowUnix,
lastFedAt: nowUnix,
cellsWide: w,
cellsHigh: h,
fromOtherZoo: true,
};
return [true, animalData];
}