import { readFileSync } from "fs"; import { join } from "path"; interface Config { canvasWidth: number; canvasHeight: number; defaultCooldown: number; enableAutomaticEvents: boolean; eventDurationMinutes: number; eventIntervalHours: number; autoExportIntervalSeconds: number; exportPath: string; } function parseConfigFile(): Config { try { const configPath = join(process.cwd(), "config.cfg"); const configContent = readFileSync(configPath, "utf-8"); const config: Partial = {}; configContent.split("\n").forEach(line => { line = line.trim(); if (line.startsWith("#") || !line.includes("=")) return; const [key, value] = line.split("="); const trimmedKey = key.trim(); const trimmedValue = value.trim(); switch (trimmedKey) { case "CANVAS_WIDTH": config.canvasWidth = parseInt(trimmedValue); break; case "CANVAS_HEIGHT": config.canvasHeight = parseInt(trimmedValue); break; case "DEFAULT_COOLDOWN": config.defaultCooldown = parseInt(trimmedValue); break; case "ENABLE_AUTOMATIC_EVENTS": config.enableAutomaticEvents = trimmedValue.toLowerCase() === "true"; break; case "EVENT_DURATION_MINUTES": config.eventDurationMinutes = parseInt(trimmedValue); break; case "EVENT_INTERVAL_HOURS": config.eventIntervalHours = parseInt(trimmedValue); break; case "AUTO_EXPORT_INTERVAL_SECONDS": config.autoExportIntervalSeconds = parseInt(trimmedValue); break; case "EXPORT_PATH": config.exportPath = trimmedValue; break; } }); // Set defaults for missing values return { canvasWidth: config.canvasWidth || 100, canvasHeight: config.canvasHeight || 100, defaultCooldown: config.defaultCooldown || 5, enableAutomaticEvents: config.enableAutomaticEvents || false, eventDurationMinutes: config.eventDurationMinutes || 30, eventIntervalHours: config.eventIntervalHours || 6, autoExportIntervalSeconds: config.autoExportIntervalSeconds || 60, exportPath: config.exportPath || "./exports/", }; } catch (error) { console.error("Error reading config file, using defaults:", error); return { canvasWidth: 100, canvasHeight: 100, defaultCooldown: 5, enableAutomaticEvents: false, eventDurationMinutes: 30, eventIntervalHours: 6, autoExportIntervalSeconds: 60, exportPath: "./exports/", }; } } export const config = parseConfigFile();