Skip to content

Commit

Permalink
Update examples to use id and entity extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanCheeseBurrito committed Nov 18, 2024
1 parent 488cc38 commit a2c355f
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Entities/IterateComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static void IterateComponents(Entity e)
else
{
// Id contains a regular entity. Strip role before printing.
Entity comp = id.Entity();
Entity comp = id.ToEntity();
Console.Write($"Entity: {comp}");
}

Expand Down
14 changes: 7 additions & 7 deletions src/Flecs.NET.Examples/GameMechanics/InventorySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public static void Main()
.Add(Ecs.Exclusive); // Item can only be contained by one container

// Register item kinds
ecs.Component<Sword>().Entity.IsA<Item>();
ecs.Component<Armor>().Entity.IsA<Item>();
ecs.Component<Coin>().Entity.IsA<Item>();
ecs.Component<Sword>().IsA<Item>();
ecs.Component<Armor>().IsA<Item>();
ecs.Component<Coin>().IsA<Item>();

// Register item prefabs
ecs.Prefab<WoodenSword>().Add<Sword>()
Expand Down Expand Up @@ -116,8 +116,8 @@ private static Entity ItemKind(Entity item)
{
// If id is a plain entity (component), check if component inherits
// from Item
if (id.Entity().Has(Ecs.IsA, world.Id<Item>()))
result = id.Entity();
if (id.ToEntity().Has(Ecs.IsA, world.Id<Item>()))
result = id.ToEntity();
}
else if (id.IsPair())
{
Expand Down Expand Up @@ -146,8 +146,8 @@ private static string ItemName(Entity item)
{
if (id.IsEntity())
{
if (id.Entity().Has(Ecs.IsA, world.Id<Item>()))
result = id.Entity().Name();
if (id.ToEntity().Has(Ecs.IsA, world.Id<Item>()))
result = id.ToEntity().Name();
}
else if (id.IsPair())
{
Expand Down
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Prefabs/Basics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Main()
// Make Defense component inheritable. By default, components are copied from
// the instance to the prefab. An inherited component is only stored on the
// prefab, and is shared across all instances.
world.Component<Defense>().Entity.Add(Ecs.OnInstantiate, Ecs.Inherit);
world.Component<Defense>().Add(Ecs.OnInstantiate, Ecs.Inherit);

// Create a SpaceShip prefab with a Defense component.
Entity spaceShip = world.Prefab("SpaceShip")
Expand Down
4 changes: 2 additions & 2 deletions src/Flecs.NET.Examples/Prefabs/Override.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static void Main()
using World world = World.Create();

// Change the instantiation behavior for Attack and Defense to inherit.
world.Component<Attack>().Entity.Add(Ecs.OnInstantiate, Ecs.Inherit);
world.Component<Defense>().Entity.Add(Ecs.OnInstantiate, Ecs.Inherit);
world.Component<Attack>().Add(Ecs.OnInstantiate, Ecs.Inherit);
world.Component<Defense>().Add(Ecs.OnInstantiate, Ecs.Inherit);

// Attack and Defense are properties that can be shared across many
// spaceships. This saves memory, and speeds up prefab creation as we don't
Expand Down
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Queries/ChangeTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Main()
using World world = World.Create();

// Make Dirty inheritable so that queries can match it on prefabs.
world.Component<Dirty>().Entity.Add(Ecs.OnInstantiate, Ecs.Inherit);
world.Component<Dirty>().Add(Ecs.OnInstantiate, Ecs.Inherit);

// Create a query that just reads a component. We'll use this query for
// change tracking. Change tracking for a query is automatically enabled
Expand Down
16 changes: 8 additions & 8 deletions src/Flecs.NET.Examples/Queries/ComponentInheritance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public static void Main()

// Make the ECS aware of the inheritance relationships. Note that IsA
// relationship used here is the same as in the prefab example.
world.Component<CombatUnit>().Entity.IsA<Unit>();
world.Component<MeleeUnit>().Entity.IsA<CombatUnit>();
world.Component<RangedUnit>().Entity.IsA<CombatUnit>();

world.Component<Warrior>().Entity.IsA<MeleeUnit>();
world.Component<Wizard>().Entity.IsA<RangedUnit>();
world.Component<Marksman>().Entity.IsA<RangedUnit>();
world.Component<Builder>().Entity.IsA<Unit>();
world.Component<CombatUnit>().IsA<Unit>();
world.Component<MeleeUnit>().IsA<CombatUnit>();
world.Component<RangedUnit>().IsA<CombatUnit>();

world.Component<Warrior>().IsA<MeleeUnit>();
world.Component<Wizard>().IsA<RangedUnit>();
world.Component<Marksman>().IsA<RangedUnit>();
world.Component<Builder>().IsA<Unit>();

// Create a few units
world.Entity("Warrior1").Add<Warrior>();
Expand Down
12 changes: 6 additions & 6 deletions src/Flecs.NET.Examples/Queries/SettingVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public static void Main()
using World world = World.Create();

// See ComponentInheritance example
world.Component<CombatUnit>().Entity.IsA<Unit>();
world.Component<MeleeUnit>().Entity.IsA<CombatUnit>();
world.Component<RangedUnit>().Entity.IsA<CombatUnit>();
world.Component<CombatUnit>().IsA<Unit>();
world.Component<MeleeUnit>().IsA<CombatUnit>();
world.Component<RangedUnit>().IsA<CombatUnit>();

world.Component<Warrior>().Entity.IsA<MeleeUnit>();
world.Component<Wizard>().Entity.IsA<RangedUnit>();
world.Component<Marksman>().Entity.IsA<RangedUnit>();
world.Component<Warrior>().IsA<MeleeUnit>();
world.Component<Wizard>().IsA<RangedUnit>();
world.Component<Marksman>().IsA<RangedUnit>();

// Populate store with players and platoons
for (int p = 0; p < PlayerCount; p++)
Expand Down
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Queries/TransitiveQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main()
using World world = World.Create();

// Register the LocatedIn relationship as transitive
world.Component<LocatedIn>().Entity.Add(Ecs.Transitive);
world.Component<LocatedIn>().Add(Ecs.Transitive);

// Populate the store with locations
Entity earth = world.Entity("Earth")
Expand Down
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Relationships/ExclusiveRelations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Main()

// Register Platoon as exclusive relationship. This ensures that an entity
// can only belong to a single Platoon.
world.Component<Platoon>().Entity.Add(Ecs.Exclusive);
world.Component<Platoon>().Add(Ecs.Exclusive);

// Create two platoons
Entity platoon1 = world.Entity();
Expand Down
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Relationships/RelationComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void Main()

// You can prevent a pair from assuming the type of a component by adding
// the Tag property to a relationship:
world.Component<MustHave>().Entity.Add(Ecs.PairIsTag);
world.Component<MustHave>().Add(Ecs.PairIsTag);

// Even though Position is a component, <MustHave, Position> contains no
// data because MustHave has the Tag property.
Expand Down
2 changes: 1 addition & 1 deletion src/Flecs.NET.Examples/Relationships/SymmetricRelations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Main()

// Register TradesWith as symmetric relationship. Symmetric relationships
// go both ways, adding (R, B) to A will also add (R, A) to B.
world.Component<TradesWith>().Entity.Add(Ecs.Symmetric);
world.Component<TradesWith>().Add(Ecs.Symmetric);

// Create two players
Entity player1 = world.Entity();
Expand Down
4 changes: 2 additions & 2 deletions src/Flecs.NET.Examples/Relationships/Union.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static void Main()
{
using World world = World.Create();

world.Component<Movement>().Entity.Add(Ecs.Union);
world.Component<Direction>().Entity.Add(Ecs.Union);
world.Component<Movement>().Add(Ecs.Union);
world.Component<Direction>().Add(Ecs.Union);

// Create a query that subscribes for all entities that have a Direction
// and that are walking
Expand Down

0 comments on commit a2c355f

Please sign in to comment.