Skip to content

Commit b251783

Browse files
committed
update to work with newest RelEcs changes
1 parent 60902e7 commit b251783

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/Godot.cs

+13-20
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,39 @@ public class Marshallable<T> : Reference where T: class
2121

2222
public static class GodotExtensions
2323
{
24-
public static Entity Spawn(this World world, Node root)
24+
public static EntityBuilder Spawn(this World world, Node root)
2525
{
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);
2933
}
3034

3135
public static void AttachNode(this World world, Entity entity, Node root)
3236
{
33-
world.AddComponent(entity.Identity, new Root { Node = root });
37+
world.AddComponent(entity, new Root { Node = root });
3438
root.SetMeta("Entity", new Marshallable<Entity>(entity));
3539

3640
var nodes = root.GetChildren().Cast<Node>().Prepend(root).ToList();
3741

3842
foreach (var node in nodes)
3943
{
40-
var addMethod = typeof(GodotExtensions).GetMethod("AddNodeComponent");
44+
var addMethod = typeof(GodotExtensions).GetMethod(nameof(AddNodeComponent));
4145
var addChildMethod = addMethod?.MakeGenericMethod(node.GetType());
4246
addChildMethod?.Invoke(null, new object[] { world, entity, node });
4347
}
4448

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));
4650
}
4751

4852
public static void AddNodeComponent<T>(World world, Entity entity, T node) where T : Node, new()
4953
{
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);
5655
}
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+
6457
public static EntityBuilder Attach(this EntityBuilder entityBuilder, Node node)
6558
{
6659
entityBuilder.World.AttachNode(entityBuilder.Id(), node);

0 commit comments

Comments
 (0)