winter-tales/Utilities/PostProcessingHack.cs

102 lines
2.0 KiB
C#
Raw Normal View History

2025-11-28 14:27:39 +00:00
using Godot;
using Rokojori;
using System.Collections.Generic;
using System.Threading.Tasks;
[Tool, GlobalClass]
public partial class PostProcessingHack : Action
{
[Export]
public WorldEnvironment environment;
2026-01-15 14:01:40 +00:00
[Export]
public CompositorEffectOwner owner;
2025-11-28 14:27:39 +00:00
protected override void _OnTrigger()
{
2025-12-21 18:58:19 +00:00
ApplyHack();
}
2025-11-28 14:27:39 +00:00
2025-12-21 18:58:19 +00:00
void ApplyHack()
{
2025-11-28 14:27:39 +00:00
var godotArray = new Godot.Collections.Array<CompositorEffect>();
2025-12-21 18:58:19 +00:00
var compositorEffects = environment.Compositor.CompositorEffects;
2025-11-28 14:27:39 +00:00
2025-12-21 18:58:19 +00:00
for ( int i = 0; i < compositorEffects.Count; i++ )
2025-11-28 14:27:39 +00:00
{
2025-12-25 17:21:27 +00:00
if ( compositorEffects[ i ] == null )
{
godotArray.Add( null );
continue;
2026-01-15 14:01:40 +00:00
}
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 ] );
2025-12-25 17:21:27 +00:00
}
2026-01-15 14:01:40 +00:00
2025-11-28 14:27:39 +00:00
}
environment.Compositor.CompositorEffects = godotArray;
}
2025-12-21 18:58:19 +00:00
#if TOOLS
int retriggerFramesCount = 60 * 5;
int framesCounter = 0;
2026-01-15 14:01:40 +00:00
2025-12-21 18:58:19 +00:00
public override void _Process( double delta )
{
if ( ! Engine.IsEditorHint() )
{
return;
}
2025-12-25 17:21:27 +00:00
2025-12-21 18:58:19 +00:00
framesCounter --;
if ( framesCounter > 0 )
{
return;
}
2025-12-25 17:21:27 +00:00
2025-12-21 18:58:19 +00:00
framesCounter = retriggerFramesCount;
2025-12-25 17:21:27 +00:00
var selection = EditorInterface.Singleton.GetSelection();
var topSelected = selection.GetTopSelectedNodes();
if ( topSelected.Contains( environment ) )
{
// RJLog.Log( "Environment selected, not applying Post Processing Hack" );
return;
}
2025-12-21 18:58:19 +00:00
// RJLog.Log( "Applying Post Processing Hack" );
ApplyHack();
}
#endif
2025-11-28 14:27:39 +00:00
}