/* ────────────────────────────────────────────────────────────────
   Platform Exporter — Base Infrastructure
   
   Base classes and utilities for exporting Nice2Dev projects
   to various game engines and platforms.
──────────────────────────────────────────────────────────────── */
/* ── Abstract Platform Exporter ───────────────────────────────── */
class PlatformExporter {
    constructor() {
        this.errors = [];
        this.warnings = [];
        this.files = [];
    }
    /**
     * Export a Nice2Dev project to this platform.
     */
    async export(project, options) {
        const startTime = performance.now();
        this.errors = [];
        this.warnings = [];
        this.files = [];
        try {
            await this.doExport(project, options);
        }
        catch (error) {
            this.addError('EXPORT_FAILED', error instanceof Error ? error.message : String(error));
        }
        return {
            success: this.errors.length === 0,
            platform: this.platformId,
            outputFiles: this.files,
            errors: this.errors,
            warnings: this.warnings,
            stats: {
                totalFiles: this.files.length,
                totalSize: this.files.reduce((sum, f) => sum + (typeof f.content === 'string' ? f.content.length : f.content.length), 0),
                duration: performance.now() - startTime,
                assetsProcessed: project.assets.length,
                scriptsGenerated: project.scripts.length,
                scenesExported: project.scenes.length,
            },
        };
    }
    /**
     * Check if this platform supports a feature.
     */
    supportsFeature(feature) {
        return this.platformInfo.features.includes(feature);
    }
    /**
     * Check if this platform supports an asset type.
     */
    supportsAsset(type) {
        return this.platformInfo.supportedAssets.includes(type);
    }
    /* ── Protected Helpers ──────────────────────────────────────── */
    addFile(path, content, type = 'text') {
        this.files.push({ path, content, type });
    }
    addTextFile(path, content) {
        this.addFile(path, content, 'text');
    }
    addBinaryFile(path, content) {
        this.addFile(path, content, 'binary');
    }
    addError(code, message, file, line) {
        this.errors.push({ code, message, file, line });
    }
    addWarning(code, message, suggestion) {
        this.warnings.push({ code, message, suggestion });
    }
}
function detectBestPlatform(project) {
    var _a, _b, _c;
    const results = [];
    // Check for 3D content
    const has3D = project.assets.some((a) => a.type === 'material' || a.type === 'shader') ||
        ((_a = project.settings.rendering) === null || _a === void 0 ? void 0 : _a.antialias);
    // Check for tilemaps
    const hasTilemaps = project.scenes.some((s) => { var _a; return ((_a = s.tilemaps) !== null && _a !== void 0 ? _a : []).length > 0; });
    // Check for complex physics
    const hasPhysics = (_b = project.settings.physics) === null || _b === void 0 ? void 0 : _b.enabled;
    // Check for pixel art style
    const isPixelArt = (_c = project.settings.rendering) === null || _c === void 0 ? void 0 : _c.pixelArt;
    // Unity - best for 3D, complex physics
    if (has3D || hasPhysics) {
        results.push({
            platform: 'unity',
            confidence: has3D ? 0.9 : 0.7,
            reasons: [
                ...(has3D ? ['3D content detected'] : []),
                ...(hasPhysics ? ['Complex physics requirements'] : []),
            ],
        });
    }
    // Godot - good all-rounder
    results.push({
        platform: 'godot',
        confidence: 0.8,
        reasons: ['Versatile 2D/3D support', 'Open source', 'GDScript native'],
    });
    // PixiJS - best for 2D web games
    if (!has3D) {
        results.push({
            platform: 'pixijs',
            confidence: isPixelArt ? 0.85 : 0.75,
            reasons: ['Fast 2D web rendering', ...(isPixelArt ? ['Excellent pixel art support'] : [])],
        });
    }
    // Phaser - good for tilemaps
    if (hasTilemaps) {
        results.push({
            platform: 'phaser',
            confidence: 0.8,
            reasons: ['Built-in tilemap support', 'Great for 2D games'],
        });
    }
    // Sort by confidence
    results.sort((a, b) => b.confidence - a.confidence);
    return results;
}
/* ── Platform Registry ────────────────────────────────────────── */
const platformRegistry = new Map();
function registerPlatform(info) {
    platformRegistry.set(info.id, info);
}
function getPlatformInfo(id) {
    return platformRegistry.get(id);
}
function getAllPlatforms() {
    return Array.from(platformRegistry.values());
}
// Register built-in platforms
registerPlatform({
    id: 'unity',
    name: 'Unity',
    description: 'Professional game engine for 2D and 3D games',
    website: 'https://unity.com',
    features: [
        '2d-rendering',
        '3d-rendering',
        'physics-2d',
        'physics-3d',
        'audio',
        'networking',
        'ui-system',
        'visual-scripting',
        'particles',
        'animation',
        'vr-ar',
    ],
    supportedAssets: [
        'sprite',
        'tileset',
        'audio',
        'font',
        'script',
        'scene',
        'prefab',
        'material',
        'shader',
        'animation',
        'particleSystem',
    ],
    exportFormats: ['.unitypackage', '.prefab', '.unity', '.cs'],
});
registerPlatform({
    id: 'godot',
    name: 'Godot Engine',
    description: 'Free and open source game engine',
    website: 'https://godotengine.org',
    features: [
        '2d-rendering',
        '3d-rendering',
        'physics-2d',
        'physics-3d',
        'audio',
        'networking',
        'ui-system',
        'visual-scripting',
        'tilemaps',
        'particles',
        'animation',
    ],
    supportedAssets: [
        'sprite',
        'tileset',
        'audio',
        'font',
        'script',
        'scene',
        'prefab',
        'material',
        'shader',
        'animation',
        'tilemap',
        'particleSystem',
    ],
    exportFormats: ['.tscn', '.tres', '.gd', '.godot'],
});
registerPlatform({
    id: 'pixijs',
    name: 'PixiJS',
    description: 'Fast 2D WebGL renderer',
    website: 'https://pixijs.com',
    features: ['2d-rendering', 'particles', 'animation'],
    supportedAssets: ['sprite', 'tileset', 'audio', 'font', 'script', 'animation'],
    exportFormats: ['.html', '.js', '.ts'],
});
registerPlatform({
    id: 'phaser',
    name: 'Phaser',
    description: 'Desktop and mobile HTML5 game framework',
    website: 'https://phaser.io',
    features: ['2d-rendering', 'physics-2d', 'audio', 'tilemaps', 'particles', 'animation'],
    supportedAssets: ['sprite', 'tileset', 'audio', 'font', 'script', 'animation', 'tilemap'],
    exportFormats: ['.html', '.js', '.ts'],
});
registerPlatform({
    id: 'threejs',
    name: 'Three.js',
    description: '3D JavaScript library for WebGL',
    website: 'https://threejs.org',
    features: ['3d-rendering', 'particles', 'animation', 'vr-ar'],
    supportedAssets: ['sprite', 'audio', 'font', 'script', 'material', 'shader', 'animation'],
    exportFormats: ['.html', '.js', '.ts'],
});

export { PlatformExporter, detectBestPlatform, getAllPlatforms, getPlatformInfo, registerPlatform };
//# sourceMappingURL=PlatformExporter.js.map
