{"version":3,"file":"simpleLightmapFilter.cjs","sources":["../../../src/filters/simpleLightmapFilter.ts"],"sourcesContent":["import { SimpleLightmapFilter } from 'pixi-filters';\nimport { Assets, Texture } from 'pixi.js';\nimport { type SimpleLightmapFilterConfig, type FilterResult } from './types';\nimport { ShaderResourceManager } from '../managers/ShaderResourceManager';\n\n/**\n * Creates a SimpleLightmap filter that applies a lighting effect\n *\n * The SimpleLightmapFilter creates a lighting effect by using a texture as a\n * lightmap source along with an ambient color. This can be used to create\n * dynamic lighting effects on images or other display objects.\n * Uses shader pooling for better performance.\n *\n * @param config - Configuration for the SimpleLightmap filter\n * @returns FilterResult with the filter instance and control functions\n */\nexport function createSimpleLightmapFilter(config: SimpleLightmapFilterConfig): FilterResult {\n    // Get shader manager instance\n    const shaderManager = ShaderResourceManager.getInstance();\n\n    // Create initial texture (placeholder or actual)\n    let lightMapTexture: any = config.lightMap;\n\n    if (typeof config.lightMap === 'string') {\n        // For string paths, start with a placeholder\n        lightMapTexture = Texture.EMPTY; // Use empty texture as placeholder\n\n        // Load the actual texture asynchronously\n        Assets.load(config.lightMap)\n            .then(texture => {\n                if (filter) {\n                    filter.lightMap = texture;\n                }\n            })\n            .catch(error => {\n                console.error(`Failed to load lightMap texture: ${config.lightMap}`, error);\n            });\n    }\n\n    // Convert color to a compatible format for SimpleLightmapFilter\n    // SimpleLightmapFilter expects a number for the color\n    let colorValue: number | undefined;\n\n    if (config.color !== undefined) {\n        // If it's already a number, use it directly\n        if (typeof config.color === 'number') {\n            colorValue = config.color;\n        }\n    }\n\n    // Create a unique key for this filter configuration\n    // The filter is mostly driven by external texture so we'll use a simpler key\n    const colorHex = (colorValue || 0).toString(16);\n    const shaderKey = `simple-lightmap-filter-${colorHex}`;\n\n    // Create the filter with properly typed parameters\n    const filter = new SimpleLightmapFilter(\n        lightMapTexture,          // lightMap texture\n        colorValue || 0x000000,   // ambient color as number (default black)\n        config.alpha              // alpha value\n    );\n\n    // Register filter with shader manager\n    try {\n        shaderManager.registerFilter(filter, shaderKey);\n    } catch (error) {\n        console.warn('Error registering simple lightmap filter with shader manager:', error);\n    }\n\n    /**\n     * Update the filter's intensity based on the configuration\n     *\n     * @param intensity - New intensity value (0-10 scale)\n     */\n    const updateIntensity = (intensity: number): void => {\n        // Normalize intensity to a 0-10 scale\n        const normalizedIntensity = Math.max(0, Math.min(10, intensity));\n\n        // Determine which property to adjust based on config\n        if (config.primaryProperty) {\n            switch (config.primaryProperty) {\n                case 'alpha':\n                    // Map 0-10 to 0-1 for alpha\n                    filter.alpha = normalizedIntensity / 10;\n                    break;\n                case 'brightness':\n                    // Here we simulate a brightness effect by adjusting the alpha\n                    // Higher intensity means more of the lightMap shows (brighter effect)\n                    filter.alpha = normalizedIntensity / 10;\n                    break;\n                case 'colorIntensity':\n                    // Here we could adjust the color intensity, but SimpleLightmap doesn't\n                    // directly support this. Instead, we'll leave the color as is\n                    // and use alpha to control overall intensity\n                    filter.alpha = normalizedIntensity / 10;\n                    break;\n                default:\n                    // Default to alpha adjustment\n                    filter.alpha = normalizedIntensity / 10;\n            }\n        } else {\n            // Default behavior - adjust alpha\n            filter.alpha = normalizedIntensity / 10;\n        }\n    };\n\n    // Set initial intensity\n    updateIntensity(config.intensity);\n\n    /**\n     * Reset the filter to default state\n     */\n    const reset = (): void => {\n        // Reset alpha to configured value or default\n        filter.alpha = config.alpha !== undefined ? config.alpha : 1;\n\n        // Reset color to configured value or default\n        if (colorValue !== undefined) {\n            filter.color = colorValue;\n        } else {\n            filter.color = 0x000000;\n        }\n    };\n\n    /**\n     * Release any WebGL resources used by this filter\n     */\n    const dispose = (): void => {\n        try {\n            shaderManager.releaseFilter(filter, shaderKey);\n        } catch (error) {\n            console.warn('Error releasing simple lightmap filter shader:', error);\n        }\n\n        // If we have a custom lightmap texture, we might want to dispose of it\n        // but we should be careful to only dispose of textures we create\n        // and not shared textures from the global Texture cache\n\n        // Destroy the filter\n        filter.destroy();\n    };\n\n    return { filter, updateIntensity, reset, dispose };\n}"],"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