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:
@@ -46,6 +46,44 @@ function buildAnimalCell(animalId, mutationId, nowUnix, dimensions = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./types.js").GameState} state
|
||||
* @param {string} key
|
||||
* @param {number} nowUnix
|
||||
* @returns {import("./types.js").EggCell | null}
|
||||
*/
|
||||
function getEggCellIfReady(state, key, nowUnix) {
|
||||
const cell = state.grid.cells[key];
|
||||
if (cell === null || cell === undefined || cell.kind !== "egg") return null;
|
||||
if (nowUnix < cell.hatchAt) return null;
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ state: import("./types.js").GameState, cell: import("./types.js").EggCell, x: number, y: number, nowUnix: number, eventModifiers: { mutationBonus: number } }} opts
|
||||
* @returns {{ animalData: import("./types.js").AnimalCell, w: number, h: number } | null}
|
||||
*/
|
||||
function getHatchAnimalData(opts) {
|
||||
const { state, cell, x, y, nowUnix, eventModifiers } = opts;
|
||||
const eggDef = LootTables.EggTypes[cell.eggType];
|
||||
if (eggDef === null || eggDef === undefined) return null;
|
||||
const cellBiome = getCellBiome(state.grid.width, state.grid.height, x, y);
|
||||
const loot = lootForBiome(cellBiome, eggDef.loot);
|
||||
if (loot.length === 0) return null;
|
||||
const rng = createSeededRng(cell.seed);
|
||||
const pickedAnimalId = pickId(rng, loot);
|
||||
const animalDef = LootTables.Animals[pickedAnimalId];
|
||||
if (animalDef === null || animalDef === undefined) return null;
|
||||
const mutationChance = GameConfig.Mutation.BaseChance + eventModifiers.mutationBonus;
|
||||
let mutationId = "none";
|
||||
if (rng() < mutationChance) mutationId = pickId(rng, getMutationEntries());
|
||||
if (getIncomeMultiplier(mutationId) === undefined) mutationId = "none";
|
||||
const w = animalDef.cellsWide ?? 1;
|
||||
const h = animalDef.cellsHigh ?? 1;
|
||||
const animalData = buildAnimalCell(pickedAnimalId, mutationId, nowUnix, { cellsWide: w, cellsHigh: h });
|
||||
return { animalData, w, h };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./types.js").GameState} state
|
||||
* @param {{ x: number, y: number, nowUnix: number, eventModifiers: { incomeMultiplier: number, mutationBonus: number } }} opts
|
||||
@@ -54,35 +92,15 @@ function buildAnimalCell(animalId, mutationId, nowUnix, dimensions = {}) {
|
||||
export function tryHatchCell(state, opts) {
|
||||
const { x, y, nowUnix, eventModifiers } = opts;
|
||||
const key = cellKey(x, y);
|
||||
const cell = state.grid.cells[key];
|
||||
if (cell === null || cell === undefined || cell.kind !== "egg") return false;
|
||||
if (nowUnix < cell.hatchAt) return false;
|
||||
|
||||
const cell = getEggCellIfReady(state, key, nowUnix);
|
||||
if (cell === null) return false;
|
||||
const eggDef = LootTables.EggTypes[cell.eggType];
|
||||
if (eggDef === null || eggDef === undefined) throw new Error("HatchingService: unknown egg type");
|
||||
|
||||
const cellBiome = getCellBiome(state.grid.width, state.grid.height, x, y);
|
||||
const loot = lootForBiome(cellBiome, eggDef.loot);
|
||||
if (loot.length === 0) return false;
|
||||
|
||||
const rng = createSeededRng(cell.seed);
|
||||
const pickedAnimalId = pickId(rng, loot);
|
||||
const animalDef = LootTables.Animals[pickedAnimalId];
|
||||
if (animalDef === null || animalDef === undefined) return false;
|
||||
|
||||
const mutationChance = GameConfig.Mutation.BaseChance + eventModifiers.mutationBonus;
|
||||
let mutationId = "none";
|
||||
if (rng() < mutationChance) mutationId = pickId(rng, getMutationEntries());
|
||||
if (getIncomeMultiplier(mutationId) === undefined) mutationId = "none";
|
||||
|
||||
const w = animalDef.cellsWide ?? 1;
|
||||
const h = animalDef.cellsHigh ?? 1;
|
||||
const [canPlace, _reason] = canPlaceMultiCell(state, { originX: x, originY: y, w, h, excludeOriginKey: key });
|
||||
const hatchData = getHatchAnimalData({ state, cell, x, y, nowUnix, eventModifiers });
|
||||
if (hatchData === null) return false;
|
||||
const { animalData, w, h } = hatchData;
|
||||
const [canPlace] = canPlaceMultiCell(state, { originX: x, originY: y, w, h, excludeOriginKey: key });
|
||||
if (!canPlace) return false;
|
||||
const animalData = buildAnimalCell(pickedAnimalId, mutationId, nowUnix, {
|
||||
cellsWide: w,
|
||||
cellsHigh: h,
|
||||
});
|
||||
fillAnimalBlock(state, x, y, animalData);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user