refactor: unify item instance ids with the shared stable-id scheme
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using Game.Shared.Domain;
|
||||||
|
|
||||||
namespace Game.Features.Items.Contracts;
|
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();
|
public override string ToString() => Value.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ public partial class ItemSpawnerController : Node, IItemSpawner
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorldItemController item = scene.Instantiate<WorldItemController>();
|
WorldItemController item = scene.Instantiate<WorldItemController>();
|
||||||
item.InstanceId = Guid.NewGuid().ToString();
|
|
||||||
ItemsRoot.AddChild(item);
|
ItemsRoot.AddChild(item);
|
||||||
item.GlobalPosition = worldPosition;
|
item.GlobalPosition = worldPosition;
|
||||||
ItemWorld.Register(item);
|
ItemWorld.Register(item);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public partial class WorldItemController : RigidBody3D, IPickupTarget
|
|||||||
{
|
{
|
||||||
public const string ItemGroup = "world_items";
|
public const string ItemGroup = "world_items";
|
||||||
|
|
||||||
[Export] public string InstanceId;
|
[Export] public string Key;
|
||||||
[Export] public string DefinitionId = "item";
|
[Export] public string DefinitionId = "item";
|
||||||
[Export] public string DisplayName = "Item";
|
[Export] public string DisplayName = "Item";
|
||||||
[Export] public HandRequirement HandRequirement = HandRequirement.One;
|
[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.");
|
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);
|
Definition = new ItemDefinition(new ItemDefinitionId(DefinitionId), DisplayName, HandRequirement);
|
||||||
ItemInfo = new ItemInfo(
|
ItemInfo = new ItemInfo(
|
||||||
new ItemInstanceId(id),
|
ItemInstanceId.From(this.GetStableInstanceIdFrom(Key)),
|
||||||
Definition.Id,
|
Definition.Id,
|
||||||
Definition.DisplayName,
|
Definition.DisplayName,
|
||||||
Definition.HandRequirement
|
Definition.HandRequirement
|
||||||
|
|||||||
@@ -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")]
|
[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)
|
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")]
|
[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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0.65, -0.7)
|
||||||
InstanceId = "f71e67cb-786b-49eb-bd56-cb42ad19a754"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user