diff --git a/Icons/RJ_Action.svg b/Icons/RJL_Action.svg similarity index 100% rename from Icons/RJ_Action.svg rename to Icons/RJL_Action.svg diff --git a/Icons/RJ_Action.svg.import b/Icons/RJL_Action.svg.import similarity index 77% rename from Icons/RJ_Action.svg.import rename to Icons/RJL_Action.svg.import index c051f84..2d6e0d5 100644 --- a/Icons/RJ_Action.svg.import +++ b/Icons/RJL_Action.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://bc02q72sijom4" -path="res://.godot/imported/RJ_Action.svg-e2ec937a63457fcfbd6e5b3d52f60bb6.ctex" +path="res://.godot/imported/RJL_Action.svg-ef0e0e45f9dd3d858ecd91762a034172.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/rokojori_action_library/Icons/RJ_Action.svg" -dest_files=["res://.godot/imported/RJ_Action.svg-e2ec937a63457fcfbd6e5b3d52f60bb6.ctex"] +source_file="res://addons/rokojori_action_library/Icons/RJL_Action.svg" +dest_files=["res://.godot/imported/RJL_Action.svg-ef0e0e45f9dd3d858ecd91762a034172.ctex"] [params] diff --git a/Icons/RJ_SequenceAction.svg b/Icons/RJL_SequenceAction.svg similarity index 100% rename from Icons/RJ_SequenceAction.svg rename to Icons/RJL_SequenceAction.svg diff --git a/Icons/RJ_SequenceAction.svg.import b/Icons/RJL_SequenceAction.svg.import similarity index 75% rename from Icons/RJ_SequenceAction.svg.import rename to Icons/RJL_SequenceAction.svg.import index 938537f..5237561 100644 --- a/Icons/RJ_SequenceAction.svg.import +++ b/Icons/RJL_SequenceAction.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://didqgj0wwsx4l" -path="res://.godot/imported/RJ_SequenceAction.svg-1ef2c9c94a8c9f5c9dcc7af742ad00d8.ctex" +path="res://.godot/imported/RJL_SequenceAction.svg-790e79bd878da76261dea54ce9c5ee0d.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/rokojori_action_library/Icons/RJ_SequenceAction.svg" -dest_files=["res://.godot/imported/RJ_SequenceAction.svg-1ef2c9c94a8c9f5c9dcc7af742ad00d8.ctex"] +source_file="res://addons/rokojori_action_library/Icons/RJL_SequenceAction.svg" +dest_files=["res://.godot/imported/RJL_SequenceAction.svg-790e79bd878da76261dea54ce9c5ee0d.ctex"] [params] diff --git a/Icons/ActionSequence.svg b/Icons/Sequence.svg similarity index 100% rename from Icons/ActionSequence.svg rename to Icons/Sequence.svg diff --git a/Icons/ActionSequence.svg.import b/Icons/Sequence.svg.import similarity index 76% rename from Icons/ActionSequence.svg.import rename to Icons/Sequence.svg.import index c2a610f..2a9c6a6 100644 --- a/Icons/ActionSequence.svg.import +++ b/Icons/Sequence.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://c6lekbldg584j" -path="res://.godot/imported/ActionSequence.svg-ece8edf3a7454b70d9fbe1ac56623bab.ctex" +path="res://.godot/imported/Sequence.svg-a17b349c680e078faa6cea70148e2d23.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/rokojori_action_library/Icons/ActionSequence.svg" -dest_files=["res://.godot/imported/ActionSequence.svg-ece8edf3a7454b70d9fbe1ac56623bab.ctex"] +source_file="res://addons/rokojori_action_library/Icons/Sequence.svg" +dest_files=["res://.godot/imported/Sequence.svg-a17b349c680e078faa6cea70148e2d23.ctex"] [params] diff --git a/Runtime/Actions/Action.cs b/Runtime/Actions/Action.cs index 77eb37a..af365d1 100644 --- a/Runtime/Actions/Action.cs +++ b/Runtime/Actions/Action.cs @@ -1,7 +1,7 @@ using Godot; using System.Collections.Generic; - +using System.IO; namespace Rokojori; @@ -19,7 +19,7 @@ public partial class Action : NetworkNode [Export] public ActionTriggerMode triggerMode = ActionTriggerMode.Always; - #if !GD_SCRIPT_TRANSPILING + #if !ROKOJORI_ACTION_CORE [ExportToolButton( "(?) Help", Icon = "Help") ] public Callable openHelpButton => Callable.From( ()=> @@ -35,7 +35,7 @@ public partial class Action : NetworkNode [ExportToolButton( "Trigger Action in Editor")] public Callable TriggerActionButton => Callable.From( ()=> Trigger() ); - #if !GD_SCRIPT_TRANSPILING + #if !ROKOJORI_ACTION_CORE public static bool IsAction( Node n ) { @@ -51,12 +51,48 @@ public partial class Action : NetworkNode public void LogInfoFor( Node n, string message ) { + var className = GDScriptNames.ExtractClassName( n ); RJLog.GDLog( $"{className}._onTrigger()", n, message ); } #endif - + + static bool IsProcessingInHierarchy( Node n ) + { + if ( n.ProcessMode == ProcessModeEnum.Disabled ) + { + return false; + } + + if ( n.ProcessMode == Node.ProcessModeEnum.Always ) + { + return true; + } + + var paused = n.GetTree().Paused; + + if ( n.ProcessMode == Node.ProcessModeEnum.Pausable ) + { + return ! paused; + } + + if ( n.ProcessMode == Node.ProcessModeEnum.WhenPaused ) + { + return paused; + } + + var p = n.GetParent(); + + if ( p == null ) + { + return ! paused; + } + + return IsProcessingInHierarchy( p ); + + } + public void Trigger() { if ( ! IsInstanceValid( this ) ) @@ -64,12 +100,12 @@ public partial class Action : NetworkNode return; } - if ( triggerMode == ActionTriggerMode.Only_When_Processing_In_Hierarchy && ! this.IsProcessingInHierarchy() ) - { + if ( triggerMode == ActionTriggerMode.Only_When_Processing_In_Hierarchy && ! IsProcessingInHierarchy( this ) ) + { return; } - #if !GD_SCRIPT_TRANSPILING + #if !ROKOJORI_ACTION_CORE _isNetworkedTrigger = false; _sendsSeed = false; @@ -79,7 +115,7 @@ public partial class Action : NetworkNode _OnTrigger(); - #if !GD_SCRIPT_TRANSPILING + #if !ROKOJORI_ACTION_CORE SendOverNetwork(); @@ -92,7 +128,7 @@ public partial class Action : NetworkNode } - #if !GD_SCRIPT_TRANSPILING + #if !ROKOJORI_ACTION_CORE NetworkNodeSlot _seedSlot = new NetworkNodeSlot(); NetworkNodeSlot _dataSlot = new NetworkNodeSlot(); @@ -177,9 +213,10 @@ public partial class Action : NetworkNode return _sendingNetworkData; } + #endif - public static void Trigger( Action action ) + public static void TriggerSafe( Action action ) { if ( action == null ) { @@ -188,14 +225,14 @@ public partial class Action : NetworkNode action.Trigger(); } - - public static void TriggerAll( Action[] actions, Node target, bool triggerDirectChildren, Action caller = null ) + + public static void TriggerAllActions( Action[] actions, Node target, bool triggerDirectChildren, Action caller = null ) { if ( actions != null ) { for ( int i = 0; i < actions.Length; i++ ) { - Action.Trigger( actions[ i ] ); + Action.TriggerSafe( actions[ i ] ); } } @@ -204,14 +241,14 @@ public partial class Action : NetworkNode return; } - Nodes.ForEachDirectChild( target, ( a ) => Trigger( a ) ); + Nodes.ForEachDirectChild( target, ( a ) => TriggerSafe( a ) ); } public static void TriggerAll( Action action, Node target, bool triggerDirectChildren ) { if ( action != null ) { - Action.Trigger( action ); + Action.TriggerSafe( action ); } @@ -220,9 +257,9 @@ public partial class Action : NetworkNode return; } - Nodes.ForEachDirectChild( target, ( a ) => Trigger( a ) ); + Nodes.ForEachDirectChild( target, ( a ) => TriggerSafe( a ) ); } - #endif + } diff --git a/Runtime/Actions/ActionList.cs b/Runtime/Actions/ActionList.cs index ac65a53..4815d1e 100644 --- a/Runtime/Actions/ActionList.cs +++ b/Runtime/Actions/ActionList.cs @@ -25,7 +25,7 @@ namespace Rokojori public partial class ActionList : Action { - /** Actions to execute */ + /** Actions to execute */ [Export] public Action[] actions = new Action[ 0 ]; @@ -35,7 +35,7 @@ namespace Rokojori protected override void _OnTrigger() { - Action.TriggerAll( actions, this, triggerDirectChildren ); + Action.TriggerAllActions( actions, this, triggerDirectChildren ); } } } \ No newline at end of file diff --git a/Runtime/Actions/ActionReference.cs b/Runtime/Actions/ActionReference.cs index 574fe99..3c09989 100644 --- a/Runtime/Actions/ActionReference.cs +++ b/Runtime/Actions/ActionReference.cs @@ -27,7 +27,7 @@ namespace Rokojori protected override void _OnTrigger() { - Action.Trigger( referencedAction ); + Action.TriggerSafe( referencedAction ); } } diff --git a/Runtime/Actions/Conditional/ConditionalAction.cs b/Runtime/Actions/Conditional/ConditionalAction.cs index dcc273a..f3f528f 100644 --- a/Runtime/Actions/Conditional/ConditionalAction.cs +++ b/Runtime/Actions/Conditional/ConditionalAction.cs @@ -31,11 +31,11 @@ namespace Rokojori if ( conditionActive ) { - Trigger( ifAction ); + TriggerSafe( ifAction ); } else { - Trigger( elseAction ); + TriggerSafe( elseAction ); } } diff --git a/Runtime/Actions/Conditional/CoolDown.cs b/Runtime/Actions/Conditional/CoolDown.cs index a8577e2..8fba6e0 100644 --- a/Runtime/Actions/Conditional/CoolDown.cs +++ b/Runtime/Actions/Conditional/CoolDown.cs @@ -79,7 +79,7 @@ namespace Rokojori _canRelease = true; - Trigger( action ); + TriggerSafe( action ); RegisterCoolDown(); diff --git a/Runtime/Actions/Conditional/Once.cs b/Runtime/Actions/Conditional/Once.cs index de5c2c1..c1758e7 100644 --- a/Runtime/Actions/Conditional/Once.cs +++ b/Runtime/Actions/Conditional/Once.cs @@ -23,7 +23,7 @@ namespace Rokojori } canTrigger = false; - Action.Trigger( action ); + Action.TriggerSafe( action ); } } diff --git a/Runtime/Actions/GDScriptAction.cs b/Runtime/Actions/GDScriptAction.cs index cdf4ded..edf47e4 100644 --- a/Runtime/Actions/GDScriptAction.cs +++ b/Runtime/Actions/GDScriptAction.cs @@ -10,7 +10,7 @@ namespace Rokojori public partial class GDScriptAction : Action { public static string onTriggerFunctionName = "_onTrigger"; - public static string rjAction_className = "RJ_Action"; + public static string rjAction_className = "RJL_Action"; public static bool IsRJAction( Node n ) { diff --git a/Runtime/Actions/GDScriptSequenceAction.cs b/Runtime/Actions/GDScriptSequenceAction.cs index d81236b..6dff0bd 100644 --- a/Runtime/Actions/GDScriptSequenceAction.cs +++ b/Runtime/Actions/GDScriptSequenceAction.cs @@ -9,7 +9,7 @@ namespace Rokojori [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/GDScriptSequenceAction.svg")] public partial class GDScriptSequenceAction : SequenceAction { - public static string rjSequenceAction_className = "RJ_SequenceAction"; + public static string rjSequenceAction_className = "RJL_SequenceAction"; public static bool IsRJSequenceAction( Node n ) { diff --git a/Runtime/Actions/IterateActions.cs b/Runtime/Actions/IterateActions.cs index 1192fc3..9d0eb92 100644 --- a/Runtime/Actions/IterateActions.cs +++ b/Runtime/Actions/IterateActions.cs @@ -23,7 +23,7 @@ namespace Rokojori iterationIndex = MathX.Repeat( iterationIndex, num ); - Action.Trigger( this.GetNthDirectChild( iterationIndex ) ); + Action.TriggerSafe( this.GetNthDirectChild( iterationIndex ) ); iterationIndex++; } diff --git a/Runtime/Actions/LoadScene.cs b/Runtime/Actions/LoadScene.cs index 1d01cbf..110fb61 100644 --- a/Runtime/Actions/LoadScene.cs +++ b/Runtime/Actions/LoadScene.cs @@ -91,7 +91,7 @@ namespace Rokojori n3D.SetGlobalQuaternion( n3D.GlobalQuaternion() * offsetRotation ); } - Action.Trigger( onLoaded ); + Action.TriggerSafe( onLoaded ); _loadedNode = null; DispatchEnd( _id ); @@ -101,7 +101,7 @@ namespace Rokojori ( c )=> { target.AddChild( packedScene.Instantiate() ); - Action.Trigger( onLoaded ); + Action.TriggerSafe( onLoaded ); DispatchEnd( c ); } ); diff --git a/Runtime/Actions/RJLogMessage.cs b/Runtime/Actions/LogMessage.cs similarity index 82% rename from Runtime/Actions/RJLogMessage.cs rename to Runtime/Actions/LogMessage.cs index 3f19fa8..ebccdf3 100644 --- a/Runtime/Actions/RJLogMessage.cs +++ b/Runtime/Actions/LogMessage.cs @@ -6,7 +6,8 @@ namespace Rokojori { [Tool] [GlobalClass ] - public partial class RJLogMessage : Action + [RokojoriActionCoreExport] + public partial class LogMessage : Action { [Export] public string message; diff --git a/Runtime/Actions/RJLogMessage.cs.uid b/Runtime/Actions/LogMessage.cs.uid similarity index 100% rename from Runtime/Actions/RJLogMessage.cs.uid rename to Runtime/Actions/LogMessage.cs.uid diff --git a/Runtime/Actions/Node3D/OnCollision.cs b/Runtime/Actions/Node3D/OnCollision.cs index 65bf236..6a6d42e 100644 --- a/Runtime/Actions/Node3D/OnCollision.cs +++ b/Runtime/Actions/Node3D/OnCollision.cs @@ -85,7 +85,7 @@ namespace Rokojori // this.LogInfo( "Selecting Enter", area.GlobalPosition, HierarchyName.Of( n ), ( (Node3D)n ).GlobalPosition ); - Action.Trigger( onEntered ); + Action.TriggerSafe( onEntered ); onEnteredSlot.DispatchEvent( n ); if ( onInside == null ) @@ -102,7 +102,7 @@ namespace Rokojori var callback = ()=> { - Action.Trigger( onInside ); + Action.TriggerSafe( onInside ); onInsideSlot.DispatchEvent( n ); }; @@ -120,7 +120,7 @@ namespace Rokojori return; } - Action.Trigger( onExit ); + Action.TriggerSafe( onExit ); onExitSlot.DispatchEvent( n ); diff --git a/Runtime/Actions/OnPhysicsProcess.cs b/Runtime/Actions/OnPhysicsProcess.cs index 715522c..ddb1a0c 100644 --- a/Runtime/Actions/OnPhysicsProcess.cs +++ b/Runtime/Actions/OnPhysicsProcess.cs @@ -17,7 +17,7 @@ namespace Rokojori public override void _PhysicsProcess( double delta ) { - Action.TriggerAll( actions, this, triggerDirectChildren ); + Action.TriggerAllActions( actions, this, triggerDirectChildren ); } } } \ No newline at end of file diff --git a/Runtime/Actions/OnProcess.cs b/Runtime/Actions/OnProcess.cs index f453f21..7377c86 100644 --- a/Runtime/Actions/OnProcess.cs +++ b/Runtime/Actions/OnProcess.cs @@ -25,7 +25,7 @@ namespace Rokojori return; } - Action.TriggerAll( actions, this, triggerDirectChildren ); + Action.TriggerAllActions( actions, this, triggerDirectChildren ); } } } \ No newline at end of file diff --git a/Runtime/Actions/OnReady.cs b/Runtime/Actions/OnReady.cs index 036e206..f58b6a5 100644 --- a/Runtime/Actions/OnReady.cs +++ b/Runtime/Actions/OnReady.cs @@ -25,7 +25,7 @@ namespace Rokojori return; } - Action.TriggerAll( actions, this, triggerDirectChildren ); + Action.TriggerAllActions( actions, this, triggerDirectChildren ); } } } \ No newline at end of file diff --git a/Runtime/Actions/OnTick.cs b/Runtime/Actions/OnTick.cs index ac2acec..9e3ea04 100644 --- a/Runtime/Actions/OnTick.cs +++ b/Runtime/Actions/OnTick.cs @@ -69,7 +69,7 @@ namespace Rokojori TimeLineManager.RemoveEvent( timeLine, _eventID ); } - var tle = TimeLineManager.ScheduleLoopEvent( timeLine, duration, offset, tle => Action.Trigger( action ) ); + var tle = TimeLineManager.ScheduleLoopEvent( timeLine, duration, offset, tle => Action.TriggerSafe( action ) ); _eventID = tle.id; } diff --git a/Runtime/Actions/RJ_Action.gd b/Runtime/Actions/RJ_Action.gd deleted file mode 100644 index ca73e3e..0000000 --- a/Runtime/Actions/RJ_Action.gd +++ /dev/null @@ -1,23 +0,0 @@ - -@tool -@icon("res://addons/rokojori_action_library/Icons/Action.svg") -class_name RJ_Action extends RJ_NetworkNode - -enum ActionTriggerMode -{ - Only_When_Processing_In_Hierarchy, - Always -} - -@export -var trigger_mode: ActionTriggerMode; - -func trigger() -> void: - pass -## --- - - -func _on_trigger() -> void: - pass -## --- - diff --git a/Runtime/Actions/RJ_Action.gd.uid b/Runtime/Actions/RJ_Action.gd.uid deleted file mode 100644 index c952971..0000000 --- a/Runtime/Actions/RJ_Action.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dcqjcsh20ndon diff --git a/Runtime/Actions/RJ_ActionList.gd b/Runtime/Actions/RJ_ActionList.gd deleted file mode 100644 index 8fabcdc..0000000 --- a/Runtime/Actions/RJ_ActionList.gd +++ /dev/null @@ -1,14 +0,0 @@ - -@tool -@icon("res://addons/rokojori_action_library/Icons/ActionList.svg") -class_name RJ_ActionList extends RJ_Action - -@export -var actions: Action[]; -@export -var trigger_direct_children: bool; - -func _on_trigger() -> void: - pass -## --- - diff --git a/Runtime/Actions/RJ_ActionList.gd.uid b/Runtime/Actions/RJ_ActionList.gd.uid deleted file mode 100644 index 221e527..0000000 --- a/Runtime/Actions/RJ_ActionList.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ctnc7tsiwxp3j diff --git a/Runtime/Actions/Sequence/Parallel.cs b/Runtime/Actions/Sequence/Parallel.cs index 2c7f7cb..337eac7 100644 --- a/Runtime/Actions/Sequence/Parallel.cs +++ b/Runtime/Actions/Sequence/Parallel.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace Rokojori { [Tool][GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Parallel.svg") ] + [RokojoriActionCoreExport] public partial class Parallel : SequenceAction { public enum Mode @@ -46,7 +47,7 @@ namespace Rokojori if ( ! ignoreNonSequenceActions && sequenceActions.Count != actions.Count && Mode.First_Finishes_Sequence == mode ) { - actions.ForEach( a => Action.Trigger( a ) ); + actions.ForEach( a => Action.TriggerSafe( a ) ); DispatchEnd( sequenceID ); return; } @@ -100,7 +101,7 @@ namespace Rokojori } ); - actions.ForEach( a => Action.Trigger( a ) ); + actions.ForEach( a => Action.TriggerSafe( a ) ); } } } \ No newline at end of file diff --git a/Runtime/Actions/Sequence/RepeatSequence.cs b/Runtime/Actions/Sequence/RepeatSequence.cs index 5084821..ead825e 100644 --- a/Runtime/Actions/Sequence/RepeatSequence.cs +++ b/Runtime/Actions/Sequence/RepeatSequence.cs @@ -38,7 +38,7 @@ namespace Rokojori if ( ! ( action is SequenceAction ) ) { - Trigger( action ); + TriggerSafe( action ); DispatchEnd( id ); return; } diff --git a/Runtime/Actions/Sequence/Sequence.cs b/Runtime/Actions/Sequence/Sequence.cs new file mode 100644 index 0000000..b6e6cfb --- /dev/null +++ b/Runtime/Actions/Sequence/Sequence.cs @@ -0,0 +1,254 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + + // public class SequenceRunner + // { + // public Sequence sequence; + // public List actions; + // public List sequencables; + // public int sequencablesIndex = 0; + // bool cancelled = false; + // bool cancelledSequence = false; + + + // int _runID = -1; + + // SequenceAction _runningAction; + // int _runningActionID = -1; + + // public void Cancel() + // { + // if ( cancelled || _runningAction == null ) + // { + // return; + // } + + // cancelled = true; + // _runningAction.CancelAction( _runningActionID ); + // } + + // void CancelRun() + // { + // if ( cancelledSequence ) + // { + // return; + // } + + // if ( ! cancelled ) + // { + // cancelled = true; + // } + + // cancelledSequence = true; + // sequence.DispatchCancelled( _runID ); + // sequence.ClearRun( this ); + // } + + + // public void ProcessNext() + // { + // // RJLog.Log( "@" + sequence.Name, "Index:", sequencablesIndex ); + + // if ( sequencablesIndex == 0 ) + // { + // _runID = sequence.DispatchStart(); + + // if ( sequencables.Count == 0 ) + // { + // actions.ForEach( a => Action.TriggerSafe( a ) ); + // sequence.DispatchEnd( _runID ); + // sequence.ClearRun( this ); + // return; + // } + // } + + // if ( sequencablesIndex >= sequencables.Count ) + // { + // TriggerAllAfter( sequencables[ sequencables.Count -1 ] ); + // sequence.DispatchEnd( _runID ); + // sequence.ClearRun( this ); + // return; + // } + + // if ( cancelled ) + // { + // CancelRun(); + // return; + // } + + + // var sequenceAction = sequencables[ sequencablesIndex ]; + // StartAction( sequenceAction ); + // } + + // Dictionary> callbacks = + // new Dictionary>(); + + // void StartAction( SequenceAction action ) + // { + // var capturedAction = action; + + // System.Action callback = + // ( SequenceAction.FinishedEvent ev ) => + // { + + + // //RJLog.Log( "On Done", id, success ); + + // if ( ev.id != _runningActionID ) + // { + // // RJLog.Error( "Invalid ID", id, "!=", _runningActionID ); + // return; + // } + + // _runningActionID = -1; + + // if ( ev.success ) + // { + // sequencablesIndex ++; + // ProcessNext(); + // } + // else + // { + // sequence.DispatchCancelled( _runID ); + // sequence.ClearRun( this ); + // } + + // var callbackReference = callbacks[ capturedAction ]; + // capturedAction.onSequenceDone.RemoveAction( callbackReference ); + + // callbacks.Remove( capturedAction ); + // }; + + // RunNext( action, callback ); + + // /* + // _runningAction = action; + // callbacks[ _runningAction ] = callback; + // _runningAction.OnSequenceDone += callback; + // TriggerAllBefore( _runningAction ); + // Action.Trigger( _runningAction ); + // _runningActionID = _runningAction.GetLastSequenceActionID(); + // */ + // } + + // void RunNext( SequenceAction action, System.Action callback ) + // { + // _runningAction = action; + // callbacks[ _runningAction ] = callback; + // _runningAction.onSequenceDone.AddAction( callback ); + + + // TriggerAllBefore( _runningAction ); + // Action.TriggerSafe( _runningAction ); + // _runningActionID = _runningAction.GetLastSequenceActionID(); + // } + + // void TriggerAllBefore( SequenceAction action ) + // { + // var actionIndex = actions.IndexOf( action ); + + // for ( int i = actionIndex - 1; i >= 0; i -- ) + // { + // if ( typeof( SequenceAction ).IsAssignableFrom( actions[ i ].GetType() ) ) + // { + // return; + // } + + // // RJLog.Log( _runID, "Triggering Actions Before", i, actions[ i ].Name, HierarchyName.Of( action ) ); + + // Action.TriggerSafe( actions[ i ] ); + // } + + // } + + // void TriggerAllAfter( SequenceAction action ) + // { + // var actionIndex = actions.IndexOf( action ); + + // for ( int i = actionIndex + 1; i < actions.Count; i ++ ) + // { + // if ( typeof( SequenceAction ).IsAssignableFrom( actions[ i ].GetType() ) ) + // { + // return; + // } + + // // RJLog.Log( "Triggering Action", actions[ i ].Name ); + // Action.TriggerSafe( actions[ i ] ); + // } + + // } + + + // } + + + [Tool] + [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Sequence.svg") ] + [RokojoriActionCoreExport] + public partial class Sequence:SequenceAction + { + /** Actions to execute*/ + [Export] + public Action[] actions = new Action[ 0 ]; + + [Export] + public bool triggerDirectChildren = true; + + List running = new List(); + + [Export] + public bool noOverlays = false; + + protected override void _OnTrigger() + { + if ( noOverlays && running.Count > 0 ) + { + return; + } + + // this.LogInfo( "Running" ); + + + var run = new SequenceRunner(); + run.sequence = this; + run.actions = new List( actions ); + + if ( triggerDirectChildren ) + { + Nodes.ForEachDirectChild( this, a => run.actions.Add( a ) ); + } + + run.sequencables = Lists.FilterType( run.actions ); + + + + + // RJLog.Log( "Running", HierarchyName.Of( this ), run.sequencables.Count ); + running.Add( run ); + run.ProcessNext(); + } + + public override void CancelAction( int id ) + { + running.ForEach( r => r.Cancel() ); + } + + public void ClearRun( SequenceRunner run ) + { + running.Remove( run ); + } + + } + + + +} \ No newline at end of file diff --git a/Runtime/Actions/ActionSequence.cs.uid b/Runtime/Actions/Sequence/Sequence.cs.uid similarity index 100% rename from Runtime/Actions/ActionSequence.cs.uid rename to Runtime/Actions/Sequence/Sequence.cs.uid diff --git a/Runtime/Actions/SequenceAction.cs b/Runtime/Actions/Sequence/SequenceAction.cs similarity index 83% rename from Runtime/Actions/SequenceAction.cs rename to Runtime/Actions/Sequence/SequenceAction.cs index d594d08..8c62da0 100644 --- a/Runtime/Actions/SequenceAction.cs +++ b/Runtime/Actions/Sequence/SequenceAction.cs @@ -4,19 +4,19 @@ using System.Collections.Generic; using System.Linq; namespace Rokojori -{ +{ - public class SequenceActionFinishedEvent - { - public int id; - public bool success; - } - [Tool] [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/SequenceAction.svg")] + [RokojoriActionCoreExport] public abstract partial class SequenceAction : Action { - + public class FinishedEvent + { + public int id; + public bool success; + } + [ExportGroup("Debugging")] [ExportToolButton("Clear Listeners")] public Callable clearListeners => Callable.From( @@ -41,7 +41,7 @@ namespace Rokojori return _dispatchCounter; } - public readonly EventSlot onSequenceDone = new EventSlot(); + public readonly EventSlot onSequenceDone = new EventSlot(); public int DispatchStart() { @@ -61,7 +61,7 @@ namespace Rokojori { _running.Remove( id ); - var ev = new SequenceActionFinishedEvent{ id = id, success = true }; + var ev = new SequenceAction.FinishedEvent{ id = id, success = true }; onSequenceDone.DispatchEvent( ev ); if ( showRunningSequences ) @@ -76,7 +76,7 @@ namespace Rokojori { _running.Remove( id ); - var ev = new SequenceActionFinishedEvent{ id = id, success = true }; + var ev = new SequenceAction.FinishedEvent{ id = id, success = true }; onSequenceDone.DispatchEvent( ev ); if ( showRunningSequences ) diff --git a/Runtime/Actions/SequenceAction.cs.uid b/Runtime/Actions/Sequence/SequenceAction.cs.uid similarity index 100% rename from Runtime/Actions/SequenceAction.cs.uid rename to Runtime/Actions/Sequence/SequenceAction.cs.uid diff --git a/Runtime/Actions/Sequence/SequenceActionReference.cs b/Runtime/Actions/Sequence/SequenceActionReference.cs index 26f1b20..ccfd189 100644 --- a/Runtime/Actions/Sequence/SequenceActionReference.cs +++ b/Runtime/Actions/Sequence/SequenceActionReference.cs @@ -35,7 +35,7 @@ namespace Rokojori var ownID = DispatchStart(); var referenceID = -1; - System.Action callback = ( se )=> + System.Action callback = ( se )=> { if ( se.id != referenceID ) { diff --git a/Runtime/Actions/ActionSequence.cs b/Runtime/Actions/Sequence/SequenceRunner.cs similarity index 67% rename from Runtime/Actions/ActionSequence.cs rename to Runtime/Actions/Sequence/SequenceRunner.cs index c244722..6befde1 100644 --- a/Runtime/Actions/ActionSequence.cs +++ b/Runtime/Actions/Sequence/SequenceRunner.cs @@ -8,9 +8,9 @@ using Godot; namespace Rokojori { - public class ActionSequenceRunner + public class SequenceRunner { - public ActionSequence sequence; + public Sequence sequence; public List actions; public List sequencables; public int sequencablesIndex = 0; @@ -62,7 +62,7 @@ namespace Rokojori if ( sequencables.Count == 0 ) { - actions.ForEach( a => Action.Trigger( a ) ); + actions.ForEach( a => Action.TriggerSafe( a ) ); sequence.DispatchEnd( _runID ); sequence.ClearRun( this ); return; @@ -88,15 +88,15 @@ namespace Rokojori StartAction( sequenceAction ); } - Dictionary> callbacks = - new Dictionary>(); + Dictionary> callbacks = + new Dictionary>(); void StartAction( SequenceAction action ) { var capturedAction = action; - System.Action callback = - ( SequenceActionFinishedEvent ev ) => + System.Action callback = + ( SequenceAction.FinishedEvent ev ) => { @@ -139,7 +139,7 @@ namespace Rokojori */ } - void RunNext( SequenceAction action, System.Action callback ) + void RunNext( SequenceAction action, System.Action callback ) { _runningAction = action; callbacks[ _runningAction ] = callback; @@ -147,7 +147,7 @@ namespace Rokojori TriggerAllBefore( _runningAction ); - Action.Trigger( _runningAction ); + Action.TriggerSafe( _runningAction ); _runningActionID = _runningAction.GetLastSequenceActionID(); } @@ -164,7 +164,7 @@ namespace Rokojori // RJLog.Log( _runID, "Triggering Actions Before", i, actions[ i ].Name, HierarchyName.Of( action ) ); - Action.Trigger( actions[ i ] ); + Action.TriggerSafe( actions[ i ] ); } } @@ -181,71 +181,12 @@ namespace Rokojori } // RJLog.Log( "Triggering Action", actions[ i ].Name ); - Action.Trigger( actions[ i ] ); + Action.TriggerSafe( actions[ i ] ); } } - } - - [Tool] - [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/ActionSequence.svg") ] - public partial class ActionSequence:SequenceAction - { - /** Actions to execute*/ - [Export] - public Action[] actions = new Action[ 0 ]; - - [Export] - public bool triggerDirectChildren = true; - - List running = new List(); - - [Export] - public bool noOverlays = false; - - protected override void _OnTrigger() - { - if ( noOverlays && running.Count > 0 ) - { - return; - } - - // this.LogInfo( "Running" ); - - - var run = new ActionSequenceRunner(); - run.sequence = this; - run.actions = new List( actions ); - - if ( triggerDirectChildren ) - { - Nodes.ForEachDirectChild( this, a => run.actions.Add( a ) ); - } - - run.sequencables = Lists.FilterType( run.actions ); - - - - - // RJLog.Log( "Running", HierarchyName.Of( this ), run.sequencables.Count ); - running.Add( run ); - run.ProcessNext(); - } - - public override void CancelAction( int id ) - { - running.ForEach( r => r.Cancel() ); - } - - public void ClearRun( ActionSequenceRunner run ) - { - running.Remove( run ); - } - - } - - + } } \ No newline at end of file diff --git a/Runtime/Actions/Sequence/SequenceRunner.cs.uid b/Runtime/Actions/Sequence/SequenceRunner.cs.uid new file mode 100644 index 0000000..4f3dc31 --- /dev/null +++ b/Runtime/Actions/Sequence/SequenceRunner.cs.uid @@ -0,0 +1 @@ +uid://d0syxcyude3he diff --git a/Runtime/Actions/SetPauseState.cs b/Runtime/Actions/SetPauseState.cs index 2b72d7c..81dc082 100644 --- a/Runtime/Actions/SetPauseState.cs +++ b/Runtime/Actions/SetPauseState.cs @@ -48,11 +48,11 @@ namespace Rokojori if ( nextIsPaused ) { - Action.Trigger( onPausing ); + Action.TriggerSafe( onPausing ); } else { - Action.Trigger( onResuming ); + Action.TriggerSafe( onResuming ); } } diff --git a/Runtime/Actions/Time/DelayedList.cs b/Runtime/Actions/Time/DelayedList.cs index c14c2de..b2a3714 100644 --- a/Runtime/Actions/Time/DelayedList.cs +++ b/Runtime/Actions/Time/DelayedList.cs @@ -44,7 +44,7 @@ namespace Rokojori TimeLineManager.ScheduleEventIn( timeLine, offset, id => { - Action.Trigger( list[ i ] ); + Action.TriggerSafe( list[ i ] ); } ); diff --git a/Runtime/Actions/Time/Repeat.cs b/Runtime/Actions/Time/Repeat.cs index 68cacc9..ff77475 100644 --- a/Runtime/Actions/Time/Repeat.cs +++ b/Runtime/Actions/Time/Repeat.cs @@ -37,14 +37,14 @@ namespace Rokojori { if ( i == 0 ) { - Action.Trigger( onBeforeFirst ); + Action.TriggerSafe( onBeforeFirst ); } - Action.Trigger( action ); + Action.TriggerSafe( action ); if ( i == ( numRepeats - 1 ) ) { - Action.Trigger( onAfterLast ); + Action.TriggerSafe( onAfterLast ); } }, this diff --git a/Runtime/Actions/TriggerActionInEditor.cs b/Runtime/Actions/TriggerActionInEditor.cs index 046acd3..03ddc93 100644 --- a/Runtime/Actions/TriggerActionInEditor.cs +++ b/Runtime/Actions/TriggerActionInEditor.cs @@ -12,7 +12,7 @@ namespace Rokojori public Action action; [ExportToolButton( "Trigger")] - public Callable ExecuteButton => Callable.From( () => Action.Trigger( action ) ); + public Callable ExecuteButton => Callable.From( () => Action.TriggerSafe( action ) ); } } \ No newline at end of file diff --git a/Runtime/Events/EventSlot.cs b/Runtime/Events/EventSlot.cs index 71d8cda..989ea0a 100644 --- a/Runtime/Events/EventSlot.cs +++ b/Runtime/Events/EventSlot.cs @@ -55,7 +55,7 @@ namespace Rokojori { if ( _canModify ) { - var removed = _actions.Remove( action ); + _actions.Remove( action ); // RJLog.Log( "Removed:", action, removed ); } diff --git a/Runtime/Files/FilePath.cs b/Runtime/Files/FilePath.cs index 4bd760b..724c888 100644 --- a/Runtime/Files/FilePath.cs +++ b/Runtime/Files/FilePath.cs @@ -190,6 +190,11 @@ namespace Rokojori return ChangeFileName( fileName + fileNameAddition ); } + public FilePath PrependToFileName( string fileNamePrepending ) + { + return ChangeFileName( fileNamePrepending + fileName ); + } + public static FilePath Absolute( string path ) { return FilePath.Create( path, FilePathType.Absolute ); diff --git a/Runtime/Files/FilesSync.cs b/Runtime/Files/FilesSync.cs index 4239253..0db62a6 100644 --- a/Runtime/Files/FilesSync.cs +++ b/Runtime/Files/FilesSync.cs @@ -4,11 +4,24 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; namespace Rokojori { public class FilesSync { + public static void CopyTo( string fromPath, string toPath, bool overwrite = true ) + { + string? destinationDirectory = Path.GetDirectoryName( toPath ); + + if ( ! string.IsNullOrEmpty( destinationDirectory ) && ! Directory.Exists( destinationDirectory ) ) + { + Directory.CreateDirectory( destinationDirectory ); + } + + File.Copy( fromPath, toPath, overwrite ); + } + public static void Move( string fromPath, string toPath ) { string? destinationDirectory = Path.GetDirectoryName( toPath ); @@ -21,6 +34,65 @@ namespace Rokojori File.Move( fromPath, toPath ); } + public static void DeleteExcept( string rootPath, List selectedPaths ) + { + if ( string.IsNullOrWhiteSpace( rootPath ) || ! Directory.Exists( rootPath ) ) + { + RJLog.Error( "Invalid root path:", rootPath ); + return; + } + + var normalizedSelectedPaths = selectedPaths + .Select(p => Path.GetFullPath( p.TrimEnd( Path.DirectorySeparatorChar ) ) ) + .ToList(); + + string normalizedRoot = Path.GetFullPath( rootPath ); + + ProcessDirectory( normalizedRoot, normalizedSelectedPaths ); + } + + static void ProcessDirectory(string currentDir, List selectedPaths) + { + if ( IsSelectedOrInsideSelected( currentDir, selectedPaths ) ) + { + return; + } + + foreach ( var file in Directory.GetFiles( currentDir ) ) + { + if ( ! IsSelectedOrInsideSelected( file, selectedPaths ) ) + { + File.SetAttributes( file, FileAttributes.Normal ); + File.Delete( file ); + } + } + + foreach ( var dir in Directory.GetDirectories( currentDir ) ) + { + if ( IsSelectedOrInsideSelected(dir, selectedPaths ) ) + { + continue; + } + + ProcessDirectory(dir, selectedPaths); + + if ( Directory.Exists( dir ) && ! Directory.EnumerateFileSystemEntries( dir ).Any() ) + { + Directory.Delete(dir); + } + } + } + + static bool IsSelectedOrInsideSelected(string path, List selectedPaths) + { + string normalizedPath = Path.GetFullPath( path.TrimEnd( Path.DirectorySeparatorChar ) ); + + return selectedPaths.Any( selected => + normalizedPath.Equals( selected, StringComparison.OrdinalIgnoreCase ) || + normalizedPath.StartsWith( selected + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase ) + ); + } + public static void Delete( string path ) { if ( string.IsNullOrWhiteSpace( path ) ) diff --git a/Runtime/GDScript/Core/RJ_Action.gd b/Runtime/GDScript/Core/RJL_Action.gd similarity index 76% rename from Runtime/GDScript/Core/RJ_Action.gd rename to Runtime/GDScript/Core/RJL_Action.gd index 94b6ee3..6dacc0c 100644 --- a/Runtime/GDScript/Core/RJ_Action.gd +++ b/Runtime/GDScript/Core/RJL_Action.gd @@ -1,6 +1,6 @@ @tool -@icon("res://addons/rokojori_action_library/Icons/RJ_Action.svg") -@abstract class_name RJ_Action extends Node +@icon("res://addons/rokojori_action_library/Icons/RJL_Action.svg") +@abstract class_name RJL_Action extends Node @export_tool_button( "Create Wrapper" ) var createWrapperAction = _createWrapper; diff --git a/Runtime/GDScript/Core/RJ_Action.gd.uid b/Runtime/GDScript/Core/RJL_Action.gd.uid similarity index 100% rename from Runtime/GDScript/Core/RJ_Action.gd.uid rename to Runtime/GDScript/Core/RJL_Action.gd.uid diff --git a/Runtime/GDScript/Core/RJ_SequenceAction.gd b/Runtime/GDScript/Core/RJL_SequenceAction.gd similarity index 75% rename from Runtime/GDScript/Core/RJ_SequenceAction.gd rename to Runtime/GDScript/Core/RJL_SequenceAction.gd index cc9e979..d92094f 100644 --- a/Runtime/GDScript/Core/RJ_SequenceAction.gd +++ b/Runtime/GDScript/Core/RJL_SequenceAction.gd @@ -1,6 +1,6 @@ @tool -@icon("res://addons/rokojori_action_library/Icons/RJ_SequenceAction.svg") -@abstract class_name RJ_SequenceAction extends Node +@icon("res://addons/rokojori_action_library/Icons/RJL_SequenceAction.svg") +@abstract class_name RJL_SequenceAction extends Node @export_tool_button( "Create Wrapper" ) var createWrapperAction = _createWrapper diff --git a/Runtime/GDScript/Core/RJ_SequenceAction.gd.uid b/Runtime/GDScript/Core/RJL_SequenceAction.gd.uid similarity index 100% rename from Runtime/GDScript/Core/RJ_SequenceAction.gd.uid rename to Runtime/GDScript/Core/RJL_SequenceAction.gd.uid diff --git a/Runtime/Godot/Generated/Classes/RJAnimatableBody3D.cs b/Runtime/Godot/Generated/Classes/RJAnimatableBody3D.cs index 4d45c19..9d44a24 100644 --- a/Runtime/Godot/Generated/Classes/RJAnimatableBody3D.cs +++ b/Runtime/Godot/Generated/Classes/RJAnimatableBody3D.cs @@ -58,22 +58,22 @@ namespace Rokojori public override void _Ready() { - InputEvent += ( p0, p1, p2, p3, p4 ) => { Action.Trigger( OnInputEvent ); }; - MouseEntered += ( ) => { Action.Trigger( OnMouseEntered ); }; - MouseExited += ( ) => { Action.Trigger( OnMouseExited ); }; - VisibilityChanged += ( ) => { Action.Trigger( OnVisibilityChanged ); }; - Ready += ( ) => { Action.Trigger( OnReady ); }; - Renamed += ( ) => { Action.Trigger( OnRenamed ); }; - TreeEntered += ( ) => { Action.Trigger( OnTreeEntered ); }; - TreeExiting += ( ) => { Action.Trigger( OnTreeExiting ); }; - TreeExited += ( ) => { Action.Trigger( OnTreeExited ); }; - ChildEnteredTree += ( p0 ) => { Action.Trigger( OnChildEnteredTree ); }; - ChildExitingTree += ( p0 ) => { Action.Trigger( OnChildExitingTree ); }; - ChildOrderChanged += ( ) => { Action.Trigger( OnChildOrderChanged ); }; - ReplacingBy += ( p0 ) => { Action.Trigger( OnReplacingBy ); }; - EditorDescriptionChanged += ( p0 ) => { Action.Trigger( OnEditorDescriptionChanged ); }; - ScriptChanged += ( ) => { Action.Trigger( OnScriptChanged ); }; - PropertyListChanged += ( ) => { Action.Trigger( OnPropertyListChanged ); }; + InputEvent += ( p0, p1, p2, p3, p4 ) => { Action.TriggerSafe( OnInputEvent ); }; + MouseEntered += ( ) => { Action.TriggerSafe( OnMouseEntered ); }; + MouseExited += ( ) => { Action.TriggerSafe( OnMouseExited ); }; + VisibilityChanged += ( ) => { Action.TriggerSafe( OnVisibilityChanged ); }; + Ready += ( ) => { Action.TriggerSafe( OnReady ); }; + Renamed += ( ) => { Action.TriggerSafe( OnRenamed ); }; + TreeEntered += ( ) => { Action.TriggerSafe( OnTreeEntered ); }; + TreeExiting += ( ) => { Action.TriggerSafe( OnTreeExiting ); }; + TreeExited += ( ) => { Action.TriggerSafe( OnTreeExited ); }; + ChildEnteredTree += ( p0 ) => { Action.TriggerSafe( OnChildEnteredTree ); }; + ChildExitingTree += ( p0 ) => { Action.TriggerSafe( OnChildExitingTree ); }; + ChildOrderChanged += ( ) => { Action.TriggerSafe( OnChildOrderChanged ); }; + ReplacingBy += ( p0 ) => { Action.TriggerSafe( OnReplacingBy ); }; + EditorDescriptionChanged += ( p0 ) => { Action.TriggerSafe( OnEditorDescriptionChanged ); }; + ScriptChanged += ( ) => { Action.TriggerSafe( OnScriptChanged ); }; + PropertyListChanged += ( ) => { Action.TriggerSafe( OnPropertyListChanged ); }; } } } diff --git a/Runtime/Godot/Generated/Classes/RJCharacterBody3D.cs b/Runtime/Godot/Generated/Classes/RJCharacterBody3D.cs index 2e2c140..3023887 100644 --- a/Runtime/Godot/Generated/Classes/RJCharacterBody3D.cs +++ b/Runtime/Godot/Generated/Classes/RJCharacterBody3D.cs @@ -58,22 +58,22 @@ namespace Rokojori public override void _Ready() { - InputEvent += ( p0, p1, p2, p3, p4 ) => { Action.Trigger( OnInputEvent ); }; - MouseEntered += ( ) => { Action.Trigger( OnMouseEntered ); }; - MouseExited += ( ) => { Action.Trigger( OnMouseExited ); }; - VisibilityChanged += ( ) => { Action.Trigger( OnVisibilityChanged ); }; - Ready += ( ) => { Action.Trigger( OnReady ); }; - Renamed += ( ) => { Action.Trigger( OnRenamed ); }; - TreeEntered += ( ) => { Action.Trigger( OnTreeEntered ); }; - TreeExiting += ( ) => { Action.Trigger( OnTreeExiting ); }; - TreeExited += ( ) => { Action.Trigger( OnTreeExited ); }; - ChildEnteredTree += ( p0 ) => { Action.Trigger( OnChildEnteredTree ); }; - ChildExitingTree += ( p0 ) => { Action.Trigger( OnChildExitingTree ); }; - ChildOrderChanged += ( ) => { Action.Trigger( OnChildOrderChanged ); }; - ReplacingBy += ( p0 ) => { Action.Trigger( OnReplacingBy ); }; - EditorDescriptionChanged += ( p0 ) => { Action.Trigger( OnEditorDescriptionChanged ); }; - ScriptChanged += ( ) => { Action.Trigger( OnScriptChanged ); }; - PropertyListChanged += ( ) => { Action.Trigger( OnPropertyListChanged ); }; + InputEvent += ( p0, p1, p2, p3, p4 ) => { Action.TriggerSafe( OnInputEvent ); }; + MouseEntered += ( ) => { Action.TriggerSafe( OnMouseEntered ); }; + MouseExited += ( ) => { Action.TriggerSafe( OnMouseExited ); }; + VisibilityChanged += ( ) => { Action.TriggerSafe( OnVisibilityChanged ); }; + Ready += ( ) => { Action.TriggerSafe( OnReady ); }; + Renamed += ( ) => { Action.TriggerSafe( OnRenamed ); }; + TreeEntered += ( ) => { Action.TriggerSafe( OnTreeEntered ); }; + TreeExiting += ( ) => { Action.TriggerSafe( OnTreeExiting ); }; + TreeExited += ( ) => { Action.TriggerSafe( OnTreeExited ); }; + ChildEnteredTree += ( p0 ) => { Action.TriggerSafe( OnChildEnteredTree ); }; + ChildExitingTree += ( p0 ) => { Action.TriggerSafe( OnChildExitingTree ); }; + ChildOrderChanged += ( ) => { Action.TriggerSafe( OnChildOrderChanged ); }; + ReplacingBy += ( p0 ) => { Action.TriggerSafe( OnReplacingBy ); }; + EditorDescriptionChanged += ( p0 ) => { Action.TriggerSafe( OnEditorDescriptionChanged ); }; + ScriptChanged += ( ) => { Action.TriggerSafe( OnScriptChanged ); }; + PropertyListChanged += ( ) => { Action.TriggerSafe( OnPropertyListChanged ); }; } } } diff --git a/Runtime/Godot/Nodes.cs b/Runtime/Godot/Nodes.cs index 16ad5ce..ba5e2b2 100644 --- a/Runtime/Godot/Nodes.cs +++ b/Runtime/Godot/Nodes.cs @@ -10,6 +10,68 @@ namespace Rokojori { public static class Nodes { + public static void ForEachDirectChild( this Node parent, System.Action action ) where T:Node + { + if ( parent == null || action == null ) + { + return; + } + + var numChildren = parent.GetChildCount(); + + for ( int i = 0; i < numChildren; i++ ) + { + var node = parent.GetChild( i ); + + if ( ! ( node is T ) ) + { + continue; + } + + action( node as T ); + } + } + + public static void ForEachDirectChildSelected( this Node parent, Predicate selector, Action action ) + { + if ( parent == null || action == null ) + { + return; + } + + var numChildren = parent.GetChildCount(); + + for ( int i = 0; i < numChildren; i++ ) + { + var node = parent.GetChild( i ); + + if ( ! selector( node ) ) + { + continue; + } + + action( node ); + } + } + + public static void LogInfo( this Node node, params object[] messages ) + { + RJLog.Log( node, messages ); + } + + public static void LogError( this Node node, params object[] messages ) + { + RJLog.Error( node, messages ); + } + + + #if !ROKOJORI_ACTION_CORE + + public static void LogInfo( this Resource resource, params object[] messages ) + { + RJLog.Log( resource, messages ); + } + public static NodePath GetNodePath( this Node node ) { @@ -494,20 +556,7 @@ namespace Rokojori return copy; } - public static void LogInfo( this Node node, params object[] messages ) - { - RJLog.Log( node, messages ); - } - - public static void LogError( this Node node, params object[] messages ) - { - RJLog.Error( node, messages ); - } - - public static void LogInfo( this Resource resource, params object[] messages ) - { - RJLog.Log( resource, messages ); - } + public static void LogInfoIf( this Resource resource, bool condition, params object[] messages ) { @@ -989,49 +1038,7 @@ namespace Rokojori } - public static void ForEachDirectChild( this Node parent, System.Action action ) where T:Node - { - if ( parent == null || action == null ) - { - return; - } - - var numChildren = parent.GetChildCount(); - - for ( int i = 0; i < numChildren; i++ ) - { - var node = parent.GetChild( i ); - - if ( ! ( node is T ) ) - { - continue; - } - - action( node as T ); - } - } - - public static void ForEachDirectChild( this Node parent, Predicate selector, Action action ) - { - if ( parent == null || action == null ) - { - return; - } - - var numChildren = parent.GetChildCount(); - - for ( int i = 0; i < numChildren; i++ ) - { - var node = parent.GetChild( i ); - - if ( ! selector( node ) ) - { - continue; - } - - action( node ); - } - } + public static List MapDirectChildren( Node parent, System.Func mapper ) where T:Node { @@ -1122,6 +1129,8 @@ namespace Rokojori } } + #endif + } diff --git a/Runtime/Interactions/CharacterController/CharacterController.cs b/Runtime/Interactions/CharacterController/CharacterController.cs index fbb4e60..2ae7b35 100644 --- a/Runtime/Interactions/CharacterController/CharacterController.cs +++ b/Runtime/Interactions/CharacterController/CharacterController.cs @@ -134,7 +134,7 @@ namespace Rokojori c.SetCharacterController( this ); - Action.Trigger( c ); + Action.TriggerSafe( c ); } ); diff --git a/Runtime/Interactions/CharacterController/CharacterMovement.cs b/Runtime/Interactions/CharacterController/CharacterMovement.cs index 74c4e4b..861e020 100644 --- a/Runtime/Interactions/CharacterController/CharacterMovement.cs +++ b/Runtime/Interactions/CharacterController/CharacterMovement.cs @@ -198,11 +198,11 @@ namespace Rokojori { if ( _moving ) { - Trigger( onStartedMoving ); + TriggerSafe( onStartedMoving ); } else { - Trigger( onStoppedMoving ); + TriggerSafe( onStoppedMoving ); } } diff --git a/Runtime/Interactions/CharacterController/Jump.cs b/Runtime/Interactions/CharacterController/Jump.cs index 6f47d6c..f020a57 100644 --- a/Runtime/Interactions/CharacterController/Jump.cs +++ b/Runtime/Interactions/CharacterController/Jump.cs @@ -110,7 +110,7 @@ namespace Rokojori jumping = true; jumpStart = TimeLine.osTime; - Trigger( onJump ); + TriggerSafe( onJump ); jumpDirection = Vector3.Up * strength.GetJumpStrength( this ); diff --git a/Runtime/Interactions/Collidable.cs b/Runtime/Interactions/Collidable.cs index cb44ed9..92ae0b3 100644 --- a/Runtime/Interactions/Collidable.cs +++ b/Runtime/Interactions/Collidable.cs @@ -78,8 +78,8 @@ namespace Rokojori onEnteredColliderPose.CopyGlobalPoseFrom( collider.area ); } - Action.Trigger( collider.onEntered ); - Action.Trigger( onEntered ); + Action.TriggerSafe( collider.onEntered ); + Action.TriggerSafe( onEntered ); } else if ( phase == CollisionPhase.Inside ) { @@ -90,8 +90,8 @@ namespace Rokojori onInsideColliderPose.CopyGlobalPoseFrom( collider.area ); } - Action.Trigger( collider.onInside ); - Action.Trigger( onInside ); + Action.TriggerSafe( collider.onInside ); + Action.TriggerSafe( onInside ); } else if ( phase == CollisionPhase.Exit ) { @@ -102,8 +102,8 @@ namespace Rokojori onExitColliderPose.CopyGlobalPoseFrom( collider.area ); } - Action.Trigger( collider.onExit ); - Action.Trigger( onExit ); + Action.TriggerSafe( collider.onExit ); + Action.TriggerSafe( onExit ); } _collider = null; diff --git a/Runtime/Interactions/Grabbable.cs b/Runtime/Interactions/Grabbable.cs index 0db9de8..eabd872 100644 --- a/Runtime/Interactions/Grabbable.cs +++ b/Runtime/Interactions/Grabbable.cs @@ -107,11 +107,11 @@ namespace Rokojori if ( this.grabber != null ) { - Action.Trigger( onGrab ); + Action.TriggerSafe( onGrab ); } else { - Action.Trigger( onRelease ); + Action.TriggerSafe( onRelease ); } } diff --git a/Runtime/Interactions/Grabber.cs b/Runtime/Interactions/Grabber.cs index c7ee540..e03d5ce 100644 --- a/Runtime/Interactions/Grabber.cs +++ b/Runtime/Interactions/Grabber.cs @@ -100,7 +100,7 @@ namespace Rokojori }) ); - Action.Trigger( onGrab ); + Action.TriggerSafe( onGrab ); } void ReleaseGrabbing() @@ -114,7 +114,7 @@ namespace Rokojori _callback.done = true; _callback = null; - Action.Trigger( onRelease ); + Action.TriggerSafe( onRelease ); } void UpdateGrabbable() diff --git a/Runtime/Interactions/Interactor.cs b/Runtime/Interactions/Interactor.cs index 5efa639..1b8f004 100644 --- a/Runtime/Interactions/Interactor.cs +++ b/Runtime/Interactions/Interactor.cs @@ -49,7 +49,7 @@ namespace Rokojori return; } - Action.Trigger( interactable.onInteraction ); + Action.TriggerSafe( interactable.onInteraction ); } } } \ No newline at end of file diff --git a/Runtime/Interactions/MultiRayCaster.cs b/Runtime/Interactions/MultiRayCaster.cs index d5d8cbd..52fff4e 100644 --- a/Runtime/Interactions/MultiRayCaster.cs +++ b/Runtime/Interactions/MultiRayCaster.cs @@ -82,7 +82,7 @@ namespace Rokojori } - Action.Trigger( beforeProcess ); + Action.TriggerSafe( beforeProcess ); ResolveCollisions(); SortCollisions(); @@ -99,7 +99,7 @@ namespace Rokojori } } - Action.Trigger( afterProcess ); + Action.TriggerSafe( afterProcess ); } diff --git a/Runtime/Interactions/Pointable.cs b/Runtime/Interactions/Pointable.cs index afec0b7..af513b2 100644 --- a/Runtime/Interactions/Pointable.cs +++ b/Runtime/Interactions/Pointable.cs @@ -66,11 +66,11 @@ namespace Rokojori if ( pointed ) { _pointers.Add( pointer ); - Action.Trigger( onPointerAdded ); + Action.TriggerSafe( onPointerAdded ); if ( _pointers.Count == 1 ) { - Action.Trigger( onPointed ); + Action.TriggerSafe( onPointed ); } } @@ -78,11 +78,11 @@ namespace Rokojori { _pointers.Remove( pointer ); - Action.Trigger( onPointerRemoved ); + Action.TriggerSafe( onPointerRemoved ); if ( _pointers.Count == 0 ) { - Action.Trigger( onUnpointed ); + Action.TriggerSafe( onUnpointed ); } } diff --git a/Runtime/Logging/RJLog.cs b/Runtime/Logging/RJLog.cs index 1eef39a..6c487a2 100644 --- a/Runtime/Logging/RJLog.cs +++ b/Runtime/Logging/RJLog.cs @@ -9,7 +9,37 @@ namespace Rokojori { public class RJLog { + + #if ROKOJORI_ACTION_CORE + static void _LogObjects( object obj, params object[] values ) + { + string message = obj + ""; + + for ( int i = 0; i < values.Length; i++ ) + { + message += " " + values[ i ]; + } + + GD.Print( message ); + } + + public static void Log( object obj, params object[] values ) + { + _LogObjects( obj, values ); + } + + public static void Warn( object obj, params object[] values ) + { + _LogObjects( obj, values ); + } + + public static void Error( object obj, params object[] values ) + { + _LogObjects( obj, values ); + } + + #else public static string GetInfo( object obj, params object[] values ) { @@ -296,6 +326,9 @@ namespace Rokojori return sb.ToString(); } + + + #endif } } diff --git a/Runtime/Math/Geometry/Path2.cs b/Runtime/Math/Geometry/Path2.cs index f652580..54e07ea 100644 --- a/Runtime/Math/Geometry/Path2.cs +++ b/Runtime/Math/Geometry/Path2.cs @@ -4,9 +4,6 @@ using Godot; namespace Rokojori { - - - public enum PointInPathResult { INSIDE, @@ -14,8 +11,6 @@ namespace Rokojori ERROR } - - public class Path2 { float POINT_TO_CLOSE_DISTANCE = 0.0001f; @@ -556,6 +551,7 @@ namespace Rokojori const double DefaultClipperLibraryScale = 10e8; + public static Path2 ToLinearXZPath( Path3D path3D ) { var curve = path3D.Curve; @@ -571,7 +567,9 @@ namespace Rokojori return new Path2( points ); - } + } + + #if !ROKOJORI_ACTION_CORE public static List ToClipperPath( Path2 path, double scale = Path2.DefaultClipperLibraryScale ) { @@ -648,6 +646,6 @@ namespace Rokojori return s; } - + #endif } } \ No newline at end of file diff --git a/Runtime/Math/Geometry/Shape2.cs b/Runtime/Math/Geometry/Shape2.cs index cb791f2..dcb75aa 100644 --- a/Runtime/Math/Geometry/Shape2.cs +++ b/Runtime/Math/Geometry/Shape2.cs @@ -1,14 +1,19 @@ using System.Collections; using System.Collections.Generic; using Godot; + +#if !ROKOJORI_ACTION_CORE using TriangleNet.Geometry; using TriangleNet.Meshing; using TriangleNet.Meshing.Algorithm; +#endif namespace Rokojori { + #if !ROKOJORI_ACTION_CORE using ClipperPath = List; using ClipperShape = List>; + #endif public enum ShapeFillRule { @@ -31,195 +36,13 @@ namespace Rokojori this.paths.AddRange( paths ); } - public Shape2 CleanUp( ShapeFillRule fillRule = ShapeFillRule.NonZero ) - { - var clipperPath = ToClipperPaths( this ); - - var clipper = new ClipperLib.Clipper(); - - var fillType = _ConvertFillRule( fillRule ); - - clipperPath = ClipperLib.Clipper.SimplifyPolygons( clipperPath, fillType ); - - return FromClipperPaths( clipperPath ); - } - - - Polygon _CreateTNetPolygon( bool simplify = true ) - { - // RJLog.Log( "Creating polygon", paths.Count ); - - if ( paths.Count == 0 ) - { - RJLog.Log( "No paths" ); - return null; - } - - var polyPaths = paths; - - if ( simplify && false ) - { - var resultPaths = Lists.Map( polyPaths, p => Path2.ToClipperPath( p ) ); - - resultPaths = ClipperLib.Clipper.SimplifyPolygons( resultPaths, ClipperLib.PolyFillType.pftEvenOdd ); - - polyPaths = new List(); - - resultPaths.ForEach( - ( r ) => - { - polyPaths.Add( Path2.FromClipperPath( r ) ); - } - ); - - } - - // RJLog.Log( "Using paths", polyPaths.Count ); - - var polygon = new Polygon(); - - - var index = 0; - var firstIsClockWise = polyPaths.Count > 0 && polyPaths[ 0 ].isClockwise; - - polyPaths.ForEach( - ( path )=> - { - var vertices = Lists.Map( path.points, p => new Vertex( p.X, p.Y ) ); - var center = path.center; - var isClockwise = path.isClockwise; - var isHole = firstIsClockWise != isClockwise; - - // RJLog.Log( "Adding contour", center, vertices.Count, isHole ? "Hole" : "Fill" ); - - - polygon.Add( new Contour( vertices, index ), isHole ); - - - index ++; - } - ); - - return polygon; - } - - public static List> ToClipperPaths( Shape2 s ) - { - var paths = new List>(); - - s.paths.ForEach( p => paths.Add( Path2.ToClipperPath( p ) ) ); - - return paths; - } - - public static Shape2 FromClipperPaths( List> paths ) - { - var shape = new Shape2(); - - paths.ForEach( p => shape.paths.Add( Path2.FromClipperPath( p ) ) ); - - return shape; - } - - static ClipperLib.PolyFillType _ConvertFillRule( ShapeFillRule fillRule ) - { - return ShapeFillRule.EvenOdd == fillRule ? ClipperLib.PolyFillType.pftEvenOdd : ClipperLib.PolyFillType.pftNonZero; - } - public string ToSVGPath() { var svgPaths = Lists.Map( paths, p => p.ToSVGPath() ); return Lists.Join( svgPaths, " " ); } + - public static Shape2 UnionAll( List paths ) - { - paths.ForEach( p => - { - if ( ! p.isClockwise ) - { - p.Reverse(); - } - - // RJLog.Log( pathIndex++, p.isClockwise ); - } - ); - - var shape = new Shape2(); - shape.fillRule = ShapeFillRule.EvenOdd; - // shape.paths = paths; - // shape.CleanUp(); - - - shape.paths.Add( paths[ 0 ] ); - - for ( int i = 1; i < paths.Count; i++ ) - { - var otherShape = new Shape2(); - otherShape.fillRule = ShapeFillRule.EvenOdd; - otherShape.paths.Add( paths[ i ] ); - var pathsBefore = shape.paths.Count; - shape = Shape2.Boolean( shape, otherShape, Geometry2D.PolyBooleanOperation.Union ); - - // RJLog.Log( "Union:", pathsBefore, shape.paths.Count ); - - - } - - return shape; - } - - public static Shape2 Boolean( Shape2 a, Shape2 b, Geometry2D.PolyBooleanOperation booleanOperation, bool simplify = true ) - { - // RJLog.Log( "Using Clipper Library" ); - - var clipperPathsA = ToClipperPaths( a ); - var clipperPathsB = ToClipperPaths( b ); - - var resultPaths = new List>(); - - var type = ClipperLib.ClipType.ctUnion; - - if ( Geometry2D.PolyBooleanOperation.Difference == booleanOperation ) - { - type = ClipperLib.ClipType.ctDifference; - } - else if ( Geometry2D.PolyBooleanOperation.Intersection == booleanOperation ) - { - type = ClipperLib.ClipType.ctIntersection; - } - else if ( Geometry2D.PolyBooleanOperation.Xor == booleanOperation ) - { - type = ClipperLib.ClipType.ctXor; - } - - var subjectPolyType = _ConvertFillRule( a.fillRule ); - var clipPolyType = _ConvertFillRule( b.fillRule ); - - // RJLog.Log( "ShapeBool", "type: " + type, "boolOp: " + booleanOperation, "A|B >>",clipperPathsA.Count, clipperPathsB.Count ); - var clipper = new ClipperLib.Clipper(); - clipper.AddPaths( clipperPathsA, ClipperLib.PolyType.ptSubject, true); - clipper.AddPaths( clipperPathsB, ClipperLib.PolyType.ptClip, true); - clipper.Execute( type, resultPaths, subjectPolyType, clipPolyType ); - - if ( simplify ) - { - resultPaths = ClipperLib.Clipper.SimplifyPolygons( resultPaths ); - } - - - var s = new Shape2(); - - resultPaths.ForEach( - ( r ) => - { - s.paths.Add( Path2.FromClipperPath( r ) ); - } - ); - - return s; - } - public static Shape2 FromSVGPath( string pathData, float resolution ) { var shape = new Shape2(); @@ -328,6 +151,210 @@ namespace Rokojori return shape; } + + public Shape2 CleanUp( ShapeFillRule fillRule = ShapeFillRule.NonZero ) + { + + #if !ROKOJORI_ACTION_CORE + + var clipperPath = ToClipperPaths( this ); + + var clipper = new ClipperLib.Clipper(); + + var fillType = _ConvertFillRule( fillRule ); + + clipperPath = ClipperLib.Clipper.SimplifyPolygons( clipperPath, fillType ); + + return FromClipperPaths( clipperPath ); + + #else + + return this; + + #endif + } + + + // ============================================ + // ============================================ + // ============================================ + + + #if !ROKOJORI_ACTION_CORE + + Polygon _CreateTNetPolygon( bool simplify = true ) + { + // RJLog.Log( "Creating polygon", paths.Count ); + + if ( paths.Count == 0 ) + { + RJLog.Log( "No paths" ); + return null; + } + + var polyPaths = paths; + + if ( simplify && false ) + { + var resultPaths = Lists.Map( polyPaths, p => Path2.ToClipperPath( p ) ); + + resultPaths = ClipperLib.Clipper.SimplifyPolygons( resultPaths, ClipperLib.PolyFillType.pftEvenOdd ); + + polyPaths = new List(); + + resultPaths.ForEach( + ( r ) => + { + polyPaths.Add( Path2.FromClipperPath( r ) ); + } + ); + + } + + // RJLog.Log( "Using paths", polyPaths.Count ); + + var polygon = new Polygon(); + + + var index = 0; + var firstIsClockWise = polyPaths.Count > 0 && polyPaths[ 0 ].isClockwise; + + polyPaths.ForEach( + ( path )=> + { + var vertices = Lists.Map( path.points, p => new Vertex( p.X, p.Y ) ); + var center = path.center; + var isClockwise = path.isClockwise; + var isHole = firstIsClockWise != isClockwise; + + // RJLog.Log( "Adding contour", center, vertices.Count, isHole ? "Hole" : "Fill" ); + + + polygon.Add( new Contour( vertices, index ), isHole ); + + + index ++; + } + ); + + return polygon; + } + + + + + public static List> ToClipperPaths( Shape2 s ) + { + var paths = new List>(); + + s.paths.ForEach( p => paths.Add( Path2.ToClipperPath( p ) ) ); + + return paths; + } + + public static Shape2 FromClipperPaths( List> paths ) + { + var shape = new Shape2(); + + paths.ForEach( p => shape.paths.Add( Path2.FromClipperPath( p ) ) ); + + return shape; + } + + static ClipperLib.PolyFillType _ConvertFillRule( ShapeFillRule fillRule ) + { + return ShapeFillRule.EvenOdd == fillRule ? ClipperLib.PolyFillType.pftEvenOdd : ClipperLib.PolyFillType.pftNonZero; + } + + + public static Shape2 UnionAll( List paths ) + { + paths.ForEach( p => + { + if ( ! p.isClockwise ) + { + p.Reverse(); + } + + // RJLog.Log( pathIndex++, p.isClockwise ); + } + ); + + var shape = new Shape2(); + shape.fillRule = ShapeFillRule.EvenOdd; + // shape.paths = paths; + // shape.CleanUp(); + + + shape.paths.Add( paths[ 0 ] ); + + for ( int i = 1; i < paths.Count; i++ ) + { + var otherShape = new Shape2(); + otherShape.fillRule = ShapeFillRule.EvenOdd; + otherShape.paths.Add( paths[ i ] ); + var pathsBefore = shape.paths.Count; + shape = Shape2.Boolean( shape, otherShape, Geometry2D.PolyBooleanOperation.Union ); + + // RJLog.Log( "Union:", pathsBefore, shape.paths.Count ); + + + } + + return shape; + } + + public static Shape2 Boolean( Shape2 a, Shape2 b, Geometry2D.PolyBooleanOperation booleanOperation, bool simplify = true ) + { + // RJLog.Log( "Using Clipper Library" ); + + var clipperPathsA = ToClipperPaths( a ); + var clipperPathsB = ToClipperPaths( b ); + + var resultPaths = new List>(); + + var type = ClipperLib.ClipType.ctUnion; + + if ( Geometry2D.PolyBooleanOperation.Difference == booleanOperation ) + { + type = ClipperLib.ClipType.ctDifference; + } + else if ( Geometry2D.PolyBooleanOperation.Intersection == booleanOperation ) + { + type = ClipperLib.ClipType.ctIntersection; + } + else if ( Geometry2D.PolyBooleanOperation.Xor == booleanOperation ) + { + type = ClipperLib.ClipType.ctXor; + } + + var subjectPolyType = _ConvertFillRule( a.fillRule ); + var clipPolyType = _ConvertFillRule( b.fillRule ); + + // RJLog.Log( "ShapeBool", "type: " + type, "boolOp: " + booleanOperation, "A|B >>",clipperPathsA.Count, clipperPathsB.Count ); + var clipper = new ClipperLib.Clipper(); + clipper.AddPaths( clipperPathsA, ClipperLib.PolyType.ptSubject, true); + clipper.AddPaths( clipperPathsB, ClipperLib.PolyType.ptClip, true); + clipper.Execute( type, resultPaths, subjectPolyType, clipPolyType ); + + if ( simplify ) + { + resultPaths = ClipperLib.Clipper.SimplifyPolygons( resultPaths ); + } + + + var s = new Shape2(); + + resultPaths.ForEach( + ( r ) => + { + s.paths.Add( Path2.FromClipperPath( r ) ); + } + ); + + return s; + } + public MeshGeometry CreateFillMeshGeometry() { /*if ( paths.Count == 1 ) @@ -387,5 +414,7 @@ namespace Rokojori return meshGeometry; } + + #endif } } \ No newline at end of file diff --git a/Runtime/Math/Math2D.cs b/Runtime/Math/Math2D.cs index 9bcbed0..135a228 100644 --- a/Runtime/Math/Math2D.cs +++ b/Runtime/Math/Math2D.cs @@ -13,6 +13,8 @@ namespace Rokojori X, Y } + #if !ROKOJORI_ACTION_CORE + public static Vector2I RoundToInt( this Vector2 v ) { return new Vector2I( Mathf.RoundToInt( v.X ), Mathf.RoundToInt( v.Y ) ); @@ -176,5 +178,7 @@ namespace Rokojori return mean; } + + #endif } } \ No newline at end of file diff --git a/Runtime/Math/Math3D.cs b/Runtime/Math/Math3D.cs index 3046c94..45e79cc 100644 --- a/Runtime/Math/Math3D.cs +++ b/Runtime/Math/Math3D.cs @@ -14,6 +14,8 @@ namespace Rokojori } + #if !ROKOJORI_ACTION_CORE + public static float ComputeLineDistance( IEnumerable points ) { return ComputeLineDistance( points, ( p ) => p ); @@ -853,7 +855,7 @@ namespace Rokojori return (Box3) aabb; } - + #endif } } \ No newline at end of file diff --git a/Runtime/Networking/Backends/LAN/LANNetworkingBackend.cs b/Runtime/Networking/Backends/LAN/LANNetworkingBackend.cs index c0f2b32..b9b263a 100644 --- a/Runtime/Networking/Backends/LAN/LANNetworkingBackend.cs +++ b/Runtime/Networking/Backends/LAN/LANNetworkingBackend.cs @@ -42,7 +42,7 @@ namespace Rokojori _state = NetworkSessionConnectionState.Connected_As_Server; _sessionManager.SetInSessionState(); - Action.Trigger( _manager.onStartedSession ); + Action.TriggerSafe( _manager.onStartedSession ); AssignMultiplyer(); @@ -130,7 +130,7 @@ namespace Rokojori _state = NetworkSessionConnectionState.Connected_As_Client; _sessionManager.SetInSessionState(); - Action.Trigger( _manager.onStartedSession ); + Action.TriggerSafe( _manager.onStartedSession ); }; multiplayer.PeerConnected += ( id )=> diff --git a/Runtime/Networking/Nodes/INetworkingNode.cs b/Runtime/Networking/Nodes/INetworkingNode.cs index 04262b2..c4bb7d9 100644 --- a/Runtime/Networking/Nodes/INetworkingNode.cs +++ b/Runtime/Networking/Nodes/INetworkingNode.cs @@ -7,10 +7,13 @@ namespace Rokojori public interface INetworkNode { + #if !ROKOJORI_ACTION_CORE List GetNetworkNodeMembers(); NetworkTransportType GetNetworkType(); int GetNetworkOwner(); + + #endif } } \ No newline at end of file diff --git a/Runtime/Networking/Nodes/NetworkNode.cs b/Runtime/Networking/Nodes/NetworkNode.cs index 725deb0..caf61ff 100644 --- a/Runtime/Networking/Nodes/NetworkNode.cs +++ b/Runtime/Networking/Nodes/NetworkNode.cs @@ -1,5 +1,8 @@ using Godot; +#if !ROKOJORI_ACTION_CORE using Rokojori.Tools; +#endif + using System.Collections.Generic; namespace Rokojori; @@ -9,7 +12,7 @@ namespace Rokojori; [RokojoriActionCoreExport] public partial class NetworkNode : Node, INetworkNode { - #if !GD_SCRIPT_TRANSPILING + #if !ROKOJORI_ACTION_CORE [ExportGroup("Network Settings")] [Export] diff --git a/Runtime/Physics/Projectile.cs b/Runtime/Physics/Projectile.cs index 23bc846..dd8cff7 100644 --- a/Runtime/Physics/Projectile.cs +++ b/Runtime/Physics/Projectile.cs @@ -48,7 +48,7 @@ namespace Rokojori collider.TriggerOnCollisionEnter( this, collision ); } - Action.Trigger( onCollision ); + Action.TriggerSafe( onCollision ); if ( disableOnCollision ) { diff --git a/Runtime/Selectors/EvaluateSelector.cs b/Runtime/Selectors/EvaluateSelector.cs index bd5006b..a055356 100644 --- a/Runtime/Selectors/EvaluateSelector.cs +++ b/Runtime/Selectors/EvaluateSelector.cs @@ -40,11 +40,11 @@ namespace Rokojori if ( selected ) { - Trigger( onSelected ); + TriggerSafe( onSelected ); } else { - Trigger( onNotSelected ); + TriggerSafe( onNotSelected ); } } } diff --git a/Runtime/Sensors/OnSensor.cs b/Runtime/Sensors/OnSensor.cs index e167ddb..ff0fd3a 100644 --- a/Runtime/Sensors/OnSensor.cs +++ b/Runtime/Sensors/OnSensor.cs @@ -102,7 +102,7 @@ namespace Rokojori if ( executesStart ) { - Action.Trigger( onStart ); + Action.TriggerSafe( onStart ); if ( consumeEvent && onStart != null ) { @@ -112,7 +112,7 @@ namespace Rokojori if ( executesDouble ) { - Action.Trigger( onDouble ); + Action.TriggerSafe( onDouble ); if ( consumeEvent && onDouble != null ) { @@ -124,7 +124,7 @@ namespace Rokojori if ( sensor.isHold ) { - Action.Trigger( onActive ); + Action.TriggerSafe( onActive ); if ( consumeEvent && onActive != null ) { @@ -136,7 +136,7 @@ namespace Rokojori if ( sensor.isUp ) { _lastUpTime = timeNow; - Action.Trigger( onEnd ); + Action.TriggerSafe( onEnd ); if ( consumeEvent && onEnd != null ) { diff --git a/Runtime/Sensors/SensorManager.cs b/Runtime/Sensors/SensorManager.cs index 28d4d53..debe02f 100644 --- a/Runtime/Sensors/SensorManager.cs +++ b/Runtime/Sensors/SensorManager.cs @@ -151,7 +151,7 @@ namespace Rokojori } - Action.Trigger( onActiveDeviceChange ); + Action.TriggerSafe( onActiveDeviceChange ); _onActiveDeviceChange.DispatchEvent( null ); } diff --git a/Runtime/Sensors/TriggerOnSensor.cs b/Runtime/Sensors/TriggerOnSensor.cs index 50da7a7..6872583 100644 --- a/Runtime/Sensors/TriggerOnSensor.cs +++ b/Runtime/Sensors/TriggerOnSensor.cs @@ -30,7 +30,7 @@ namespace Rokojori if ( se.IsDown( sensor ) ) { - Action.Trigger( action ); + Action.TriggerSafe( action ); } } diff --git a/Runtime/Testing/DebugAction.cs b/Runtime/Testing/DebugAction.cs index 2ad40fd..ae2445d 100644 --- a/Runtime/Testing/DebugAction.cs +++ b/Runtime/Testing/DebugAction.cs @@ -50,7 +50,7 @@ namespace Rokojori public Callable RunButton => Callable.From( ()=> { - Trigger( this ); + TriggerSafe( this ); } ); diff --git a/Runtime/Testing/GDScriptExportTest.cs b/Runtime/Testing/GDScriptExportTest.cs new file mode 100644 index 0000000..2801f34 --- /dev/null +++ b/Runtime/Testing/GDScriptExportTest.cs @@ -0,0 +1,126 @@ + +using Godot; +using System.Collections.Generic; +using System.IO; + +namespace Rokojori; + +[Tool] +[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Action.svg")] +[RokojoriActionCoreExport] +public partial class GDScriptExportTest : NetworkNode +{ + + public static void OtherTest() + { + var lockable = new object(); + + lock ( lockable ) + { + if ( lockable != null ) + { + GD.Print(); + } + else + { + throw new System.Exception( "Some Error" ); + } + } + + var path = ""; + var data = ""; + + try + { + StreamWriter streamWriter = File.CreateText( path ); + + streamWriter.Write( data ); + + streamWriter.Dispose(); + } + catch ( System.Exception e ) + { + RJLog.Log( "Could not save text: ", path, "exception", e ); + + } + + + } + + public static void SwitchTest() + { + var value = 4; + + switch ( value ) + { + case 1: return; + case 2: + case 3: + { + RJLog.Log( "Should not be 3" ); + } + break; + + case 7: + { + RJLog.Log( "Should not be 7" ); + break; + } + + default: + { + RJLog.Log( "This is the default!" ); + break; + } + } + } + + + public static void CrazyLoopTest() + { + var someVar = true; + var xx = 0; + + while ( someVar ) + { + xx += 2; + + if ( xx > 100 ) + { + someVar = false; + } + + if ( xx < 100) + { + break; + } + } + + for ( int startX = 0, startY = -1, x = 4; x < 10; x++ ) + { + if ( x == 7 ) + { + continue; + } + + if ( startX - x > startY ) + { + continue; + } + + for ( int startZ = -5, startW = -1, y = 4; y < 10; y++,x+=2 ) + { + if ( startZ < 0 ) + { + for ( int zz = 77; zz > 0; zz-- ) + { + if ( startZ == startW - zz ) + { + continue; + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Testing/GDScriptExportTest.cs.uid b/Runtime/Testing/GDScriptExportTest.cs.uid new file mode 100644 index 0000000..44e0118 --- /dev/null +++ b/Runtime/Testing/GDScriptExportTest.cs.uid @@ -0,0 +1 @@ +uid://dlpm2q1vmoetr diff --git a/Runtime/Text/CodeGenerators/GDScript/CSDocToGDScriptDoc.cs b/Runtime/Text/CodeGenerators/GDScript/CSDocToGDScriptDoc.cs deleted file mode 100644 index e517b06..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/CSDocToGDScriptDoc.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.Text; - -namespace Rokojori; - -class CSDocToGDScriptDoc -{ - static void AddChildrenToIgnoreSet( XMLNode n, HashSet ignoreSet ) - { - var walker = XMLWalker.instance; - - walker.Iterate( n, - ( n )=> - { - ignoreSet.Add( n ); - } - ); - } - - public static string ConvertDoc( string docComment ) - { - if ( docComment == null || docComment == "" ) - { - return " (...) "; - } - - var xml = XMLDocument.From( docComment ); - var walker = XMLWalker.instance; - - var d = new StringBuilder(); - - var docRoot = xml.documentElement; - - var formats = new List(){ "i", "b", "s", "u" }; - var ignoreSet = new HashSet(); - - - walker.Iterate( docRoot, - n => - { - if ( ignoreSet.Contains( n ) ) - { - return; - } - - if ( n is XMLElementNode br && br.nodeName == "br" ) - { - d.Append( "[br]" ); - AddChildrenToIgnoreSet( n, ignoreSet ); - } - else if ( n is XMLElementNode url && url.nodeName == "url" ) - { - d.Append( "[url=" + url.GetAttribute( "data-path" ) + "]"); - d.Append( url.textContent ); - d.Append( "[/url]"); - - AddChildrenToIgnoreSet( n, ignoreSet ); - } - else if ( n is XMLElementNode s && formats.IndexOf( s.nodeName ) != -1 ) - { - d.Append( "[" + s.nodeName + "]"); - d.Append( s.textContent ); - d.Append( "[/" + s.nodeName + "]"); - - AddChildrenToIgnoreSet( n, ignoreSet ); - } - else if ( n is XMLElementNode c && c.nodeName.StartsWith( "doc-code" )) - { - if ( c.nodeName == "doc-code-block" ) - { - d.Append( "[codeblock]"); - d.Append( c.textContent ); - d.Append( "[/codeblock]"); - } - else - { - d.Append( "[code]"); - d.Append( c.textContent ); - d.Append( "[/code]"); - } - - AddChildrenToIgnoreSet( n, ignoreSet ); - } - else if ( n is XMLElementNode m && m.nodeName.StartsWith( "doc-link-" )) - { - d.Append( "["); - - var name = m.nodeName.Replace( "doc-link-", "" ); - - if ( name != "class" ) - { - d.Append( name ); - d.Append( " " ); - } - - d.Append( m.textContent ); - d.Append( "]"); - - AddChildrenToIgnoreSet( n, ignoreSet ); - } - else if ( n is XMLTextNode ) - { - d.Append( n.textContent ); - } - }, - false - ); - - - var dString = RegexUtility.Indent( d.ToString(), " "); - - var docLines = RegexUtility.SplitLines( dString ); - - var gdComment = "##" + docLines.Join( "\n##" ) + "\n"; - - return gdComment; - } - -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/CSDocToGDScriptDoc.cs.uid b/Runtime/Text/CodeGenerators/GDScript/CSDocToGDScriptDoc.cs.uid deleted file mode 100644 index 833f03c..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/CSDocToGDScriptDoc.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bwskdk8sbbaqo diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptFromCSAST.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptFromCSAST.cs deleted file mode 100644 index de27579..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptFromCSAST.cs +++ /dev/null @@ -1,271 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.Text; - -namespace Rokojori; - -public class GDScriptFromCSAST -{ - public GDScriptGeneratorClass gdClass = new GDScriptGeneratorClass(); - public string rokojoriPrefix = "RJ_"; - - - public static string CStoGDVariable( string csName ) - { - var sb = new StringBuilder(); - var hasUnderscore = false; - var wordStarted = false; - - for ( int i = 0; i < csName.Length; i++ ) - { - if ( char.IsUpper( csName[ i ] ) ) - { - if ( ! hasUnderscore && wordStarted ) - { - sb.Append( "_" ); - hasUnderscore = true; - } - - sb.Append( char.ToLower( csName[ i ] ) ); - wordStarted = true; - - } - else - { - sb.Append( csName[ i ] ); - hasUnderscore = csName[ i ] == '_'; - - if ( ! hasUnderscore ) - { - wordStarted = true; - } - } - } - - return sb.ToString(); - } - - static HashSet godotBuiltIn = new HashSet(){ - "Node", "Node3D", "Node2D", "Control", - "Resource", - "Vector2", "Vector3", "Vector4" - }; - - - public static bool IsGodotBuiltIn( string type ) - { - return godotBuiltIn.Contains( type ); - } - - - public static bool IsCSBuiltIn( string type ) - { - - return godotBuiltIn.Contains( type ); - } - - public static string GetNamespaceForType( string typeName, List namespaces ) - { - var assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); - - foreach ( var ns in namespaces ) - { - string fullName = ns + "." + typeName; - - foreach ( var asm in assemblies ) - { - if ( asm.GetType( fullName, false ) != null) - { - return ns; - } - } - } - - return null; - } - - public string GetClassName( string className, string ns ) - { - if ( ns != null && ! ns.StartsWith( "Rokojori" ) ) - { - return className; - } - - if ( ns == null && IsGodotBuiltIn( className ) ) - { - return className; - } - - return rokojoriPrefix + className; - } - - List namespaces = new List{ - "Godot","Godot.Collections", - "Rokojori" - }; - - - string ConvertRawType( string type ) - { - var ns = GetNamespaceForType( type, namespaces ); - - if ( ns == null ) - { - return type; - } - - if ( ns.StartsWith( "Rokojori" ) ) - { - return rokojoriPrefix + type; - } - - return type; - } - - string ConvertType( CSTypeDefinition parent ) - { - if ( parent.IsGenericList() ) - { - var convertedType = ConvertRawType( parent.GetGenericType() ); - return "Array[" + convertedType + "]"; - } - - if ( parent.IsArrayType() ) - { - var convertedType = ConvertRawType( parent.GetBaseType() ); - return "Array[" + convertedType + "]"; - } - - return ConvertRawType( parent.GetBaseType() ); - } - - - public void Convert( CSFileRoot root ) - { - var walker = root.walker; - var csClass = walker.Find( root, n => n is CSClassDeclaration, true ) as CSClassDeclaration; - - gdClass.name = GetClassName( csClass.GetClassName(), csClass.GetNamespace() ); - - if ( csClass.objectTail != null && csClass.objectTail.inheritanceDeclaration != null ) - { - gdClass.extendingClassName = GetClassName( csClass.objectTail.GetExtendingObject(), null ); - } - - if ( csClass.docComment != null ) - { - gdClass.doc = CSDocToGDScriptDoc.ConvertDoc( csClass.GetDocumentation() ); - } - - var atts = CSModifierAttributesParser.GetAttributes( csClass.attributeBrackets ); - - RJLog.Log( "Att:", atts.Map( a => "'" + a + "'" ) ); - - atts.ForEach( - ( att )=> - { - - if ( att == "Tool" ) - { - gdClass.annotations.Add( "tool" ); - } - else if ( att.StartsWith( "Icon" ) ) - { - var lcAtt = ( att[ 0 ] + "" ).ToLower() + att.Substring( 1 ); - gdClass.annotations.Add( lcAtt ); - } - } - ); - - - var members = new List(); - - walker.Iterate( csClass, - n => - { - if ( n is CSEnumDeclaration en ) - { - var enumType = new GDScriptGeneratorEnum(); - enumType.name = en.objectName.match; - - var values = en.objectBody.children.FilterType( ); - enumType.values =values.Map( v => v.GetEnumName() ); - - gdClass.members.Add( enumType ); - - return; - } - - if ( ! ( n is CSMemberDeclaration ) ) - { - return; - } - - - var m = n as CSMemberDeclaration; - - GDScriptGeneratorMember gdMember = null; - - if ( m is CSFieldDeclaration f ) - { - var gdField = new GDScriptGeneratorField(); - gdField.name = CStoGDVariable( f.GetMemberName() ); - gdField.memberType = ConvertType( f.memberType ); - - gdMember = gdField; - } - else if ( m is CSMethodMemberDeclaration me ) - { - var gdMethod = new GDScriptGeneratorMethod(); - gdMethod.name = me.isContructor ? "_init" : CStoGDVariable( me.GetMemberName() ); - gdMethod.memberType = me.isContructor ? me.GetMemberType() : ConvertType( me.memberType ); - gdMethod.isConstructor = me.isContructor; - - if ( me.parametersContent != null ) - { - me.parametersContent.children.ForEach( - ( c ) => - { - var p = c as CSParameterDeclaration; - - var gdParameter = new GDScriptGeneratorParameter(); - gdParameter.name = p.GetParameterName(); - gdParameter.parameterType = ConvertType( p.parameterType ); - - gdMethod.parameters.Add( gdParameter ); - - if ( p.parameterValue != null ) - { - gdParameter.parameterValue = p.GetParameterValue(); - } - } - ); - } - - gdMember = gdMethod; - } - - if ( gdMember == null ) - { - return; - } - - if ( m.docComment != null ) - { - gdMember.doc = CSDocToGDScriptDoc.ConvertDoc( m.GetDocumentation() ); - } - - if ( CSModifierAttributesParser.IsExported( m.attributeBrackets ) ) - { - gdMember.annotations.Add( "export" ); - } - - gdClass.members.Add( gdMember ); - - }, - false - ); - - } -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptFromCSAST.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptFromCSAST.cs.uid deleted file mode 100644 index f1707d2..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptFromCSAST.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://cgi2d0hhd5d6t diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGenerator.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGenerator.cs deleted file mode 100644 index d5c6b48..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGenerator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public class GDScriptGenerator -{ - public static readonly string GD_SCRIPT_TRANSPILING = "GD_SCRIPT_TRANSPILING"; - public List gdClasses = new List(); - - public void Generate( string outputPath ) - { - gdClasses.ForEach( - ( gd )=> - { - var source = gd.Generate(); - RJLog.Log( "GD Script from:", gd.name, "\n" + source ); - var path = FilePath.Join( outputPath, gd.name + ".gd" ); - - RJLog.Log( "GD Script Save to:", path ); - FilesSync.SaveUTF8( path, source ); - } - ); - } -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGenerator.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGenerator.cs.uid deleted file mode 100644 index dd97096..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGenerator.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://duym6hiqy40dh diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorClass.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorClass.cs deleted file mode 100644 index 61810b8..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorClass.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public class GDScriptGeneratorClass -{ - public List annotations = []; - public string name; - public string doc; - public string extendingClassName; - public List members = []; - - StringBuilder sb = new StringBuilder(); - - public string Generate() - { - sb.Append( "\n" ); - - annotations.ForEach( - annotation => - { - sb.Append( "@" ); - sb.Append( annotation ); - sb.Append( "\n" ); - } - ); - - AddClassHeader(); - - - if ( doc != null ) - { - sb.Append( doc ); - sb.Append( "\n" ); - } - - members.ForEach( m => - { - if ( m.doc != null ) - { - sb.Append( m.doc ); - } - - m.Generate( sb ); - sb.Append( "\n\n" ); - }); - - return sb.ToString(); - } - - void AddClassHeader() - { - sb.Append( "class_name " + name ); - - if ( extendingClassName != null ) - { - sb.Append( " extends " + extendingClassName ); - } - - sb.Append( "\n" ); - } -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorClass.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorClass.cs.uid deleted file mode 100644 index b74042d..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorClass.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dvt4yeqpmmrur diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorEnum.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorEnum.cs deleted file mode 100644 index 631599e..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorEnum.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public class GDScriptGeneratorEnum:GDScriptGeneratorMember -{ - public List values = new List(); - - public override void Generate( StringBuilder sb ) - { - sb.Append( "enum " + name + "\n" ); - sb.Append( "{\n" ); - - for ( int i = 0; i < values.Count; i ++ ) - { - var ending = "\n"; - - if ( i != ( values.Count - 1 ) ) - { - ending = ",\n"; - } - - sb.Append( " " + values[ i ] + ending ); - } - - sb.Append( "}\n" ); - } - -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorEnum.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorEnum.cs.uid deleted file mode 100644 index 9be4ffc..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorEnum.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://eqbysvejll0q diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorField.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorField.cs deleted file mode 100644 index 81919f6..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorField.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public class GDScriptGeneratorField:GDScriptGeneratorMember -{ - public override void Generate( StringBuilder sb ) - { - annotations.ForEach( - ( an )=> - { - sb.Append( "@" ); - sb.Append( an ); - sb.Append( "\n" ); - } - ); - - sb.Append( "var " + name + ": " + memberType + "; " ); - } - -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorField.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorField.cs.uid deleted file mode 100644 index e78ebb0..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorField.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://51c533ougel diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMember.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMember.cs deleted file mode 100644 index c7bbcef..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMember.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public abstract class GDScriptGeneratorMember -{ - public string name; - public string doc; - public string memberType; - public List annotations = []; - - - public abstract void Generate( StringBuilder sb ); - -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMember.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMember.cs.uid deleted file mode 100644 index e864a06..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMember.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bnl20gavp2hi2 diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMethod.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMethod.cs deleted file mode 100644 index 16fd301..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMethod.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public class GDScriptGeneratorMethod:GDScriptGeneratorMember -{ - public List parameters = []; - public string body = ""; - public bool isConstructor = false; - - public override void Generate( StringBuilder sb ) - { - sb.Append( "\n" ); - sb.Append( "func " + name + "(" ); - - var first = true; - - if ( parameters.Count > 0 ) - { - sb.Append( " " ); - } - - parameters.ForEach( - ( p ) => - { - if ( first ) - { - first = false; - } - else - { - sb.Append( ", " ); - } - - p.Generate( sb ); - - } - ); - - if ( parameters.Count > 0 ) - { - sb.Append( " " ); - } - - if ( isConstructor ) - { - sb.Append( "):\n" ); - } - else - { - sb.Append( ") -> " + memberType + ":\n" ); - } - - - if ( string.IsNullOrEmpty( body ) ) - { - sb.Append( " pass" ); - } - else - { - sb.Append( body ); - } - - - sb.Append( "\n" ); - sb.Append( "## ---"); - sb.Append( "\n" ); - - } - - -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMethod.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMethod.cs.uid deleted file mode 100644 index 1b2114c..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorMethod.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ddcgqrokie8en diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorParameter.cs b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorParameter.cs deleted file mode 100644 index 9004d41..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorParameter.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Rokojori; - -public class GDScriptGeneratorParameter -{ - public string name; - public string parameterType; - public string parameterValue; - - public void Generate( StringBuilder sb ) - { - sb.Append( name + ": " + parameterType ); - - if ( parameterValue != null ) - { - sb.Append( " = " + parameterValue ); - } - } - -} \ No newline at end of file diff --git a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorParameter.cs.uid b/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorParameter.cs.uid deleted file mode 100644 index c786982..0000000 --- a/Runtime/Text/CodeGenerators/GDScript/GDScriptGeneratorParameter.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bg3fdqomodfh2 diff --git a/Runtime/Text/RegexUtility.cs b/Runtime/Text/RegexUtility.cs index 94fdeb2..70a0496 100644 --- a/Runtime/Text/RegexUtility.cs +++ b/Runtime/Text/RegexUtility.cs @@ -63,6 +63,8 @@ namespace Rokojori public static class RegexUtility { + #if !ROKOJORI_ACTION_CORE + public static MatchResult Exec( this string source, string pattern, RegexOptions options = RegexOptions.None ) { var regex = new Regex( pattern ); @@ -872,5 +874,7 @@ namespace Rokojori return path; } + + #endif } } \ No newline at end of file diff --git a/Runtime/Text/TextLinesMapper.cs b/Runtime/Text/TextLinesMapper.cs index c78fa0f..724015c 100644 --- a/Runtime/Text/TextLinesMapper.cs +++ b/Runtime/Text/TextLinesMapper.cs @@ -180,7 +180,9 @@ namespace Rokojori } if ( _lines.Count == 0 || characterIndex < 0 || characterIndex > numCharacters ) - { return -1; } + { + return -1; + } var lineContainsCharacterIndex = false; var lineIndexInRange = true; @@ -193,9 +195,18 @@ namespace Rokojori var maxTries = 1000; var currentTries = 0; // currentTries ++; if ( currentTries == maxTries ) { throw new System.Exception(); } - do + var isFirst = true; + + while ( isFirst || ( ! lineContainsCharacterIndex && lineIndexInRange ) ) { - currentTries ++; if ( currentTries == maxTries ) { throw new System.Exception(); } + isFirst = false; + currentTries ++; + + if ( currentTries == maxTries ) + { + throw new System.Exception(); + } + var nextLineIndex = _cachedLineIndex + searchStep; lineIndexInRange = 0 <= nextLineIndex && nextLineIndex < _lines.Count; @@ -210,7 +221,7 @@ namespace Rokojori } } - while ( ! lineContainsCharacterIndex && lineIndexInRange ); + if ( lineContainsCharacterIndex ) { diff --git a/Runtime/Tools/Arrays.cs b/Runtime/Tools/Arrays.cs index aa9e0e8..b06716f 100644 --- a/Runtime/Tools/Arrays.cs +++ b/Runtime/Tools/Arrays.cs @@ -5,6 +5,7 @@ using System; namespace Rokojori { + [RokojoriActionCoreExportCustom] public static class Arrays { public static T[] Concat( T[] a, T[] b ) diff --git a/Runtime/Tools/Lists.cs b/Runtime/Tools/Lists.cs index a59e3ad..c5519fc 100644 --- a/Runtime/Tools/Lists.cs +++ b/Runtime/Tools/Lists.cs @@ -8,50 +8,138 @@ using System.Linq; namespace Rokojori { - - public class ListView - { - List _list; - int _offset; - int _length; - - - public ListView( List list, int offset, int length ) - { - _list = list; - _offset = offset; - _length = length; - } - - public T this[ int index ] - { - get => _list[ index - _offset ]; - set => _list[ index - _offset ] = value; - } - - public int Count => _length; - - public void ForEach( Action action ) - { - for ( int i = 0; i < _length; i++ ) - { - action( this[ i ] ); - } - } - - public List GetList() - { - return _list; - } - - public List SubList() - { - return _list.Sub( _offset, _length ); - } - } + [RokojoriActionCoreExportCustom] public static class Lists { + public static List Sub( this List elements, int start, int length = 0 ) + { + var end = length == 0 ? elements.Count : ( start + length ); + + + var list = new List( end - start ); + + for ( int i = start; i < end; i++ ) + { + list.Add( elements[ i ] ); + } + + return list; + } + + public static List FilterType( this List inputList ) where R:T + { + var list = new List(); + + inputList.ForEach + ( + e => + { + if ( e == null || ! typeof( R ).IsAssignableFrom( e.GetType() ) ) + { + return; + } + + list.Add( (R) e ); + } + ); + + return list; + } + + public static List FilterWithType( this List inputList, Type type ) + { + var list = new List(); + + inputList.ForEach + ( + e => + { + if ( e == null || ! type.IsAssignableFrom( e.GetType() ) ) + { + return; + } + + list.Add( e ); + } + ); + + return list; + } + + public static bool Has( this List list, T item ) + { + return list.IndexOf( item ) != - 1; + } + + + public static void RemoveList( this List list, List removals ) + { + var removalSet = new HashSet(); + removalSet.UnionWith( removals ); + + list.RemoveAll( e => removalSet.Contains( e ) ); + } + + public static List FilterAndMap( List list, Func filter, Func map) + { + var mapped = new List(); + + for ( int i = 0; i < list.Count; i++ ) + { + if ( ! filter( list[ i ], i ) ) + { + continue; + } + + mapped.Add( map( list[ i ] ) ); + } + + return mapped; + } + + public static bool AreEntriesEqual( List a, List b ) + { + if ( a.Count != b.Count ) + { + return false; + } + + for ( int i = 0; i < a.Count; i++ ) + { + var isEqual = EqualityComparer.Default.Equals( a[ i ], b[ i ]); + + if ( ! isEqual ) + { + return false; + } + } + + return true; + } + + public static List FromEnumerable( IEnumerable enumerable ) + { + var listA = new List(); + + foreach ( var it in enumerable ) + { + listA.Add( (T) it ); + } + + return listA; + } + + + // =============================================== + // =============================================== + // =============================================== + // =============================================== + // =============================================== + + + + #if !ROKOJORI_ACTION_CORE public static void Union( this List list, List other ) { @@ -506,21 +594,7 @@ namespace Rokojori { return elements.Sub( start, end - start + 1 ); } - - public static List Sub( this List elements, int start, int length = 0 ) - { - var end = length == 0 ? elements.Count : ( start + length ); - - - var list = new List( end - start ); - - for ( int i = start; i < end; i++ ) - { - list.Add( elements[ i ] ); - } - - return list; - } + public static void ShuffleMultiple( this List list, int numShuffles, int step = 2 ) { @@ -575,10 +649,7 @@ namespace Rokojori return list; } - public static bool Has( this List list, T item ) - { - return list.IndexOf( item ) != - 1; - } + public static T RemoveAt( List list, int index ) { @@ -686,13 +757,6 @@ namespace Rokojori } } - public static void RemoveList( this List list, List removals ) - { - var removalSet = new HashSet(); - removalSet.UnionWith( removals ); - - list.RemoveAll( e => removalSet.Contains( e ) ); - } public static int CountItems( List list, Predicate test ) { @@ -724,17 +788,6 @@ namespace Rokojori return result; } - public static List FromEnumerable( IEnumerable enumerable ) - { - var listA = new List(); - - foreach ( var it in enumerable ) - { - listA.Add( (T) it ); - } - - return listA; - } public static bool AreListsAndEntriesEqual( object objA, object objB ) { @@ -746,25 +799,7 @@ namespace Rokojori return AreEntriesEqual( FromEnumerable( objA as IEnumerable ), FromEnumerable( objB as IEnumerable ) ); } - public static bool AreEntriesEqual( List a, List b ) - { - if ( a.Count != b.Count ) - { - return false; - } - - for ( int i = 0; i < a.Count; i++ ) - { - var isEqual = EqualityComparer.Default.Equals( a[ i ], b[ i ]); - - if ( ! isEqual ) - { - return false; - } - } - - return true; - } + /*public static string Join( this List list, string seperator = "," ) @@ -881,23 +916,7 @@ namespace Rokojori } - public static List FilterAndMap( List list, Func filter, Func map) - { - var mapped = new List(); - - for ( int i = 0; i < list.Count; i++ ) - { - if ( ! filter( list[ i ], i ) ) - { - continue; - } - - mapped.Add( map( list[ i ] ) ); - } - - return mapped; - } - + public static async Task> FilterAsync( this List list, Func> filter ) { var outputList = new List(); @@ -976,45 +995,7 @@ namespace Rokojori } - public static List FilterType( this List inputList ) where R:T - { - var list = new List(); - - inputList.ForEach - ( - e => - { - if ( e == null || ! typeof( R ).IsAssignableFrom( e.GetType() ) ) - { - return; - } - - list.Add( (R) e ); - } - ); - - return list; - } - - public static List FilterType( this List inputList, Type type ) - { - var list = new List(); - - inputList.ForEach - ( - e => - { - if ( e == null || ! type.IsAssignableFrom( e.GetType() ) ) - { - return; - } - - list.Add( e ); - } - ); - - return list; - } + public static void Add( this List list, params T[] entries ) { @@ -1211,6 +1192,49 @@ namespace Rokojori return list; } + #endif + + + } + + public class ListView + { + List _list; + int _offset; + int _length; + + public ListView( List list, int offset, int length ) + { + _list = list; + _offset = offset; + _length = length; + } + + public T this[ int index ] + { + get => _list[ index - _offset ]; + set => _list[ index - _offset ] = value; + } + + public int Count => _length; + + public void ForEach( Action action ) + { + for ( int i = 0; i < _length; i++ ) + { + action( this[ i ] ); + } + } + + public List GetList() + { + return _list; + } + + public List SubList() + { + return _list.Sub( _offset, _length ); + } } } \ No newline at end of file diff --git a/Runtime/Tools/ReflectionHelper.cs b/Runtime/Tools/ReflectionHelper.cs index 91caf24..52afbf4 100644 --- a/Runtime/Tools/ReflectionHelper.cs +++ b/Runtime/Tools/ReflectionHelper.cs @@ -9,6 +9,8 @@ namespace Rokojori { public static class ReflectionHelper { + #if !ROKOJORI_ACTION_CORE + public static List> GetExportedMembersAsJSON( object obj ) { var type = obj.GetType(); @@ -576,5 +578,7 @@ namespace Rokojori ); } + #endif + } } \ No newline at end of file diff --git a/Runtime/UI/Nodes/Image/UIImage.cs b/Runtime/UI/Nodes/Image/UIImage.cs index 8a8b757..49c9015 100644 --- a/Runtime/UI/Nodes/Image/UIImage.cs +++ b/Runtime/UI/Nodes/Image/UIImage.cs @@ -512,17 +512,17 @@ namespace Rokojori if ( mb.ButtonIndex == MouseButton.Left ) { - Action.Trigger( onLeftClick ); + Action.TriggerSafe( onLeftClick ); } if ( mb.ButtonIndex == MouseButton.Middle ) { - Action.Trigger( onMiddleClick ); + Action.TriggerSafe( onMiddleClick ); } if ( mb.ButtonIndex == MouseButton.Right ) { - Action.Trigger( onRightClick ); + Action.TriggerSafe( onRightClick ); } } } diff --git a/Runtime/UI/Nodes/UIRegion.cs b/Runtime/UI/Nodes/UIRegion.cs index a12e5d7..5abc63e 100644 --- a/Runtime/UI/Nodes/UIRegion.cs +++ b/Runtime/UI/Nodes/UIRegion.cs @@ -152,17 +152,17 @@ namespace Rokojori if ( mb.ButtonIndex == MouseButton.Left ) { - Action.Trigger( onLeftClick ); + Action.TriggerSafe( onLeftClick ); } if ( mb.ButtonIndex == MouseButton.Middle ) { - Action.Trigger( onMiddleClick ); + Action.TriggerSafe( onMiddleClick ); } if ( mb.ButtonIndex == MouseButton.Right ) { - Action.Trigger( onRightClick ); + Action.TriggerSafe( onRightClick ); } } } diff --git a/Runtime/UI/Nodes/UIText.cs b/Runtime/UI/Nodes/UIText.cs index 04b5329..5dd31c7 100644 --- a/Runtime/UI/Nodes/UIText.cs +++ b/Runtime/UI/Nodes/UIText.cs @@ -508,17 +508,17 @@ namespace Rokojori if ( mb.ButtonIndex == MouseButton.Left ) { - Action.Trigger( onLeftClick ); + Action.TriggerSafe( onLeftClick ); } if ( mb.ButtonIndex == MouseButton.Middle ) { - Action.Trigger( onMiddleClick ); + Action.TriggerSafe( onMiddleClick ); } if ( mb.ButtonIndex == MouseButton.Right ) { - Action.Trigger( onRightClick ); + Action.TriggerSafe( onRightClick ); } } } diff --git a/Runtime/UI/OnSliderValueChange.cs b/Runtime/UI/OnSliderValueChange.cs index b6ee02a..fb00f70 100644 --- a/Runtime/UI/OnSliderValueChange.cs +++ b/Runtime/UI/OnSliderValueChange.cs @@ -39,7 +39,7 @@ namespace Rokojori void OnChanged() { - Action.Trigger( onChange ); + Action.TriggerSafe( onChange ); } } } \ No newline at end of file diff --git a/Runtime/XML/XMLWalker.cs b/Runtime/XML/XMLWalker.cs index b61ecf7..aca1fef 100644 --- a/Runtime/XML/XMLWalker.cs +++ b/Runtime/XML/XMLWalker.cs @@ -45,7 +45,7 @@ namespace Rokojori public override XMLNode Parent( XMLNode node ) { - return node.parentNode; + return node?.parentNode; } } diff --git a/Tools/core-generation/RokojoriActionCoreExportCustom.cs b/Tools/core-generation/RokojoriActionCoreExportCustom.cs new file mode 100644 index 0000000..05dbb0e --- /dev/null +++ b/Tools/core-generation/RokojoriActionCoreExportCustom.cs @@ -0,0 +1,7 @@ +using System; +namespace Rokojori; + +public class RokojoriActionCoreExportCustom : Attribute +{ + +} \ No newline at end of file diff --git a/Tools/core-generation/RokojoriActionCoreExportCustom.cs.uid b/Tools/core-generation/RokojoriActionCoreExportCustom.cs.uid new file mode 100644 index 0000000..0c2095a --- /dev/null +++ b/Tools/core-generation/RokojoriActionCoreExportCustom.cs.uid @@ -0,0 +1 @@ +uid://b63k1xk5nx27u diff --git a/Tools/core-generation/RokojoriActionCoreGenerator.cs b/Tools/core-generation/RokojoriActionCoreGenerator.cs index d126dfa..bf64184 100644 --- a/Tools/core-generation/RokojoriActionCoreGenerator.cs +++ b/Tools/core-generation/RokojoriActionCoreGenerator.cs @@ -14,6 +14,8 @@ namespace Rokojori.CoreGeneration; [Tool] public partial class RokojoriActionCoreGenerator : Node { + public static readonly string ROKOJORI_ACTION_CORE = "ROKOJORI_ACTION_CORE"; + [ExportToolButton( "Generate" )] public Callable generateButton => Callable.From( ()=> diff --git a/plugin.cfg b/plugin.cfg index 6ab27ae..10cc573 100644 --- a/plugin.cfg +++ b/plugin.cfg @@ -3,5 +3,5 @@ name="Rokojori Action Library" description="Library for actions, assets and effects" author="Rokojori" -version="0.2" +version="0.5" script="RokojoriPlugin.cs"