Skip to content

Commit 2f31b76

Browse files
committed
Add Name component
1 parent 747cd76 commit 2f31b76

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Entity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ref T GetOrAdd<T>() where T : struct
6767
}
6868
public void Delete() => CurrentScene.DeleteEntity(this);
6969

70-
public override string ToString() => $"Entity {Id} (v{Version})";
70+
public override string ToString() => Has<NameComponent>() ? Get<NameComponent>().Name : $"EID {Id} (v{Version})";
7171

7272
public override bool Equals(object? obj) => obj is Entity other && this == other;
7373
public override int GetHashCode() => (int)(BitOperations.RotateLeft((uint)Id, 16) ^ Version);

src/NameComponent.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SimpleECS
2+
{
3+
public struct NameComponent
4+
{
5+
public string Name;
6+
public NameComponent(string name) => Name = name;
7+
}
8+
}

0 commit comments

Comments
 (0)