diff --git a/src/Features/Items/Contracts/ItemInstanceId.cs b/src/Features/Items/Contracts/ItemInstanceId.cs index 442b243..4010708 100644 --- a/src/Features/Items/Contracts/ItemInstanceId.cs +++ b/src/Features/Items/Contracts/ItemInstanceId.cs @@ -1,8 +1,10 @@ -using System; +using Game.Shared.Domain; namespace Game.Features.Items.Contracts; -public readonly record struct ItemInstanceId(Guid Value) +public readonly record struct ItemInstanceId(InstanceId Value) { + public static ItemInstanceId From(InstanceId value) => new(value); + public override string ToString() => Value.ToString(); } diff --git a/src/Features/Items/Godot/ItemSpawnerController.cs b/src/Features/Items/Godot/ItemSpawnerController.cs index c06ec13..edbcccc 100644 --- a/src/Features/Items/Godot/ItemSpawnerController.cs +++ b/src/Features/Items/Godot/ItemSpawnerController.cs @@ -68,7 +68,6 @@ public partial class ItemSpawnerController : Node, IItemSpawner } WorldItemController item = scene.Instantiate(); - item.InstanceId = Guid.NewGuid().ToString(); ItemsRoot.AddChild(item); item.GlobalPosition = worldPosition; ItemWorld.Register(item); diff --git a/src/Features/Items/Godot/WorldItemController.cs b/src/Features/Items/Godot/WorldItemController.cs index 87c0b05..ccd27d2 100644 --- a/src/Features/Items/Godot/WorldItemController.cs +++ b/src/Features/Items/Godot/WorldItemController.cs @@ -10,7 +10,7 @@ public partial class WorldItemController : RigidBody3D, IPickupTarget { public const string ItemGroup = "world_items"; - [Export] public string InstanceId; + [Export] public string Key; [Export] public string DefinitionId = "item"; [Export] public string DisplayName = "Item"; [Export] public HandRequirement HandRequirement = HandRequirement.One; @@ -41,13 +41,9 @@ public partial class WorldItemController : RigidBody3D, IPickupTarget throw new InvalidOperationException($"{Name}: held view scene is not assigned."); } - Guid id = string.IsNullOrWhiteSpace(InstanceId) - ? Guid.NewGuid() - : Guid.Parse(InstanceId); - Definition = new ItemDefinition(new ItemDefinitionId(DefinitionId), DisplayName, HandRequirement); ItemInfo = new ItemInfo( - new ItemInstanceId(id), + ItemInstanceId.From(this.GetStableInstanceIdFrom(Key)), Definition.Id, Definition.DisplayName, Definition.HandRequirement diff --git a/src/Godot/Scenes/GameWorld.tscn b/src/Godot/Scenes/GameWorld.tscn index dca6016..5dcf1c0 100644 --- a/src/Godot/Scenes/GameWorld.tscn +++ b/src/Godot/Scenes/GameWorld.tscn @@ -89,8 +89,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4, 0, 0) [node name="FlashlightLeft" parent="Entities" instance=ExtResource("7_flashlight")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.25, 0.65, -0.7) -InstanceId = "c08790de-b2de-44e6-a73c-a7502ca27e34" [node name="FlashlightRight" parent="Entities" instance=ExtResource("7_flashlight")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0.65, -0.7) -InstanceId = "f71e67cb-786b-49eb-bd56-cb42ad19a754"