Selectors Update

This commit is contained in:
Josef 2025-06-12 16:04:15 +02:00
parent b475d5141a
commit 31f5077b72
11 changed files with 252 additions and 12 deletions

View File

@ -45,11 +45,20 @@ namespace Rokojori
void TriggerOnEnter( Node n ) void TriggerOnEnter( Node n )
{ {
if ( ! Selector.IsSelecting( selector, n ) ) if ( ! Math3D.IsValid( area.GlobalPosition ) )
{ {
return; return;
} }
if ( ! Selector.IsSelecting( selector, n ) )
{
return;
}
this.LogInfo( "Selecting Enter", area.GlobalPosition, HierarchyName.Of( n ), ( (Node3D)n ).GlobalPosition );
Action.Trigger( onEntered ); Action.Trigger( onEntered );
if ( onInside == null ) if ( onInside == null )

View File

@ -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();
}
}
}
);
}
}
}

View File

@ -0,0 +1 @@
uid://lowdvkluckpb

View File

@ -25,6 +25,8 @@ namespace Rokojori
public static readonly AnimationMember Rotation = new AnimationMember( "rotation" ); public static readonly AnimationMember Rotation = new AnimationMember( "rotation" );
public static readonly AnimationMember Scale = new AnimationMember( "scale" ); public static readonly AnimationMember Scale = new AnimationMember( "scale" );
public static readonly AnimationMember VolumeDB = new AnimationMember( "volumeDB" );
public static readonly AnimationMember[] Transform = new AnimationMember[] public static readonly AnimationMember[] Transform = new AnimationMember[]
{ {
AnimationMember.Position, AnimationMember.Rotation, AnimationMember.Scale AnimationMember.Position, AnimationMember.Rotation, AnimationMember.Scale

View File

@ -50,8 +50,8 @@ namespace Rokojori
[ExportToolButton( "Initialize")] // [ExportToolButton( "Initialize")]
public Callable InitializeButton => Callable.From( Initialize ); // public Callable InitializeButton => Callable.From( Initialize );
public void Initialize() public void Initialize()
{ {

View File

@ -153,8 +153,6 @@ namespace Rokojori
{ {
Trigger( onStoppedMoving ); Trigger( onStoppedMoving );
} }
this.LogInfo( "Moving:", _moving );
} }
Velocity( smoothedMovement, onFloor ); Velocity( smoothedMovement, onFloor );

View File

@ -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<Node>.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;
}
}
}

View File

@ -0,0 +1 @@
uid://doo8jwdet1hyi

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
uid://c5vxa38rgr24k

View File

@ -19,7 +19,7 @@ namespace Rokojori
set set
{ {
_inputIcons = value; _inputIcons = value;
UpdateInfo(); // UpdateInfo();
} }
} }
@ -39,10 +39,10 @@ namespace Rokojori
[Export] [Export]
public DeviceFilter deviceFilter; public DeviceFilter deviceFilter;
// public override void _Ready() public override void _Ready()
// { {
// UpdateInfo(); UpdateInfo();
// } }
void UpdateInfo() void UpdateInfo()
{ {