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:
@@ -91,7 +91,7 @@ export function addReceptionAnimalToSale(state, receptionCellKey) {
|
||||
|
||||
/**
|
||||
* Remove expired sale listings. If listing was a baby (isBaby), increment deathCountRecent (bébé invendu meurt).
|
||||
* Call from game loop each tick.
|
||||
* If listing was an adult (isBaby false), also increment deathCountRecent (vente échouée = mort adulte).
|
||||
* @param {import("./types.js").GameState} state
|
||||
* @param {number} nowUnix
|
||||
*/
|
||||
@@ -99,24 +99,29 @@ export function tickSaleListings(state, nowUnix) {
|
||||
const listings = state.saleListings ?? [];
|
||||
const kept = [];
|
||||
let babyDeaths = 0;
|
||||
let adultDeaths = 0;
|
||||
for (const listing of listings) {
|
||||
if (nowUnix < listing.endAt) {
|
||||
kept.push(listing);
|
||||
} else if (listing.isBaby) {
|
||||
babyDeaths += 1;
|
||||
} else {
|
||||
adultDeaths += 1;
|
||||
}
|
||||
}
|
||||
state.saleListings = kept;
|
||||
if (babyDeaths > 0) state.deathCountRecent = (state.deathCountRecent ?? 0) + babyDeaths;
|
||||
const totalDeaths = babyDeaths + adultDeaths;
|
||||
if (totalDeaths > 0) state.deathCountRecent = (state.deathCountRecent ?? 0) + totalDeaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute sell result for animal at (x,y). Returns [false, reason] or [true, { blockKeys, sellValue }].
|
||||
* @param {import("./types.js").GameState} state
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @returns {[boolean, number | string]}
|
||||
* @returns {[false, string] | [true, { blockKeys: string[], sellValue: number }]}
|
||||
*/
|
||||
export function sellAnimalToNpc(state, x, y) {
|
||||
function getSellAnimalResult(state, x, y) {
|
||||
const key = cellKey(x, y);
|
||||
const cell = state.grid.cells[key];
|
||||
if (cell === null || cell === undefined || cell.kind !== "animal") return [false, "NoAnimal"];
|
||||
@@ -133,6 +138,19 @@ export function sellAnimalToNpc(state, x, y) {
|
||||
mutationMultiplier,
|
||||
animalDef.sellFactor
|
||||
);
|
||||
return [true, { blockKeys, sellValue }];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./types.js").GameState} state
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @returns {[boolean, number | string]}
|
||||
*/
|
||||
export function sellAnimalToNpc(state, x, y) {
|
||||
const result = getSellAnimalResult(state, x, y);
|
||||
if (result[0] === false) return [false, result[1]];
|
||||
const { blockKeys, sellValue } = result[1];
|
||||
for (const k of blockKeys) delete state.grid.cells[k];
|
||||
state.coins += sellValue;
|
||||
state.lastEvolutionAt = Math.floor(Date.now() / 1000);
|
||||
|
||||
Reference in New Issue
Block a user