'use strict';

/* ────────────────────────────────────────────────────────────────
   GameConfig — Global game configuration
──────────────────────────────────────────────────────────────── */
const WHITE = { r: 1, g: 1, b: 1, a: 1 };
const DEFAULT_PHYSICS = {
    gravity: { x: 0, y: 980 },
    fixedTimestep: 1 / 60,
    velocityIterations: 8,
    positionIterations: 3,
};
const DEFAULT_AUDIO = {
    masterVolume: 1,
    musicVolume: 0.7,
    sfxVolume: 1,
    voiceVolume: 1,
};
const DEFAULT_RENDERING = {
    pixelPerfect: false,
    antiAlias: true,
    backgroundColor: WHITE,
};
const DEFAULT_SETTINGS = {
    width: 1280,
    height: 720,
    targetFps: 60,
    maxPlayers: 4,
    physics: { ...DEFAULT_PHYSICS },
    audio: { ...DEFAULT_AUDIO },
    rendering: { ...DEFAULT_RENDERING },
};
class GameConfig {
    constructor(overrides) {
        this._settings = mergeSettings(DEFAULT_SETTINGS, overrides !== null && overrides !== void 0 ? overrides : {});
    }
    get settings() {
        return this._settings;
    }
    get width() { return this._settings.width; }
    get height() { return this._settings.height; }
    get targetFps() { return this._settings.targetFps; }
    get maxPlayers() { return this._settings.maxPlayers; }
    get physics() { return this._settings.physics; }
    get audio() { return this._settings.audio; }
    get rendering() { return this._settings.rendering; }
    update(overrides) {
        this._settings = mergeSettings(this._settings, overrides);
    }
    toJSON() {
        return structuredClone(this._settings);
    }
    static fromJSON(json) {
        return new GameConfig(json);
    }
}
/* ── Deep merge utility ───────────────────────────────────────── */
/** Type-safe deep merge wrapper — returns T preserving the original shape. */
function mergeSettings(target, source) {
    return mergeDeepRaw(target, source);
}
function mergeDeepRaw(target, source) {
    const result = { ...target };
    const src = source;
    for (const key of Object.keys(src)) {
        const sv = src[key];
        const tv = result[key];
        if (isPlainObject(sv) && isPlainObject(tv)) {
            result[key] = mergeDeepRaw(tv, sv);
        }
        else if (sv !== undefined) {
            result[key] = sv;
        }
    }
    return result;
}
function isPlainObject(v) {
    return typeof v === 'object' && v !== null && !Array.isArray(v);
}

exports.DEFAULT_AUDIO = DEFAULT_AUDIO;
exports.DEFAULT_PHYSICS = DEFAULT_PHYSICS;
exports.DEFAULT_RENDERING = DEFAULT_RENDERING;
exports.DEFAULT_SETTINGS = DEFAULT_SETTINGS;
exports.GameConfig = GameConfig;
//# sourceMappingURL=GameConfig.js.map
