refactor: remove Source property from IRelationship

Remove the redundant `Source` property from `IRelationship` and its
implementations. Since the relationship component is inherently
stored on the source entity, the `Source` field was unnecessary and
required manual synchronization during deserialization.

This change simplifies the relationship model, reduces memory usage,
and removes the need for reflection-based fixups in the serializer.
This commit is contained in:
2026-07-20 22:59:27 +08:00
parent 2de735498c
commit 91c6f4aa2c
21 changed files with 39 additions and 98 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ public struct HitCommand : ICommand
// Remove from deck, add to hand.
world.RemoveComponent<InDeck>(cardEntity);
world.AddComponent(cardEntity, new Holds { Source = cardEntity, Target = handEntity });
world.AddComponent(cardEntity, new Holds { Target = handEntity });
}
internal static Entity FindEntity<T>(World world, Entity singletonEntity)
+1 -1
View File
@@ -42,7 +42,7 @@ public struct NewRoundCommand : ICommand
foreach (var card in cards)
{
world.RemoveComponent<Holds>(card);
world.AddComponent(card, new InDeck { Source = card, Target = deckEntity });
world.AddComponent(card, new InDeck { Target = deckEntity });
}
}
+1 -2
View File
@@ -10,6 +10,5 @@ namespace Game.Blackjack;
[MessagePackObject]
public record struct Holds : IRelationship
{
[Key(0)] public Entity Source { get; set; }
[Key(1)] public Entity Target { get; set; }
[Key(0)] public Entity Target { get; set; }
}
+1 -2
View File
@@ -10,6 +10,5 @@ namespace Game.Blackjack;
[MessagePackObject]
public record struct InDeck : IRelationship
{
[Key(0)] public Entity Source { get; set; }
[Key(1)] public Entity Target { get; set; }
[Key(0)] public Entity Target { get; set; }
}
+2 -2
View File
@@ -36,7 +36,7 @@ public class DeckSetupSystem : ISystem
{
var cardEntity = world.CreateEntity();
world.AddComponent(cardEntity, new Card { Suit = suit, Rank = rank });
world.AddComponent(cardEntity, new InDeck { Source = cardEntity, Target = deckEntity });
world.AddComponent(cardEntity, new InDeck { Target = deckEntity });
}
}
@@ -81,7 +81,7 @@ public class DeckSetupSystem : ISystem
}
for (int i = 0; i < cardEntities.Length; i++)
{
world.AddComponent(cardEntities[i], new InDeck { Source = cardEntities[i], Target = deckEntity });
world.AddComponent(cardEntities[i], new InDeck { Target = deckEntity });
}
}
}