From 31f5077b7279844ac7d959e862cb8190bc0b1e4f Mon Sep 17 00:00:00 2001 From: Josef Date: Thu, 12 Jun 2025 16:04:15 +0200 Subject: [PATCH] Selectors Update --- Runtime/Actions/Node3D/OnCollision.cs | 13 +- Runtime/Actions/Node3D/TweenAudio.cs | 140 ++++++++++++++++++ Runtime/Actions/Node3D/TweenAudio.cs.uid | 1 + Runtime/Animation/AnimationManager.cs | 2 + Runtime/App/App.cs | 4 +- .../CharacterController/CharacterMovement.cs | 2 - Runtime/Selectors/FlagSelector.cs | 68 +++++++++ Runtime/Selectors/FlagSelector.cs.uid | 1 + Runtime/Selectors/Selectable.cs | 20 +++ Runtime/Selectors/Selectable.cs.uid | 1 + Runtime/UI/Nodes/UIInputInfo.cs | 12 +- 11 files changed, 252 insertions(+), 12 deletions(-) create mode 100644 Runtime/Actions/Node3D/TweenAudio.cs create mode 100644 Runtime/Actions/Node3D/TweenAudio.cs.uid create mode 100644 Runtime/Selectors/FlagSelector.cs create mode 100644 Runtime/Selectors/FlagSelector.cs.uid create mode 100644 Runtime/Selectors/Selectable.cs create mode 100644 Runtime/Selectors/Selectable.cs.uid diff --git a/Runtime/Actions/Node3D/OnCollision.cs b/Runtime/Actions/Node3D/OnCollision.cs index 0460023..9a7047b 100644 --- a/Runtime/Actions/Node3D/OnCollision.cs +++ b/Runtime/Actions/Node3D/OnCollision.cs @@ -45,11 +45,20 @@ namespace Rokojori void TriggerOnEnter( Node n ) { - if ( ! Selector.IsSelecting( selector, n ) ) + if ( ! Math3D.IsValid( area.GlobalPosition ) ) { + return; + } + + if ( ! Selector.IsSelecting( selector, n ) ) + { + return; } - + + + + this.LogInfo( "Selecting Enter", area.GlobalPosition, HierarchyName.Of( n ), ( (Node3D)n ).GlobalPosition ); Action.Trigger( onEntered ); if ( onInside == null ) diff --git a/Runtime/Actions/Node3D/TweenAudio.cs b/Runtime/Actions/Node3D/TweenAudio.cs new file mode 100644 index 0000000..3b04277 --- /dev/null +++ b/Runtime/Actions/Node3D/TweenAudio.cs @@ -0,0 +1,140 @@ + +using System; +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass ] + public partial class TweenAudio:SequenceAction, Animator + { + + [Export] + public AudioStreamPlayer3D target; + + [Export(PropertyHint.Range, "-80,80")] + public float endVolumeDB; + + [Export] + public bool tweenInLinearAmplitude = true; + + [Export] + public bool changePlayState = true; + + [Export] + public float changingPlayStateTresholdDB = -40f; + + [Export] + public TweenType tweenType = new TweenTimeCurve(); + + + [Export] + public bool cacheEndVolumeOnStart = true; + + [Export] + public TimeLine timeLine; + + + public void OnAnimatorStart(){} + public void OnAnimatorEnd(){} + public void OnAnimatorCancel(){} + + + public float GetVolume( float volume ) + { + if ( tweenInLinearAmplitude ) + { + return MathAudio.DecibelsToAmplitude( volume ); + } + + return volume; + } + + public float SetVolume( float volume ) + { + if ( tweenInLinearAmplitude ) + { + return MathAudio.AmplitudeToDecibels( volume ); + } + + return volume; + } + + + protected override void _OnTrigger() + { + if ( target == null ) + { + return; + } + + var tl = TimeLineManager.Ensure( timeLine ); + + var start = tl.position; + + var fromVolume = GetVolume( target.VolumeDb ); + var toVolume = GetVolume( endVolumeDB ); + + + var sequenceID = DispatchStart(); + + var tweenType = this.tweenType; + + if ( tweenType == null ) + { + tweenType = TweenTimeCurve.defaultCurve; + } + + if ( changePlayState && toVolume > changingPlayStateTresholdDB ) + { + // this.LogInfo( "Play" ); + target.Playing = true; + target.Play( 0 ); + } + + AnimationManager.StartAnimation( this, target, AnimationMember.VolumeDB ); + + TimeLineManager.ScheduleSpanIn( tl, 0, tweenType.GetTweenDuration(), + ( span, type )=> + { + if ( ! AnimationManager.IsAnimating( this, target, AnimationMember.VolumeDB ) ) + { + return; + } + + var timeNow = tl.position; + var elapsed = timeNow - start; + + var state = tweenType.GetTweenPhaseForPhase( span.phase ); + + if ( ! cacheEndVolumeOnStart ) + { + toVolume = GetVolume( endVolumeDB ); + } + + var lerpedVolume = Mathf.Lerp( fromVolume, toVolume, state ); + + target.VolumeDb = SetVolume( lerpedVolume ); + + // this.LogInfo( "Volume", lerpedVolume ); + + if ( type == TimeLineSpanUpdateType.End ) + { + DispatchEnd( sequenceID ); + + AnimationManager.EndAnimation( this, target, AnimationMember.VolumeDB ); + + if ( changePlayState && SetVolume( toVolume ) < changingPlayStateTresholdDB ) + { + // this.LogInfo( "Stop" ); + target.Playing = false; + target.Stop(); + } + } + } + ); + } + + } +} \ No newline at end of file diff --git a/Runtime/Actions/Node3D/TweenAudio.cs.uid b/Runtime/Actions/Node3D/TweenAudio.cs.uid new file mode 100644 index 0000000..1183f4b --- /dev/null +++ b/Runtime/Actions/Node3D/TweenAudio.cs.uid @@ -0,0 +1 @@ +uid://lowdvkluckpb diff --git a/Runtime/Animation/AnimationManager.cs b/Runtime/Animation/AnimationManager.cs index 00262e7..78efea0 100644 --- a/Runtime/Animation/AnimationManager.cs +++ b/Runtime/Animation/AnimationManager.cs @@ -25,6 +25,8 @@ namespace Rokojori public static readonly AnimationMember Rotation = new AnimationMember( "rotation" ); public static readonly AnimationMember Scale = new AnimationMember( "scale" ); + public static readonly AnimationMember VolumeDB = new AnimationMember( "volumeDB" ); + public static readonly AnimationMember[] Transform = new AnimationMember[] { AnimationMember.Position, AnimationMember.Rotation, AnimationMember.Scale diff --git a/Runtime/App/App.cs b/Runtime/App/App.cs index 6209151..33745f3 100644 --- a/Runtime/App/App.cs +++ b/Runtime/App/App.cs @@ -50,8 +50,8 @@ namespace Rokojori - [ExportToolButton( "Initialize")] - public Callable InitializeButton => Callable.From( Initialize ); + // [ExportToolButton( "Initialize")] + // public Callable InitializeButton => Callable.From( Initialize ); public void Initialize() { diff --git a/Runtime/Interactions/CharacterController/CharacterMovement.cs b/Runtime/Interactions/CharacterController/CharacterMovement.cs index 12b346b..eca959b 100644 --- a/Runtime/Interactions/CharacterController/CharacterMovement.cs +++ b/Runtime/Interactions/CharacterController/CharacterMovement.cs @@ -153,8 +153,6 @@ namespace Rokojori { Trigger( onStoppedMoving ); } - - this.LogInfo( "Moving:", _moving ); } Velocity( smoothedMovement, onFloor ); diff --git a/Runtime/Selectors/FlagSelector.cs b/Runtime/Selectors/FlagSelector.cs new file mode 100644 index 0000000..cec835f --- /dev/null +++ b/Runtime/Selectors/FlagSelector.cs @@ -0,0 +1,68 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; +using System.Linq; + + +namespace Rokojori +{ + [Tool] + [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Selector.svg")] + public partial class FlagSelector:Selector + { + [Export] + public SelectorFlag[] flag; + + public enum FlagMode + { + Needs_One_Flag, + Needs_All_Flags + } + + [Export] + public FlagMode mode = FlagMode.Needs_One_Flag; + + [Export] + + public TreeIteratorType iteratorType = TreeIteratorType.DirectChildren; + + public override bool Selects( Node node ) + { + var iterator = TreeIterator.GetIterator( iteratorType, node, NodesWalker.Get() ); + + while ( iterator.HasNext() ) + { + iterator.MoveToNext(); + + var it = iterator.Current(); + + if ( it is Selectable s ) + { + var numPresent = 0; + + for ( int i = 0; i < flag.Length; i++ ) + { + if ( Array.IndexOf( s.flags, flag[ i ] ) != -1 ) + { + numPresent ++; + } + } + + if ( numPresent == flag.Length || mode == FlagMode.Needs_One_Flag && numPresent > 0 ) + { + return true; + } + + + } + } + + return false; + + } + + } +} \ No newline at end of file diff --git a/Runtime/Selectors/FlagSelector.cs.uid b/Runtime/Selectors/FlagSelector.cs.uid new file mode 100644 index 0000000..8ef504d --- /dev/null +++ b/Runtime/Selectors/FlagSelector.cs.uid @@ -0,0 +1 @@ +uid://doo8jwdet1hyi diff --git a/Runtime/Selectors/Selectable.cs b/Runtime/Selectors/Selectable.cs new file mode 100644 index 0000000..d2954ae --- /dev/null +++ b/Runtime/Selectors/Selectable.cs @@ -0,0 +1,20 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Selector.svg")] + public partial class Selectable:Node + { + [Export] + public SelectorFlag[] flags; + + + } +} \ No newline at end of file diff --git a/Runtime/Selectors/Selectable.cs.uid b/Runtime/Selectors/Selectable.cs.uid new file mode 100644 index 0000000..cfb6f98 --- /dev/null +++ b/Runtime/Selectors/Selectable.cs.uid @@ -0,0 +1 @@ +uid://c5vxa38rgr24k diff --git a/Runtime/UI/Nodes/UIInputInfo.cs b/Runtime/UI/Nodes/UIInputInfo.cs index 766538f..7304410 100644 --- a/Runtime/UI/Nodes/UIInputInfo.cs +++ b/Runtime/UI/Nodes/UIInputInfo.cs @@ -19,7 +19,7 @@ namespace Rokojori set { _inputIcons = value; - UpdateInfo(); + // UpdateInfo(); } } @@ -38,11 +38,11 @@ namespace Rokojori [Export] public DeviceFilter deviceFilter; - - // public override void _Ready() - // { - // UpdateInfo(); - // } + + public override void _Ready() + { + UpdateInfo(); + } void UpdateInfo() {