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

@@ -54,14 +54,19 @@ function buildDefaultCells() {
return buildDefaultRow1Cells();
}
function getDefaultStats() {
return { eggsPlaced: 0, animalsSold: 0, conveyorUpgrades: 0, plotUpgrades: 0, truckUpgrades: 0, coinsEarned: 0 };
}
function buildStatePayload(width, height, worldZoos, cells) {
const grid = { width, height, cells };
return {
version: GameConfig.StateVersion,
coins: 200,
conveyorLevel: 1,
plotLevel: 1,
truckLevel: 1,
grid: { width, height, cells },
grid,
pendingEggTokens: [],
nextTokenId: 1,
conveyorOffers: [],
@@ -73,15 +78,14 @@ function buildStatePayload(width, height, worldZoos, cells) {
laboratoryOffer: null,
prestigeLevel: 0,
timeOfDay: 6,
gameDayTotal: 0,
lastSeason: "spring",
weather: "sun",
lastWeatherChangeAt: 0,
quests: [],
lastQuestDay: "",
stats: { eggsPlaced: 0, animalsSold: 0, conveyorUpgrades: 0, plotUpgrades: 0, truckUpgrades: 0, coinsEarned: 0 },
mapZoom: 1,
mapPanX: 0,
mapPanY: 0,
worldMapLevel: 1,
stats: getDefaultStats(),
mapZoom: 1, mapPanX: 0, mapPanY: 0, worldMapLevel: 1,
autoMode: false,
autoModeProfile: "balanced",
researchPoints: 0,
@@ -145,16 +149,22 @@ function applyLoadStateWorldZoos(data) {
data.worldZoos = [...GameConfig.WorldMap.Zoos];
}
if (data.worldZoos !== null && data.worldZoos !== undefined && Array.isArray(data.worldZoos)) {
const keys = getColorNames();
data.worldZoos = data.worldZoos.map((z, _i) => ({
...z,
animalWeights: z.animalWeights && keys.some((k) => k in (z.animalWeights ?? {}))
? z.animalWeights
: normalizeZooWeights(z.animalWeights),
}));
data.worldZoos.forEach((zoo) => ensureBotState(zoo, zoo.id === "player"));
applyWorldZoosWeightsAndBots(data);
}
if (data.worldZoos === null || data.worldZoos === undefined) data.worldZoos = [{ id: "player", name: "Mon zoo", x: 25, y: 50, animalWeights: defaultAnimalWeights() }];
if (data.worldZoos === null || data.worldZoos === undefined) {
data.worldZoos = [{ id: "player", name: "Mon zoo", x: 25, y: 50, animalWeights: defaultAnimalWeights() }];
}
}
function applyWorldZoosWeightsAndBots(data) {
const keys = getColorNames();
data.worldZoos = data.worldZoos.map((z) => ({
...z,
animalWeights: z.animalWeights && keys.some((k) => k in (z.animalWeights ?? {}))
? z.animalWeights
: normalizeZooWeights(z.animalWeights),
}));
data.worldZoos.forEach((zoo) => ensureBotState(zoo, zoo.id === "player"));
}
/** Set data[key] to defaultVal when data[key] is null or undefined. defaultVal may be a function (called for value). */
@@ -170,6 +180,8 @@ const LOAD_STATE_SCALAR_DEFAULTS = [
["nextTokenId", 1],
["prestigeLevel", 0],
["timeOfDay", 6],
["gameDayTotal", 0],
["lastSeason", "spring"],
["weather", "sun"],
["lastWeatherChangeAt", 0],
["quests", []],
@@ -211,15 +223,24 @@ function applyLoadStateLegacyCells(data) {
if (c12 && (c12.kind === "plotUpgrade" || c12.kind === "worldMapUpgrade")) delete data.grid.cells["1_2"];
}
function normalizeOneAnimalCell(cell, now) {
if (cell.kind !== "animal") return;
if (cell.id && !LootTables.Animals[cell.id]) cell.id = "c0_r0";
if (cell.lastVisitedAt === null || cell.lastVisitedAt === undefined) cell.lastVisitedAt = now;
if (cell.lastFedAt === null || cell.lastFedAt === undefined) cell.lastFedAt = cell.placedAt ?? now;
}
function normalizeOneEggCell(cell) {
if (cell.kind === "egg" && cell.eggType && !LootTables.EggTypes[cell.eggType]) cell.eggType = "Color_1";
}
function normalizeLoadedCells(cells) {
const now = Math.floor(Date.now() / 1000);
for (const key of Object.keys(cells)) {
const cell = cells[key];
if (cell) {
if (cell.kind === "animal" && cell.id && !LootTables.Animals[cell.id]) cell.id = "c0_r0";
if (cell.kind === "animal" && (cell.lastVisitedAt === null || cell.lastVisitedAt === undefined)) cell.lastVisitedAt = now;
if (cell.kind === "animal" && (cell.lastFedAt === null || cell.lastFedAt === undefined)) cell.lastFedAt = cell.placedAt ?? now;
if (cell.kind === "egg" && cell.eggType && !LootTables.EggTypes[cell.eggType]) cell.eggType = "Color_1";
if (cell.kind === "animal") normalizeOneAnimalCell(cell, now);
if (cell.kind === "egg") normalizeOneEggCell(cell);
}
}
}