Updated/Cleaned Form ScriptGenerators

This commit is contained in:
Rokojori 2026-05-02 12:32:42 +02:00
parent f6f2958f49
commit 107614bcb7
107 changed files with 1201 additions and 1332 deletions

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -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]

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -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]

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -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]

View File

@ -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 )
{
@ -189,13 +226,13 @@ 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<Action>( target, ( a ) => Trigger( a ) );
Nodes.ForEachDirectChild<Action>( 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<Action>( target, ( a ) => Trigger( a ) );
Nodes.ForEachDirectChild<Action>( target, ( a ) => TriggerSafe( a ) );
}
#endif
}

View File

@ -35,7 +35,7 @@ namespace Rokojori
protected override void _OnTrigger()
{
Action.TriggerAll( actions, this, triggerDirectChildren );
Action.TriggerAllActions( actions, this, triggerDirectChildren );
}
}
}

View File

@ -27,7 +27,7 @@ namespace Rokojori
protected override void _OnTrigger()
{
Action.Trigger( referencedAction );
Action.TriggerSafe( referencedAction );
}
}

View File

@ -31,11 +31,11 @@ namespace Rokojori
if ( conditionActive )
{
Trigger( ifAction );
TriggerSafe( ifAction );
}
else
{
Trigger( elseAction );
TriggerSafe( elseAction );
}
}

View File

@ -79,7 +79,7 @@ namespace Rokojori
_canRelease = true;
Trigger( action );
TriggerSafe( action );
RegisterCoolDown();

View File

@ -23,7 +23,7 @@ namespace Rokojori
}
canTrigger = false;
Action.Trigger( action );
Action.TriggerSafe( action );
}
}

View File

@ -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 )
{

View File

@ -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 )
{

View File

@ -23,7 +23,7 @@ namespace Rokojori
iterationIndex = MathX.Repeat( iterationIndex, num );
Action.Trigger( this.GetNthDirectChild<Action>( iterationIndex ) );
Action.TriggerSafe( this.GetNthDirectChild<Action>( iterationIndex ) );
iterationIndex++;
}

View File

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

View File

@ -6,7 +6,8 @@ namespace Rokojori
{
[Tool]
[GlobalClass ]
public partial class RJLogMessage : Action
[RokojoriActionCoreExport]
public partial class LogMessage : Action
{
[Export]
public string message;

View File

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

View File

@ -17,7 +17,7 @@ namespace Rokojori
public override void _PhysicsProcess( double delta )
{
Action.TriggerAll( actions, this, triggerDirectChildren );
Action.TriggerAllActions( actions, this, triggerDirectChildren );
}
}
}

View File

@ -25,7 +25,7 @@ namespace Rokojori
return;
}
Action.TriggerAll( actions, this, triggerDirectChildren );
Action.TriggerAllActions( actions, this, triggerDirectChildren );
}
}
}

View File

@ -25,7 +25,7 @@ namespace Rokojori
return;
}
Action.TriggerAll( actions, this, triggerDirectChildren );
Action.TriggerAllActions( actions, this, triggerDirectChildren );
}
}
}

View File

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

View File

@ -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
## ---

View File

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

View File

@ -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
## ---

View File

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

View File

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

View File

@ -38,7 +38,7 @@ namespace Rokojori
if ( ! ( action is SequenceAction ) )
{
Trigger( action );
TriggerSafe( action );
DispatchEnd( id );
return;
}

View File

@ -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<Action> actions;
// public List<SequenceAction> 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<SequenceAction,System.Action<SequenceAction.FinishedEvent>> callbacks =
// new Dictionary<SequenceAction, System.Action<SequenceAction.FinishedEvent>>();
// void StartAction( SequenceAction action )
// {
// var capturedAction = action;
// System.Action<SequenceAction.FinishedEvent> 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<SequenceAction.FinishedEvent> 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
{
/** <summary for="field actions">Actions to execute</summary>*/
[Export]
public Action[] actions = new Action[ 0 ];
[Export]
public bool triggerDirectChildren = true;
List<SequenceRunner> running = new List<SequenceRunner>();
[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<Action>( actions );
if ( triggerDirectChildren )
{
Nodes.ForEachDirectChild<Action>( this, a => run.actions.Add( a ) );
}
run.sequencables = Lists.FilterType<Action,SequenceAction>( 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 );
}
}
}

View File

@ -6,17 +6,17 @@ using System.Linq;
namespace Rokojori
{
public class SequenceActionFinishedEvent
[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;
}
[Tool]
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/SequenceAction.svg")]
public abstract partial class SequenceAction : Action
{
[ExportGroup("Debugging")]
[ExportToolButton("Clear Listeners")]
public Callable clearListeners => Callable.From(
@ -41,7 +41,7 @@ namespace Rokojori
return _dispatchCounter;
}
public readonly EventSlot<SequenceActionFinishedEvent> onSequenceDone = new EventSlot<SequenceActionFinishedEvent>();
public readonly EventSlot<SequenceAction.FinishedEvent> onSequenceDone = new EventSlot<SequenceAction.FinishedEvent>();
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 )

View File

@ -35,7 +35,7 @@ namespace Rokojori
var ownID = DispatchStart();
var referenceID = -1;
System.Action<SequenceActionFinishedEvent> callback = ( se )=>
System.Action<SequenceAction.FinishedEvent> callback = ( se )=>
{
if ( se.id != referenceID )
{

View File

@ -8,9 +8,9 @@ using Godot;
namespace Rokojori
{
public class ActionSequenceRunner
public class SequenceRunner
{
public ActionSequence sequence;
public Sequence sequence;
public List<Action> actions;
public List<SequenceAction> 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<SequenceAction,System.Action<SequenceActionFinishedEvent>> callbacks =
new Dictionary<SequenceAction, System.Action<SequenceActionFinishedEvent>>();
Dictionary<SequenceAction,System.Action<SequenceAction.FinishedEvent>> callbacks =
new Dictionary<SequenceAction, System.Action<SequenceAction.FinishedEvent>>();
void StartAction( SequenceAction action )
{
var capturedAction = action;
System.Action<SequenceActionFinishedEvent> callback =
( SequenceActionFinishedEvent ev ) =>
System.Action<SequenceAction.FinishedEvent> callback =
( SequenceAction.FinishedEvent ev ) =>
{
@ -139,7 +139,7 @@ namespace Rokojori
*/
}
void RunNext( SequenceAction action, System.Action<SequenceActionFinishedEvent> callback )
void RunNext( SequenceAction action, System.Action<SequenceAction.FinishedEvent> 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,7 +181,7 @@ namespace Rokojori
}
// RJLog.Log( "Triggering Action", actions[ i ].Name );
Action.Trigger( actions[ i ] );
Action.TriggerSafe( actions[ i ] );
}
}
@ -189,63 +189,4 @@ namespace Rokojori
}
[Tool]
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/ActionSequence.svg") ]
public partial class ActionSequence:SequenceAction
{
/** <summary for="field actions">Actions to execute</summary>*/
[Export]
public Action[] actions = new Action[ 0 ];
[Export]
public bool triggerDirectChildren = true;
List<ActionSequenceRunner> running = new List<ActionSequenceRunner>();
[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<Action>( actions );
if ( triggerDirectChildren )
{
Nodes.ForEachDirectChild<Action>( this, a => run.actions.Add( a ) );
}
run.sequencables = Lists.FilterType<Action,SequenceAction>( 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 );
}
}
}

View File

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

View File

@ -48,11 +48,11 @@ namespace Rokojori
if ( nextIsPaused )
{
Action.Trigger( onPausing );
Action.TriggerSafe( onPausing );
}
else
{
Action.Trigger( onResuming );
Action.TriggerSafe( onResuming );
}
}

View File

@ -44,7 +44,7 @@ namespace Rokojori
TimeLineManager.ScheduleEventIn( timeLine, offset,
id =>
{
Action.Trigger( list[ i ] );
Action.TriggerSafe( list[ i ] );
}
);

View File

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

View File

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

View File

@ -55,7 +55,7 @@ namespace Rokojori
{
if ( _canModify )
{
var removed = _actions.Remove( action );
_actions.Remove( action );
// RJLog.Log( "Removed:", action, removed );
}

View File

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

View File

@ -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<string> 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<string> 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<string> 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 ) )

View File

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

View File

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

View File

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

View File

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

View File

@ -10,6 +10,68 @@ namespace Rokojori
{
public static class Nodes
{
public static void ForEachDirectChild<T>( this Node parent, System.Action<T> 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<Node> selector, Action<Node> 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<T>( this Node parent, System.Action<T> 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<Node> selector, Action<Node> 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<U> MapDirectChildren<T,U>( Node parent, System.Func<T,U> mapper ) where T:Node
{
@ -1122,6 +1129,8 @@ namespace Rokojori
}
}
#endif
}

View File

@ -134,7 +134,7 @@ namespace Rokojori
c.SetCharacterController( this );
Action.Trigger( c );
Action.TriggerSafe( c );
}
);

View File

@ -198,11 +198,11 @@ namespace Rokojori
{
if ( _moving )
{
Trigger( onStartedMoving );
TriggerSafe( onStartedMoving );
}
else
{
Trigger( onStoppedMoving );
TriggerSafe( onStoppedMoving );
}
}

View File

@ -110,7 +110,7 @@ namespace Rokojori
jumping = true;
jumpStart = TimeLine.osTime;
Trigger( onJump );
TriggerSafe( onJump );
jumpDirection = Vector3.Up * strength.GetJumpStrength( this );

View File

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

View File

@ -107,11 +107,11 @@ namespace Rokojori
if ( this.grabber != null )
{
Action.Trigger( onGrab );
Action.TriggerSafe( onGrab );
}
else
{
Action.Trigger( onRelease );
Action.TriggerSafe( onRelease );
}
}

View File

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

View File

@ -49,7 +49,7 @@ namespace Rokojori
return;
}
Action.Trigger( interactable.onInteraction );
Action.TriggerSafe( interactable.onInteraction );
}
}
}

View File

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

View File

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

View File

@ -10,6 +10,36 @@ 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
}
}

View File

@ -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;
@ -573,6 +569,8 @@ namespace Rokojori
}
#if !ROKOJORI_ACTION_CORE
public static List<ClipperLib.IntPoint> ToClipperPath( Path2 path, double scale = Path2.DefaultClipperLibraryScale )
{
return Lists.Map(
@ -648,6 +646,6 @@ namespace Rokojori
return s;
}
#endif
}
}

View File

@ -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<ClipperLib.IntPoint>;
using ClipperShape = List<List<ClipperLib.IntPoint>>;
#endif
public enum ShapeFillRule
{
@ -31,194 +36,12 @@ 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<Path2>();
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<List<ClipperLib.IntPoint>> ToClipperPaths( Shape2 s )
{
var paths = new List<List<ClipperLib.IntPoint>>();
s.paths.ForEach( p => paths.Add( Path2.ToClipperPath( p ) ) );
return paths;
}
public static Shape2 FromClipperPaths( List<List<ClipperLib.IntPoint>> 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<Path2> 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<List<ClipperLib.IntPoint>>();
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 )
{
@ -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<Path2>();
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<List<ClipperLib.IntPoint>> ToClipperPaths( Shape2 s )
{
var paths = new List<List<ClipperLib.IntPoint>>();
s.paths.ForEach( p => paths.Add( Path2.ToClipperPath( p ) ) );
return paths;
}
public static Shape2 FromClipperPaths( List<List<ClipperLib.IntPoint>> 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<Path2> 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<List<ClipperLib.IntPoint>>();
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
}
}

View File

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

View File

@ -14,6 +14,8 @@ namespace Rokojori
}
#if !ROKOJORI_ACTION_CORE
public static float ComputeLineDistance( IEnumerable<Vector3> points )
{
return ComputeLineDistance( points, ( p ) => p );
@ -853,7 +855,7 @@ namespace Rokojori
return (Box3) aabb;
}
#endif
}
}

View File

@ -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 )=>

View File

@ -7,10 +7,13 @@ namespace Rokojori
public interface INetworkNode
{
#if !ROKOJORI_ACTION_CORE
List<NetworkNodeMember> GetNetworkNodeMembers();
NetworkTransportType GetNetworkType();
int GetNetworkOwner();
#endif
}
}

View File

@ -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]

View File

@ -48,7 +48,7 @@ namespace Rokojori
collider.TriggerOnCollisionEnter( this, collision );
}
Action.Trigger( onCollision );
Action.TriggerSafe( onCollision );
if ( disableOnCollision )
{

View File

@ -40,11 +40,11 @@ namespace Rokojori
if ( selected )
{
Trigger( onSelected );
TriggerSafe( onSelected );
}
else
{
Trigger( onNotSelected );
TriggerSafe( onNotSelected );
}
}
}

View File

@ -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 )
{

View File

@ -151,7 +151,7 @@ namespace Rokojori
}
Action.Trigger( onActiveDeviceChange );
Action.TriggerSafe( onActiveDeviceChange );
_onActiveDeviceChange.DispatchEvent( null );
}

View File

@ -30,7 +30,7 @@ namespace Rokojori
if ( se.IsDown( sensor ) )
{
Action.Trigger( action );
Action.TriggerSafe( action );
}
}

View File

@ -50,7 +50,7 @@ namespace Rokojori
public Callable RunButton => Callable.From(
()=>
{
Trigger( this );
TriggerSafe( this );
}
);

View File

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

View File

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

View File

@ -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<XMLNode> 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<string>(){ "i", "b", "s", "u" };
var ignoreSet = new HashSet<XMLNode>();
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;
}
}

View File

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

View File

@ -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<string> godotBuiltIn = new HashSet<string>(){
"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<string> 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<string> namespaces = new List<string>{
"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<CSMemberDeclaration>();
walker.Iterate( csClass,
n =>
{
if ( n is CSEnumDeclaration en )
{
var enumType = new GDScriptGeneratorEnum();
enumType.name = en.objectName.match;
var values = en.objectBody.children.FilterType<ASTNode,CSEnumValueDeclaration>( );
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
);
}
}

View File

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

View File

@ -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<GDScriptGeneratorClass> gdClasses = new List<GDScriptGeneratorClass>();
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 );
}
);
}
}

View File

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

View File

@ -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<string> annotations = [];
public string name;
public string doc;
public string extendingClassName;
public List<GDScriptGeneratorMember> 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" );
}
}

View File

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

View File

@ -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<string> values = new List<string>();
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" );
}
}

View File

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

View File

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

View File

@ -1 +0,0 @@
uid://51c533ougel

View File

@ -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<string> annotations = [];
public abstract void Generate( StringBuilder sb );
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 )
{

View File

@ -5,6 +5,7 @@ using System;
namespace Rokojori
{
[RokojoriActionCoreExportCustom]
public static class Arrays
{
public static T[] Concat<T>( T[] a, T[] b )

View File

@ -9,49 +9,137 @@ using System.Linq;
namespace Rokojori
{
public class ListView<T>
{
List<T> _list;
int _offset;
int _length;
public ListView( List<T> 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<T> action )
{
for ( int i = 0; i < _length; i++ )
{
action( this[ i ] );
}
}
public List<T> GetList()
{
return _list;
}
public List<T> SubList()
{
return _list.Sub( _offset, _length );
}
}
[RokojoriActionCoreExportCustom]
public static class Lists
{
public static List<T> Sub<T>( this List<T> elements, int start, int length = 0 )
{
var end = length == 0 ? elements.Count : ( start + length );
var list = new List<T>( end - start );
for ( int i = start; i < end; i++ )
{
list.Add( elements[ i ] );
}
return list;
}
public static List<R> FilterType<T,R>( this List<T> inputList ) where R:T
{
var list = new List<R>();
inputList.ForEach
(
e =>
{
if ( e == null || ! typeof( R ).IsAssignableFrom( e.GetType() ) )
{
return;
}
list.Add( (R) e );
}
);
return list;
}
public static List<T> FilterWithType<T>( this List<T> inputList, Type type )
{
var list = new List<T>();
inputList.ForEach
(
e =>
{
if ( e == null || ! type.IsAssignableFrom( e.GetType() ) )
{
return;
}
list.Add( e );
}
);
return list;
}
public static bool Has<T>( this List<T> list, T item )
{
return list.IndexOf( item ) != - 1;
}
public static void RemoveList<T>( this List<T> list, List<T> removals )
{
var removalSet = new HashSet<T>();
removalSet.UnionWith( removals );
list.RemoveAll( e => removalSet.Contains( e ) );
}
public static List<U> FilterAndMap<T,U>( List<T> list, Func<T,int,bool> filter, Func<T,U> map)
{
var mapped = new List<U>();
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<T>( List<T> a, List<T> b )
{
if ( a.Count != b.Count )
{
return false;
}
for ( int i = 0; i < a.Count; i++ )
{
var isEqual = EqualityComparer<T>.Default.Equals( a[ i ], b[ i ]);
if ( ! isEqual )
{
return false;
}
}
return true;
}
public static List<T> FromEnumerable<T>( IEnumerable enumerable )
{
var listA = new List<T>();
foreach ( var it in enumerable )
{
listA.Add( (T) it );
}
return listA;
}
// ===============================================
// ===============================================
// ===============================================
// ===============================================
// ===============================================
#if !ROKOJORI_ACTION_CORE
public static void Union<T>( this List<T> list, List<T> other )
{
@ -507,20 +595,6 @@ namespace Rokojori
return elements.Sub( start, end - start + 1 );
}
public static List<T> Sub<T>( this List<T> elements, int start, int length = 0 )
{
var end = length == 0 ? elements.Count : ( start + length );
var list = new List<T>( end - start );
for ( int i = start; i < end; i++ )
{
list.Add( elements[ i ] );
}
return list;
}
public static void ShuffleMultiple<T>( this List<T> list, int numShuffles, int step = 2 )
{
@ -575,10 +649,7 @@ namespace Rokojori
return list;
}
public static bool Has<T>( this List<T> list, T item )
{
return list.IndexOf( item ) != - 1;
}
public static T RemoveAt<T>( List<T> list, int index )
{
@ -686,13 +757,6 @@ namespace Rokojori
}
}
public static void RemoveList<T>( this List<T> list, List<T> removals )
{
var removalSet = new HashSet<T>();
removalSet.UnionWith( removals );
list.RemoveAll( e => removalSet.Contains( e ) );
}
public static int CountItems<T>( List<T> list, Predicate<T> test )
{
@ -724,17 +788,6 @@ namespace Rokojori
return result;
}
public static List<T> FromEnumerable<T>( IEnumerable enumerable )
{
var listA = new List<T>();
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<object>( objA as IEnumerable ), FromEnumerable<object>( objB as IEnumerable ) );
}
public static bool AreEntriesEqual<T>( List<T> a, List<T> b )
{
if ( a.Count != b.Count )
{
return false;
}
for ( int i = 0; i < a.Count; i++ )
{
var isEqual = EqualityComparer<T>.Default.Equals( a[ i ], b[ i ]);
if ( ! isEqual )
{
return false;
}
}
return true;
}
/*public static string Join<T>( this List<T> list, string seperator = "," )
@ -881,22 +916,6 @@ namespace Rokojori
}
public static List<U> FilterAndMap<T,U>( List<T> list, Func<T,int,bool> filter, Func<T,U> map)
{
var mapped = new List<U>();
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<List<T>> FilterAsync<T>( this List<T> list, Func<T,Task<bool>> filter )
{
@ -976,45 +995,7 @@ namespace Rokojori
}
public static List<R> FilterType<T,R>( this List<T> inputList ) where R:T
{
var list = new List<R>();
inputList.ForEach
(
e =>
{
if ( e == null || ! typeof( R ).IsAssignableFrom( e.GetType() ) )
{
return;
}
list.Add( (R) e );
}
);
return list;
}
public static List<T> FilterType<T>( this List<T> inputList, Type type )
{
var list = new List<T>();
inputList.ForEach
(
e =>
{
if ( e == null || ! type.IsAssignableFrom( e.GetType() ) )
{
return;
}
list.Add( e );
}
);
return list;
}
public static void Add<T>( this List<T> list, params T[] entries )
{
@ -1211,6 +1192,49 @@ namespace Rokojori
return list;
}
#endif
}
public class ListView<T>
{
List<T> _list;
int _offset;
int _length;
public ListView( List<T> 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<T> action )
{
for ( int i = 0; i < _length; i++ )
{
action( this[ i ] );
}
}
public List<T> GetList()
{
return _list;
}
public List<T> SubList()
{
return _list.Sub( _offset, _length );
}
}
}

View File

@ -9,6 +9,8 @@ namespace Rokojori
{
public static class ReflectionHelper
{
#if !ROKOJORI_ACTION_CORE
public static List<Tuple<string,string>> GetExportedMembersAsJSON( object obj )
{
var type = obj.GetType();
@ -576,5 +578,7 @@ namespace Rokojori
);
}
#endif
}
}

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More