Refactor: Centralisation des constantes de configuration
**Motivations:** - Éviter la duplication de code pour la lecture des configurations - Centraliser les valeurs par défaut **Root causes:** - Code dupliqué dans bot-zoo.js et trade.js **Correctifs:** - N/A **Evolutions:** - Ajout de `getUpgradeMaxLevels` dans bot-zoo.js - Ajout de `getSaleListingDefaults` dans trade.js - Mise à jour de la documentation `centralisations-mutualisations.md` **Pages affectées:** - web/js/bot-zoo.js - web/js/trade.js - docs/features/centralisations-mutualisations.md
This commit is contained in:
@@ -6,6 +6,17 @@ import { getBlockKeysFromCell } from "./placement.js";
|
||||
import { GameConfig } from "./config.js";
|
||||
import { getReproductionScore } from "./reproduction.js";
|
||||
|
||||
/**
|
||||
* Default duration and price for a new sale listing from config.
|
||||
* @returns {{ duration: number, price: number }}
|
||||
*/
|
||||
function getSaleListingDefaults() {
|
||||
return {
|
||||
duration: GameConfig.Sale?.ListingDurationSeconds ?? 3600,
|
||||
price: GameConfig.Sale?.DefaultPrice ?? 50,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a mature baby from nursery on sale (phase 10). Removes it from pendingBabies and clears the nursery cell.
|
||||
* @param {import("./types.js").GameState} state
|
||||
@@ -27,8 +38,7 @@ export function addMatureBabyToSale(state, nurseryCellKey) {
|
||||
const cell = state.grid.cells[nurseryCellKey];
|
||||
if (cell && cell.kind === "nursery") cell.tokenId = undefined;
|
||||
state.saleListings = state.saleListings ?? [];
|
||||
const duration = GameConfig.Sale?.ListingDurationSeconds ?? 3600;
|
||||
const price = GameConfig.Sale?.DefaultPrice ?? 50;
|
||||
const { duration, price } = getSaleListingDefaults();
|
||||
const listingId = `sale_${state.nextTokenId}`;
|
||||
state.nextTokenId += 1;
|
||||
state.saleListings.push({
|
||||
@@ -63,8 +73,7 @@ export function addReceptionAnimalToSale(state, receptionCellKey) {
|
||||
const rec = receptionAnimals[idx];
|
||||
state.receptionAnimals = receptionAnimals.filter((_, i) => i !== idx);
|
||||
state.saleListings = state.saleListings ?? [];
|
||||
const duration = GameConfig.Sale?.ListingDurationSeconds ?? 3600;
|
||||
const price = GameConfig.Sale?.DefaultPrice ?? 50;
|
||||
const { duration, price } = getSaleListingDefaults();
|
||||
const listingId = `sale_${state.nextTokenId}`;
|
||||
state.nextTokenId += 1;
|
||||
state.saleListings.push({
|
||||
|
||||
Reference in New Issue
Block a user