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

@@ -55,6 +55,16 @@ export function getZooSkillLevel(zoo) {
return b ? b.conveyorLevel : 1;
}
/**
* @param {Record<string, number>} out
* @param {Record<string, number>} neighborWeights
* @param {string[]} colorNames
* @returns {void}
*/
function addNeighborWeights(out, neighborWeights, colorNames) {
for (const c of colorNames) out[c] = (out[c] ?? 0) + (neighborWeights[c] ?? 0);
}
/**
* Neighbor color weights (sum of animalWeights of zoos within maxDistance on the map).
* @param {import("./types.js").GameState} state
@@ -73,10 +83,7 @@ export function getNeighborColorWeights(state, zooId) {
const dx = (z.x - self.x) / 100;
const dy = (z.y - self.y) / 100;
const dist = Math.sqrt(dx * dx + dy * dy) * 100;
if (dist <= maxD) {
const w = z.animalWeights ?? {};
for (const c of colorNames) out[c] = (out[c] ?? 0) + (w[c] ?? 0);
}
if (dist <= maxD) addNeighborWeights(out, z.animalWeights ?? {}, colorNames);
}
}
return out;
@@ -150,27 +157,13 @@ export function ensureBotState(zoo, isPlayer) {
}
/**
* @param {import("./types.js").GameState} state
* @param {import("./types.js").WorldZooEntry} zoo
* @param {{ b: import("./types.js").BotState, rng: () => number, params: { spendThreshold: number, upgradeChance: number } }} opts
* @param {import("./types.js").BotState} b
* @param {string} choice
* @param {{ plotCost: number, skillCost: number, truckCost: number }} costs
* @returns {boolean}
*/
function botDecideUpgrade(state, zoo, opts) {
const { b, rng, params } = opts;
const { spendThreshold, upgradeChance } = params;
const { plotMax, skillMax, truckMax } = getUpgradeMaxLevels();
const plotCost = getPlotUpgradeCost(b.plotLevel);
const skillCost = getSchoolUpgradeCost(b.conveyorLevel);
const truckCost = getTruckUpgradeCost(b.truckLevel);
const canUpgradePlot = b.plotLevel < plotMax && b.coins >= plotCost * spendThreshold;
const canUpgradeSkill = b.conveyorLevel < skillMax && b.coins >= skillCost * spendThreshold;
const canUpgradeTruck = b.truckLevel < truckMax && b.coins >= truckCost * spendThreshold;
const upgradeChoices = [];
if (canUpgradePlot) upgradeChoices.push("plot");
if (canUpgradeSkill) upgradeChoices.push("skill");
if (canUpgradeTruck) upgradeChoices.push("truck");
if (upgradeChoices.length === 0 || rng() >= upgradeChance) return false;
const choice = upgradeChoices[Math.floor(rng() * upgradeChoices.length)];
function applyBotUpgradeChoice(b, choice, costs) {
const { plotCost, skillCost, truckCost } = costs;
if (choice === "plot" && b.coins >= plotCost) {
b.coins -= plotCost;
b.plotLevel += 1;
@@ -189,6 +182,28 @@ function botDecideUpgrade(state, zoo, opts) {
return false;
}
/**
* @param {import("./types.js").GameState} state
* @param {import("./types.js").WorldZooEntry} zoo
* @param {{ b: import("./types.js").BotState, rng: () => number, params: { spendThreshold: number, upgradeChance: number } }} opts
* @returns {boolean}
*/
function botDecideUpgrade(state, zoo, opts) {
const { b, rng, params } = opts;
const { spendThreshold, upgradeChance } = params;
const { plotMax, skillMax, truckMax } = getUpgradeMaxLevels();
const plotCost = getPlotUpgradeCost(b.plotLevel);
const skillCost = getSchoolUpgradeCost(b.conveyorLevel);
const truckCost = getTruckUpgradeCost(b.truckLevel);
const upgradeChoices = [];
if (b.plotLevel < plotMax && b.coins >= plotCost * spendThreshold) upgradeChoices.push("plot");
if (b.conveyorLevel < skillMax && b.coins >= skillCost * spendThreshold) upgradeChoices.push("skill");
if (b.truckLevel < truckMax && b.coins >= truckCost * spendThreshold) upgradeChoices.push("truck");
if (upgradeChoices.length === 0 || rng() >= upgradeChance) return false;
const choice = upgradeChoices[Math.floor(rng() * upgradeChoices.length)];
return applyBotUpgradeChoice(b, choice, { plotCost, skillCost, truckCost });
}
/**
* @param {import("./types.js").WorldZooEntry} zoo
* @param {() => number} rng
@@ -288,6 +303,40 @@ export function tickBotZoos(state, nowUnix, dt) {
const PLAYER_AUTO_MIN_INTERVAL = 10;
const PLAYER_AUTO_MAX_INTERVAL = 28;
/** @param {string[]} choices
* @param {import("./types.js").GameState} state
* @param {{ level: number, maxLevel: number, costFn: (n: number) => number, key: string, st: number }} opts
* @returns {void}
*/
function maybePushUpgradeChoice(choices, state, opts) {
const { level, maxLevel, costFn, key, st } = opts;
if (level < maxLevel && state.coins >= costFn(level) * st) choices.push(key);
}
/** @param {import("./types.js").GameState} state
* @param {{ spendThreshold: number }} params
* @returns {string[]}
*/
function getPlayerUpgradeChoices(state, params) {
const { plotMax, skillMax, truckMax } = getUpgradeMaxLevels();
const st = params.spendThreshold;
const choices = [];
maybePushUpgradeChoice(choices, state, { level: state.plotLevel ?? 1, maxLevel: plotMax, costFn: getPlotUpgradeCost, key: "plot", st });
maybePushUpgradeChoice(choices, state, { level: state.conveyorLevel ?? 1, maxLevel: skillMax, costFn: getConveyorUpgradeCost, key: "skill", st });
maybePushUpgradeChoice(choices, state, { level: state.truckLevel ?? 1, maxLevel: truckMax, costFn: getTruckUpgradeCost, key: "truck", st });
return choices;
}
/** @param {import("./types.js").GameState} state
* @param {string} choice
* @returns {void}
*/
function applyPlayerUpgradeChoice(state, choice) {
if (choice === "plot") tryUpgradePlot(state);
else if (choice === "skill") tryUpgrade(state);
else if (choice === "truck") tryUpgradeTruck(state);
}
/**
* Apply one upgrade (plot, skill, truck) for player auto mode.
* @param {import("./types.js").GameState} state
@@ -296,24 +345,10 @@ const PLAYER_AUTO_MAX_INTERVAL = 28;
* @returns {void}
*/
function playerAutoDoOneUpgrade(state, params, rng) {
const { spendThreshold, upgradeChance } = params;
const { plotMax, skillMax, truckMax } = getUpgradeMaxLevels();
const plotCost = getPlotUpgradeCost(state.plotLevel ?? 1);
const skillCost = getConveyorUpgradeCost(state.conveyorLevel ?? 1);
const truckCost = getTruckUpgradeCost(state.truckLevel ?? 1);
const canPlot = (state.plotLevel ?? 1) < plotMax && state.coins >= plotCost * spendThreshold;
const canSkill = (state.conveyorLevel ?? 1) < skillMax && state.coins >= skillCost * spendThreshold;
const canTruck = (state.truckLevel ?? 1) < truckMax && state.coins >= truckCost * spendThreshold;
const choices = [];
if (canPlot) choices.push("plot");
if (canSkill) choices.push("skill");
if (canTruck) choices.push("truck");
if (choices.length === 0) return;
if (rng() >= upgradeChance) return;
const choices = getPlayerUpgradeChoices(state, params);
if (choices.length === 0 || rng() >= params.upgradeChance) return;
const choice = choices[Math.floor(rng() * choices.length)];
if (choice === "plot") tryUpgradePlot(state);
else if (choice === "skill") tryUpgrade(state);
else if (choice === "truck") tryUpgradeTruck(state);
applyPlayerUpgradeChoice(state, choice);
}
/**