using Godot; using Rokojori; using System.Collections.Generic; using System.Threading.Tasks; [Tool, GlobalClass] public partial class PostProcessingHack : Action { [Export] public WorldEnvironment environment; [Export] public CompositorEffectOwner owner; protected override void _OnTrigger() { ApplyHack(); } void ApplyHack() { var godotArray = new Godot.Collections.Array(); var compositorEffects = environment.Compositor.CompositorEffects; for ( int i = 0; i < compositorEffects.Count; i++ ) { if ( compositorEffects[ i ] == null ) { godotArray.Add( null ); continue; } var effect = compositorEffects[ i ]; if ( effect.Enabled && effect is RokojoriCompositorEffect re ) { if ( re.compositorEffectID == null ) { godotArray.Add( (CompositorEffect) effect.Duplicate() ); } else if ( re.compositorEffectID.owner == owner ) { godotArray.Add( (CompositorEffect) effect.Duplicate() ); } else { godotArray.Add( compositorEffects[ i ] ); } } else { godotArray.Add( compositorEffects[ i ] ); } } environment.Compositor.CompositorEffects = godotArray; } #if TOOLS int retriggerFramesCount = 60 * 5; int framesCounter = 0; public override void _Process( double delta ) { if ( ! Engine.IsEditorHint() ) { return; } framesCounter --; if ( framesCounter > 0 ) { return; } framesCounter = retriggerFramesCount; var selection = EditorInterface.Singleton.GetSelection(); var topSelected = selection.GetTopSelectedNodes(); if ( topSelected.Contains( environment ) ) { // RJLog.Log( "Environment selected, not applying Post Processing Hack" ); return; } // RJLog.Log( "Applying Post Processing Hack" ); ApplyHack(); } #endif }