import { fileExists, hasAnyFile } from '../detection-utils.js';
const GAME_FW_SET = new Set(['unity', 'godot', 'unreal', 'bevy', 'phaser', 'pygame']);
/**
 * Returns true if the framework string matches a known game engine.
 */
export function isGameFramework(framework) {
    return framework !== null && GAME_FW_SET.has(framework);
}
/**
 * Returns the game engine name if the project is a game.
 * Uses filesystem signals as fallback when framework detection misses.
 * Macroquad (Rust) is grouped under 'bevy' as both are Rust game engines.
 */
export async function detectGameEngine(projectPath, framework) {
    if (isGameFramework(framework)) {
        return framework;
    }
    // Unity: ProjectSettings/ProjectSettings.asset
    if (await hasAnyFile(projectPath, [
        'ProjectSettings/*.asset',
        'ProjectSettings/ProjectSettings.asset',
    ])) {
        return 'unity';
    }
    // Godot: project.godot
    if (await fileExists(projectPath, 'project.godot')) {
        return 'godot';
    }
    // Unreal: *.uproject
    if (await hasAnyFile(projectPath, ['*.uproject'])) {
        return 'unreal';
    }
    // Bevy or Macroquad: Cargo.toml with bevy or macroquad dependency
    if (await fileExists(projectPath, 'Cargo.toml')) {
        const cargoContent = await tryReadFile(projectPath, 'Cargo.toml');
        if (cargoContent !== null && /bevy|macroquad/.test(cargoContent)) {
            return 'bevy';
        }
    }
    return null;
}
/**
 * Get the primary scripting/programming language for a game engine.
 */
export function getGameEngineLanguage(engine) {
    const languageMap = {
        unity: 'csharp',
        godot: 'gdscript',
        unreal: 'cpp',
        bevy: 'rust',
        phaser: 'typescript',
        pygame: 'python',
    };
    return languageMap[engine];
}
async function tryReadFile(basePath, relativePath) {
    try {
        const fsModule = await import('node:fs/promises');
        const pathModule = await import('node:path');
        const fullPath = pathModule.join(basePath, relativePath);
        return await fsModule.readFile(fullPath, 'utf-8');
    }
    catch {
        /* v8 ignore next */
        return null;
    }
}
//# sourceMappingURL=games.js.map