import { readFileSync, existsSync } from 'fs'; import { join } from 'path'; const configPath = join(process.cwd(), 'src', 'config', 'config.json'); export interface GameConfigType { leveling: { base: number; exponent: number; chat: { cooldownMs: number; minXp: number; maxXp: number; } }, economy: { daily: { amount: bigint; streakBonus: bigint; cooldownMs: number; }, transfers: { allowSelfTransfer: boolean; minAmount: bigint; } }, inventory: { maxStackSize: bigint; maxSlots: number; }, commands: Record; } // Initial default config state export const config: GameConfigType = {} as GameConfigType; export function reloadConfig() { if (!existsSync(configPath)) { throw new Error(`Config file not found at ${configPath}`); } const raw = readFileSync(configPath, 'utf-8'); const rawConfig = JSON.parse(raw); // Update config object in place config.leveling = rawConfig.leveling; config.economy = { daily: { ...rawConfig.economy.daily, amount: BigInt(rawConfig.economy.daily.amount), streakBonus: BigInt(rawConfig.economy.daily.streakBonus), }, transfers: { ...rawConfig.economy.transfers, minAmount: BigInt(rawConfig.economy.transfers.minAmount), } }; config.inventory = { ...rawConfig.inventory, maxStackSize: BigInt(rawConfig.inventory.maxStackSize), }; config.commands = rawConfig.commands || {}; console.log("🔄 Config reloaded from disk."); } // Initial load reloadConfig(); // Backwards compatibility alias export const GameConfig = config;