Files
builazoo/web/js/default-grid-layout.js
Nicolas Cantu e031c9a1d2 Initial commit
**Motivations:**
- Initialisation du versionning git pour le projet

**Root causes:**
- N/A (Nouveau projet)

**Correctifs:**
- N/A

**Evolutions:**
- Structure initiale du projet
- Ajout du .gitignore

**Pages affectées:**
- Tous les fichiers
2026-03-03 22:24:17 +01:00

67 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Shared default zoo grid layout: row 1 building cells and 3 starter couples (row 2).
* Used by state.js (defaultState) and prestige.js (doPrestige).
*/
import { LootTables } from "./loot-tables.js";
import { fillAnimalBlock } from "./placement.js";
/** Row 1 layout: (col, kind). Columns 16. */
const ROW1_LAYOUT = [
[1, "research"],
[2, "billeterie"],
[3, "nursery"],
[4, "reception"],
[5, "food"],
[6, "school"],
];
/**
* Build default cells for row 1 (research, billeterie, nursery, reception, food, school).
* @returns {Record<string, { kind: string, level: number }>}
*/
export function buildDefaultRow1Cells() {
const cells = {};
for (const [col, kind] of ROW1_LAYOUT) {
cells[`${col}_1`] = { kind, level: 1 };
}
return cells;
}
/** Default animal ids for the 3 starter couples (one per biome: Meadow, Ocean, Mountain). */
export const STARTER_ANIMAL_IDS_BY_BIOME = ["c0_r0", "c5_r0", "c10_r0"];
/** Positions for the 6 starter animals (row 2, columns 16). */
export const STARTER_ANIMAL_POSITIONS = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2]];
/**
* Place 3 breeding couples (6 animals) on the grid. Mutates state.grid.cells.
* @param {import("./types.js").GameState} state
*/
export function addStarterAnimals(state) {
const now = Math.floor(Date.now() / 1000);
let idx = 0;
for (const animalId of STARTER_ANIMAL_IDS_BY_BIOME) {
const def = LootTables.Animals[animalId];
if (def !== null && def !== undefined) {
const w = def.cellsWide ?? 1;
const h = def.cellsHigh ?? 1;
for (let pair = 0; pair < 2 && idx < STARTER_ANIMAL_POSITIONS.length; pair++, idx++) {
const [x, y] = STARTER_ANIMAL_POSITIONS[idx];
fillAnimalBlock(state, x, y, {
kind: "animal",
id: animalId,
mutation: "none",
level: 1,
placedAt: now,
lastVisitedAt: now,
lastFedAt: now,
cellsWide: w,
cellsHigh: h,
fromOtherZoo: false,
});
}
}
}
}