@@ -21,46 +21,39 @@ public class Marshallable<T> : Reference where T: class
21
21
22
22
public static class GodotExtensions
23
23
{
24
- public static Entity Spawn ( this World world , Node root )
24
+ public static EntityBuilder Spawn ( this World world , Node root )
25
25
{
26
- var entity = world . Spawn ( ) ;
27
- world . AttachNode ( entity , root ) ;
28
- return entity ;
26
+ return world . Spawn ( ) . Attach ( root ) ;
27
+ }
28
+
29
+ public static void DespawnAndFree ( this World world , Entity entity )
30
+ {
31
+ if ( world . TryGetComponent < Root > ( entity , out var root ) ) root . Node . QueueFree ( ) ;
32
+ world . Despawn ( entity ) ;
29
33
}
30
34
31
35
public static void AttachNode ( this World world , Entity entity , Node root )
32
36
{
33
- world . AddComponent ( entity . Identity , new Root { Node = root } ) ;
37
+ world . AddComponent ( entity , new Root { Node = root } ) ;
34
38
root . SetMeta ( "Entity" , new Marshallable < Entity > ( entity ) ) ;
35
39
36
40
var nodes = root . GetChildren ( ) . Cast < Node > ( ) . Prepend ( root ) . ToList ( ) ;
37
41
38
42
foreach ( var node in nodes )
39
43
{
40
- var addMethod = typeof ( GodotExtensions ) . GetMethod ( " AddNodeComponent" ) ;
44
+ var addMethod = typeof ( GodotExtensions ) . GetMethod ( nameof ( AddNodeComponent ) ) ;
41
45
var addChildMethod = addMethod ? . MakeGenericMethod ( node . GetType ( ) ) ;
42
46
addChildMethod ? . Invoke ( null , new object [ ] { world , entity , node } ) ;
43
47
}
44
48
45
- if ( root is ISpawnable spawnable ) spawnable . Spawn ( new EntityBuilder ( world , entity . Identity ) ) ;
49
+ if ( root is ISpawnable spawnable ) spawnable . Spawn ( new EntityBuilder ( world , entity ) ) ;
46
50
}
47
51
48
52
public static void AddNodeComponent < T > ( World world , Entity entity , T node ) where T : Node , new ( )
49
53
{
50
- world . AddComponent ( entity . Identity , node ) ;
51
- }
52
-
53
- public static EntityBuilder Spawn ( this ISystem system , Node node )
54
- {
55
- return new EntityBuilder ( system . World , system . World . Spawn ( node ) . Identity ) ;
54
+ world . AddComponent ( entity , node ) ;
56
55
}
57
-
58
- public static void DespawnAndFree ( this ISystem system , Entity entity )
59
- {
60
- if ( system . TryGetComponent < Root > ( entity , out var root ) ) root . Node . QueueFree ( ) ;
61
- system . Despawn ( entity ) ;
62
- }
63
-
56
+
64
57
public static EntityBuilder Attach ( this EntityBuilder entityBuilder , Node node )
65
58
{
66
59
entityBuilder . World . AttachNode ( entityBuilder . Id ( ) , node ) ;
0 commit comments