diff --git a/Runtime/Godot/Generated/ExtendingClasses/ExtendingControlClassList.cs b/Runtime/Godot/Generated/ExtendingClasses/ExtendingControlClassList.cs new file mode 100644 index 0000000..25dce28 --- /dev/null +++ b/Runtime/Godot/Generated/ExtendingClasses/ExtendingControlClassList.cs @@ -0,0 +1,90 @@ +using Godot; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + /* + + Match: [ (\w+)] + Replace: [ "$1",] + + */ + + public class ExtendingControlGodotClassList + { + public static List list = new List + { + "AspectRatioContainer", + "BaseButton", + "BoxContainer", + "Button", + "CenterContainer", + "CheckBox", + "CheckButton", + "CodeEdit", + "ColorPicker", + "ColorPickerButton", + "ColorRect", + "Container", + "EditorInspector", + "EditorProperty", + "EditorResourcePicker", + "EditorScriptPicker", + "EditorSpinSlider", + "FileSystemDock", + "FlowContainer", + "GraphEdit", + "GraphElement", + "GraphNode", + "GridContainer", + "HBoxContainer", + "HFlowContainer", + "HScrollBar", + "HSeparator", + "HSlider", + "HSplitContainer", + "ItemList", + "Label", + "LineEdit", + "LinkButton", + "MarginContainer", + "MenuBar", + "MenuButton", + "NinePatchRect", + "OptionButton", + "Panel", + "PanelContainer", + "ProgressBar", + "Range", + "ReferenceRect", + "RichTextLabel", + "ScriptEditor", + "ScriptEditorBase", + "ScrollBar", + "ScrollContainer", + "Separator", + "Slider", + "SpinBox", + "SplitContainer", + "SubViewportContainer", + "TabBar", + "TabContainer", + "TextEdit", + "TextureButton", + "TextureProgressBar", + "TextureRect", + "Tree", + "VBoxContainer", + "VFlowContainer", + "VScrollBar", + "VSeparator", + "VSlider", + "VSplitContainer", + "VideoStreamPlayer", + }; + + } +} + + diff --git a/Runtime/Godot/Generated/ExtendingClasses/ExtendingNode2DClassList.cs b/Runtime/Godot/Generated/ExtendingClasses/ExtendingNode2DClassList.cs new file mode 100644 index 0000000..41a2656 --- /dev/null +++ b/Runtime/Godot/Generated/ExtendingClasses/ExtendingNode2DClassList.cs @@ -0,0 +1,69 @@ +using Godot; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + + /* + + Match: [ (\w+)] + Replace: [ "$1",] + + */ + public class ExtendingNode2DGodotClassList + { + public static List list = new List + { + "AnimatableBody2D", + "AnimatedSprite2D", + "Area2D", + "AudioListener2D", + "AudioStreamPlayer2D", + "BackBufferCopy", + "Bone2D", + "CPUParticles2D", + "Camera2D", + "CanvasGroup", + "CanvasModulate", + "CharacterBody2D", + "CollisionObject2D", + "CollisionPolygon2D", + "CollisionShape2D", + "DampedSpringJoint2D", + "DirectionalLight2D", + "GPUParticles2D", + "GrooveJoint2D", + "Joint2D", + "Light2D", + "LightOccluder2D", + "Line2D", + "Marker2D", + "MeshInstance2D", + "MultiMeshInstance2D", + "NavigationLink2D", + "NavigationObstacle2D", + "NavigationRegion2D", + "ParallaxLayer", + "Path2D", + "PathFollow2D", + "PhysicalBone2D", + "PhysicsBody2D", + "PinJoint2D", + "PointLight2D", + "Polygon2D", + "RayCast2D", + "RemoteTransform2D", + "RigidBody2D", + "ShapeCast2D", + "Skeleton2D", + "Sprite2D", + "StaticBody2D", + "TileMap", + "TouchScreenButton", + "VisibleOnScreenEnabler2D", + "VisibleOnScreenNotifier2D" + }; + + } +} \ No newline at end of file diff --git a/Runtime/Godot/Generated/ExtendingClasses/ExtendingNode3DClassList.cs b/Runtime/Godot/Generated/ExtendingClasses/ExtendingNode3DClassList.cs new file mode 100644 index 0000000..76ceebb --- /dev/null +++ b/Runtime/Godot/Generated/ExtendingClasses/ExtendingNode3DClassList.cs @@ -0,0 +1,104 @@ +using Godot; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + /* + + Match: [ (\w+)] + Replace: [ "$1",] + + */ + + public class ExtendingNode3DGodotClassList + { + public static List list = new List + { + "AnimatableBody3D", + "AnimatedSprite3D", + "Area3D", + "AudioListener3D", + "AudioStreamPlayer3D", + "BoneAttachment3D", + "CPUParticles3D", + "CSGBox3D", + "CSGCombiner3D", + "CSGCylinder3D", + "CSGMesh3D", + "CSGPolygon3D", + "CSGPrimitive3D", + "CSGShape3D", + "CSGSphere3D", + "CSGTorus3D", + "Camera3D", + "CharacterBody3D", + "CollisionObject3D", + "CollisionPolygon3D", + "CollisionShape3D", + "ConeTwistJoint3D", + "Decal", + "DirectionalLight3D", + "FogVolume", + "GPUParticles3D", + "GPUParticlesAttractor3D", + "GPUParticlesAttractorBox3D", + "GPUParticlesAttractorSphere3D", + "GPUParticlesAttractorVectorField3D", + "GPUParticlesCollision3D", + "GPUParticlesCollisionBox3D", + "GPUParticlesCollisionHeightField3D", + "GPUParticlesCollisionSDF3D", + "GPUParticlesCollisionSphere3D", + "Generic6DOFJoint3D", + "GeometryInstance3D", + "GridMap", + "HingeJoint3D", + "Joint3D", + "Label3D", + "Light3D", + "LightmapGI", + "LightmapProbe", + "Marker3D", + "MeshInstance3D", + "MultiMeshInstance3D", + "NavigationLink3D", + "NavigationObstacle3D", + "NavigationRegion3D", + "OccluderInstance3D", + "OmniLight3D", + "OpenXRHand", + "Path3D", + "PathFollow3D", + "PhysicalBone3D", + "PhysicsBody3D", + "PinJoint3D", + "RayCast3D", + "ReflectionProbe", + "RemoteTransform3D", + "RigidBody3D", + "RootMotionView", + "ShapeCast3D", + "Skeleton3D", + "SliderJoint3D", + "SoftBody3D", + "SpotLight3D", + "SpringArm3D", + "Sprite3D", + "SpriteBase3D", + "StaticBody3D", + "VehicleBody3D", + "VehicleWheel3D", + "VisibleOnScreenEnabler3D", + "VisibleOnScreenNotifier3D", + "VisualInstance3D", + "VoxelGI", + "XRAnchor3D", + "XRCamera3D", + "XRController3D", + "XRNode3D", + "XROrigin3D" + }; + + } +} \ No newline at end of file diff --git a/Runtime/Godot/Generated/ExtendingGodotClassList.cs b/Runtime/Godot/Generated/ExtendingGodotClassList.cs new file mode 100644 index 0000000..955ec5c --- /dev/null +++ b/Runtime/Godot/Generated/ExtendingGodotClassList.cs @@ -0,0 +1,16 @@ +using Godot; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + public class ExtendingGodotClassList + { + public static List list = Lists.CombineAll( + ExtendingControlGodotClassList.list, + ExtendingNode2DGodotClassList.list, + ExtendingNode3DGodotClassList.list + ); + + } +} \ No newline at end of file diff --git a/Runtime/Godot/Generated/GodotClassGenerator.cs b/Runtime/Godot/Generated/GodotClassGenerator.cs new file mode 100644 index 0000000..b026ba9 --- /dev/null +++ b/Runtime/Godot/Generated/GodotClassGenerator.cs @@ -0,0 +1,96 @@ +using Godot; +using System.Text; +using System.Reflection; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class GodotClassGenerator:Node + { + [Export] + public string outputPath; + + [Export] + public bool exportFlag; + + [Export] + public string testClass; + + public override void _Process( double delta ) + { + if ( exportFlag ) + { + exportFlag = false; + var result = CreateClass( testClass ); + FilesSync.SaveUTF8( outputPath + testClass + ".cs", result ); + } + } + + public string CreateClass( string name ) + { + var output = new StringBuilder(); + + output.Append( "using Godot;\n" ); + output.Append( "\n" ); + output.Append( "namespace Rokojori\n" ); + output.Append( "{\n" ); + output.Append( "\n" ); + + output.Append( " [GlobalClass]\n"); + output.Append( " public partial class RJ" + name + ":" + name + "\n"); + output.Append( " {\n" ); + + var classType = ReflectionHelper.GetTypeByName( name ); + + if ( classType == null ) + { + RJLog.Log( "Type is null" ); + return ""; + } + + output.Append( " \n" ); + var bindingFlags = BindingFlags.Instance | BindingFlags.Public; + EventInfo[] events = classType.GetEvents( bindingFlags ); + + for ( int i = 0; i < events.Length; i++ ) + { + var ev = events[ i ]; + var eventName = ev.Name; + + output.Append( " [Export]\n" ); + output.Append( " public RJAction On" + eventName + ";\n" ); + } + + output.Append( " \n" ); + + output.Append( " public override void _Ready()\n" ); + output.Append( " {\n" ); + + for ( int i = 0; i < events.Length; i++ ) + { + var ev = events[ i ]; + var eventName = ev.Name; + var parameters = ev.GetRaiseMethod().GetParameters(); + var p = "("; + for ( int pn = 0; pn < parameters.Length; pn ++ ) + { + p += "p" + pn; + } + p += ")"; + + + output.Append( " " + eventName + " += " + p + " { Actions.Trigger( On" + eventName +" ); }; \n" ); + } + + output.Append( " }\n" ); + + output.Append( " }\n" ); + + output.Append( "}\n" ); + + + return output.ToString(); + } + } +} \ No newline at end of file diff --git a/Runtime/Godot/Nodes.cs b/Runtime/Godot/Nodes.cs index baa3273..f045fe6 100644 --- a/Runtime/Godot/Nodes.cs +++ b/Runtime/Godot/Nodes.cs @@ -1,11 +1,32 @@ using Godot; using System.Collections.Generic; +using System; namespace Rokojori { public class Nodes { + public static void ForEach( Node root, Action callback ) where T:class + { + var walker = nodesWalker; + + walker.Iterate( root, + ( n )=> + { + var t = n as T; + + if ( t == null ) + { + return; + } + + callback( t ); + + } + ,false ); + } + public static T GetSibling( Node node ) where T:Node { if ( node == null ) @@ -102,7 +123,23 @@ namespace Rokojori public static T GetAnyChild( Node parent ) where T:Node { - return (T) nodesWalker.Find( parent, ( n )=> n is T, true ); + var result = nodesWalker.Find( parent, + ( n )=> + { + + + var castedNode = n as T; + + RJLog.Log( "Testing", n.UniqueNameInOwner, castedNode != null, n.GetType() ); + + return castedNode != null; + + }, + + + true ); + + return (T) result; } /* diff --git a/Runtime/Godot/Root.cs b/Runtime/Godot/Root.cs index 6a15395..b062dd9 100644 --- a/Runtime/Godot/Root.cs +++ b/Runtime/Godot/Root.cs @@ -3,6 +3,7 @@ using Godot; namespace Rokojori { + [Tool] public partial class Root:Node { private static Root _singleton; @@ -14,12 +15,24 @@ namespace Rokojori public static SceneTree Tree() { + if ( _singleton == null ) + { + return null; + } + return _singleton.GetTree(); } public static Window Window() { - return Tree().Root; + var tree = Tree(); + + if ( tree == null) + { + return null; + } + + return tree.Root; } public static Root Get() diff --git a/Runtime/Godot/Unique.cs b/Runtime/Godot/Unique.cs index 9c18488..39095d2 100644 --- a/Runtime/Godot/Unique.cs +++ b/Runtime/Godot/Unique.cs @@ -9,16 +9,29 @@ namespace Rokojori { private static N _singleton; - public static N Get() + public static N Get( Node n = null ) { if ( _singleton != null ) { return _singleton; } - _singleton = Nodes.GetAnyChild( Root.Window() ); + var rootWindow = n == null ? Root.Window() : n.Owner; + + RJLog.Log( "ROOT", rootWindow ); + + if ( rootWindow == null ) + { + return null; + } + + _singleton = Nodes.GetAnyChild( rootWindow ); + + RJLog.Log( "_singleton", _singleton ); return _singleton; } + + } } \ No newline at end of file diff --git a/Runtime/Shading/Library/Colors.gdshaderinc b/Runtime/Shading/Library/Colors.gdshaderinc index 5e2b533..b57281e 100644 --- a/Runtime/Shading/Library/Colors.gdshaderinc +++ b/Runtime/Shading/Library/Colors.gdshaderinc @@ -3,7 +3,7 @@ const float HCV_EPSILON = 1e-10; const float HSL_EPSILON = 1e-10; -vec3 RGBtoHCV( vec3 rgb ) +vec3 RGBtoHCV( vec3 rgb ) { vec4 P = ( rgb.g < rgb.b ) ? vec4( rgb.bg, -1.0, 2.0/3.0 ) : vec4( rgb.gb, 0.0, -1.0/3.0 ); vec4 Q = ( rgb.r < P.x ) ? vec4( P.xyw, rgb.r ) : vec4( rgb.r, P.yzx ); @@ -108,7 +108,7 @@ vec3 HSVtoRGB( vec3 c ) { vec4 K = vec4( 1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0 ); vec3 p = abs( fract( c.xxx + K.xyz ) * 6.0 - K.www ); - + return c.z * mix( K.xxx, clamp( p - K.xxx, 0.0, 1.0 ), c.y ); } @@ -126,17 +126,16 @@ vec4 mix3_v4( vec4 a, vec4 b, vec4 c, float t ) float weightA = mapClamped( t, 0, 0.5, 1, 0 ); float weightB = triangle( t ); float weightC = mapClamped( t, 0.5, 1, 0, 1 ); - - return a * weightA + b * weightB + c * weightC; + + return a * weightA + b * weightB + c * weightC; } vec4 scaleRGB( vec4 rgba, float scale ) { - return vec4( rgba.rgb * scale, rgba.a ); + return vec4( rgba.rgb * scale, rgba.a ); } vec4 fade( vec4 rgba, float fade ) { return vec4( rgba.rgb, rgba.a * fade ); } - diff --git a/Runtime/Tools/Lists.cs b/Runtime/Tools/Lists.cs index f38f7ed..62f1028 100644 --- a/Runtime/Tools/Lists.cs +++ b/Runtime/Tools/Lists.cs @@ -7,6 +7,18 @@ namespace Rokojori { public class Lists { + public static List CombineAll( params List[] lists ) + { + var list = new List(); + + foreach ( var l in lists ) + { + list.AddRange( l ); + } + + return list; + } + public static List ToList( T[] array ) { var list = new List();