Move runtime item references to typed keys

This commit is contained in:
Meta Vens 2026-06-14 22:58:02 +01:00
commit 8337d5f5c7
9 changed files with 153 additions and 60 deletions

Binary file not shown.

View file

@ -81,8 +81,10 @@ Dead legacy catalog roots for user records and galaxy map-layer resources have
been deleted from live Unity source. Surviving runtime DTOs no longer carry
legacy catalog group/table annotations; their remaining metadata is projection
and inspection metadata for the typed runtime bridge.
Item instances now carry `RuntimeItemDefinitionReference`, a narrow
item-definition id.
Item instances now carry `AetheriaRuntimeItemReference`, a typed item-key
facade. `ItemInstance.ItemKey` is the identity surface, while `ItemId` is a
derived legacy-GUID compatibility projection for unfinished cargo and
simulation paths.
The old generic `RuntimeCatalogLink<T>` abstraction, `ItemManager.GetData`
hydration path, vague `ItemInstance.Data` identity field, and old
`RuntimeItemReference.Projection` cache have been deleted; runtime item facts

View file

@ -5,25 +5,62 @@ using GameCult.Aetheria.State.Unity;
public interface IRuntimeItemCatalogReader
{
AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey);
AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid);
}
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
{
private readonly Dictionary<Guid, AetheriaRuntimeCatalogItem> _typedItems;
private const string ItemDefinitionPrefix = "aetheria.item_definition:";
private const string LegacyItemDefinitionPrefix = "aetheria.item_definition:legacy:";
private readonly Dictionary<string, AetheriaRuntimeCatalogItem> _typedItemsByKey;
private readonly Dictionary<Guid, AetheriaRuntimeCatalogItem> _typedItemsByLegacyId;
public AetheriaRuntimeItemCatalog(AetheriaRuntimeCatalogSnapshot catalog)
{
if (catalog == null) throw new ArgumentNullException(nameof(catalog));
_typedItems = catalog.Items
_typedItemsByKey = catalog.Items
.Where(item => !string.IsNullOrWhiteSpace(item.LegacyId))
.ToDictionary(item => ToItemKey(item.LegacyId), item => item, StringComparer.OrdinalIgnoreCase);
_typedItemsByLegacyId = catalog.Items
.Where(item => Guid.TryParse(item.LegacyId, out _))
.ToDictionary(item => Guid.Parse(item.LegacyId), item => item);
}
public AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey)
{
if (string.IsNullOrWhiteSpace(itemKey))
return null;
if (_typedItemsByKey.TryGetValue(itemKey, out var item))
return item;
return Guid.TryParse(RemoveItemPrefix(itemKey), out var legacyId)
? GetRuntimeItem(legacyId)
: null;
}
public AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid)
{
_typedItems.TryGetValue(guid, out var item);
_typedItemsByLegacyId.TryGetValue(guid, out var item);
return item;
}
private static string ToItemKey(string legacyId)
{
return string.IsNullOrWhiteSpace(legacyId) ? "" : $"{LegacyItemDefinitionPrefix}{legacyId}";
}
private static string RemoveItemPrefix(string itemKey)
{
if (itemKey.StartsWith(LegacyItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase))
return itemKey.Substring(LegacyItemDefinitionPrefix.Length);
return itemKey.StartsWith(ItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(ItemDefinitionPrefix.Length)
: itemKey;
}
}

View file

@ -0,0 +1,60 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using Unity.Mathematics;
public interface INamedEntry
{
string EntryName { get; set; }
}
public class AetheriaRuntimeItemReference
{
private const string ItemDefinitionPrefix = "aetheria.item_definition:";
private const string LegacyItemDefinitionPrefix = "aetheria.item_definition:legacy:";
public string ItemKey;
public AetheriaRuntimeItemReference()
{
}
public AetheriaRuntimeItemReference(string itemKey)
{
ItemKey = itemKey;
}
public AetheriaRuntimeItemReference(Guid legacyItemId)
: this(FromLegacyId(legacyItemId))
{
}
public Guid LegacyItemId => TryParseLegacyId(ItemKey, out var itemId) ? itemId : Guid.Empty;
public static string FromLegacyId(Guid legacyItemId)
{
return legacyItemId == Guid.Empty ? "" : $"{LegacyItemDefinitionPrefix}{legacyItemId:D}";
}
private static bool TryParseLegacyId(string itemKey, out Guid itemId)
{
itemId = Guid.Empty;
if (string.IsNullOrWhiteSpace(itemKey))
return false;
var legacyId = itemKey.StartsWith(LegacyItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(LegacyItemDefinitionPrefix.Length)
: itemKey.StartsWith(ItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(ItemDefinitionPrefix.Length)
: itemKey;
return Guid.TryParse(legacyId, out itemId);
}
}
public interface ITintInspector
{
float3 TintColor { get; }
}

View file

@ -12,10 +12,11 @@ using static Unity.Mathematics.math;
public abstract class ItemInstance
{
public RuntimeItemDefinitionReference Reference;
public AetheriaRuntimeItemReference Reference;
public ItemRotation Rotation;
public Guid ItemId => Reference?.ItemId ?? Guid.Empty;
public string ItemKey => Reference?.ItemKey ?? "";
public Guid ItemId => Reference?.LegacyItemId ?? Guid.Empty;
}
public abstract class CraftedItemInstance : ItemInstance

View file

@ -52,7 +52,11 @@ public class ItemManager
public AetheriaRuntimeCatalogItem GetRuntimeItem(ItemInstance item)
{
return GetRuntimeItem(item?.ItemId ?? Guid.Empty);
return item == null
? null
: !string.IsNullOrWhiteSpace(item.ItemKey)
? _runtimeItems.GetRuntimeItem(item.ItemKey)
: GetRuntimeItem(item.ItemId);
}
public AetheriaRuntimeCatalogItem GetRuntimeItem(Guid itemId)
@ -532,9 +536,21 @@ public class ItemManager
return shape;
}
public RuntimeItemDefinitionReference CreateReference(Guid itemId)
public AetheriaRuntimeItemReference CreateReference(AetheriaRuntimeCatalogItem item)
{
return new RuntimeItemDefinitionReference(itemId);
return new AetheriaRuntimeItemReference(ToItemKey(item));
}
public AetheriaRuntimeItemReference CreateReference(Guid itemId)
{
return new AetheriaRuntimeItemReference(itemId);
}
private static string ToItemKey(AetheriaRuntimeCatalogItem item)
{
return item != null && Guid.TryParse(item.LegacyId, out var itemId)
? AetheriaRuntimeItemReference.FromLegacyId(itemId)
: "";
}
public void Log(string s)
@ -628,7 +644,7 @@ public class ItemManager
{
return new SimpleCommodity
{
Reference = CreateReference(itemId),
Reference = CreateReference(item),
Quantity = count
};
}
@ -674,14 +690,14 @@ public class ItemManager
{
return new ConsumableItem
{
Reference = CreateReference(itemId),
Reference = CreateReference(item),
Quality = quality
};
}
return new CompoundCommodity
{
Reference = CreateReference(itemId),
Reference = CreateReference(item),
Quality = quality
};
}
@ -701,7 +717,7 @@ public class ItemManager
return new EquippableItem
{
Reference = CreateReference(itemId),
Reference = CreateReference(item),
Quality = quality,
Durability = item.Durability > 0 ? (float)item.Durability : 1f
};

View file

@ -1,30 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using Unity.Mathematics;
public interface INamedEntry
{
string EntryName { get; set; }
}
public class RuntimeItemDefinitionReference
{
public Guid ItemId;
public RuntimeItemDefinitionReference()
{
}
public RuntimeItemDefinitionReference(Guid itemId)
{
ItemId = itemId;
}
}
public interface ITintInspector
{
float3 TintColor { get; }
}

View file

@ -52,8 +52,8 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
the provider-owned Eve command bridge on startup and on a daemon polling loop
while hosting the CultMesh state node. `Aetheria.State.ApplyPending` remains a
bounded local operator applicator for both pending lanes.
- Shared item domain state is still partly built around `RuntimeItemDefinitionReference`,
`ItemData`, `BehaviorData`, GUID identity, and runtime catalog metadata. Dead
- Shared item domain state is still partly built around `AetheriaRuntimeItemReference`,
`ItemData`, `RuntimeBehaviorConfig`, derived GUID compatibility, and runtime catalog metadata. Dead
user-record and galaxy-map-layer catalog roots have been deleted, and
surviving runtime DTOs no longer carry legacy catalog group/table annotations. Newtonsoft,
JsonKnownTypes, RethinkDB, LiteNetLib client transport, and the broken
@ -204,8 +204,8 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
- `ActionGameManager` opens `AetheriaRuntimeCatalogStore` over
`aetheria-world.cc`, projects it through `AetheriaRuntimeItemCatalog`, and
gives `ItemManager` explicit item lookup authority. Item instances carry
`RuntimeItemDefinitionReference`, an item-definition id, not a process-global catalog
resolver, hydrated projection cache, or durable item-data owner. The old
`AetheriaRuntimeItemReference`, a typed item key, not a process-global catalog
resolver, hydrated projection cache, bare GUID owner, or durable item-data owner. The old
`LegacyItemCatalogBoundary`,
`LegacyItemCatalogCache`, and runtime MessagePack deserializer path have been
deleted. The old `DatabaseEntry`/`RuntimeCatalogEntry`/`RuntimeItemProjectionEntry`
@ -354,8 +354,8 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
`Faction` DTOs, including allegiance edges, for the existing simulation shape
and resolves full name arrays from `aetheria.name_file.v2` records. The
runtime no longer opens the old `GameData/NameFile/*.msgpack` directory.
- Item instances carry `RuntimeItemDefinitionReference`, a narrow item-definition id
resolved by `ItemManager` against the typed runtime item catalog projected
- Item instances carry `AetheriaRuntimeItemReference`, a typed item key resolved
by `ItemManager` against the typed runtime item catalog projected
from `aetheria-world.cc`. Runtime item references no longer carry hydrated DTO
projection caches or global link-resolution authority. MessagePack catalog construction no longer grabs global link-resolution
authority, and the old generic `RuntimeCatalogLink<T>` abstraction is gone.
@ -618,8 +618,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
config reads no longer escape `ItemManager`;
gameplay stat modifiers target live behavior instances and package-owned
behavior metadata instead of rebuilding config DTOs for lookup.
`ItemInstance.ItemId` is the runtime identity surface and
`ItemInstance.Reference` is the explicit item-reference API;
`ItemInstance.Reference` stores the typed item key, `ItemInstance.ItemKey`
is the runtime identity surface, and `ItemInstance.ItemId` is a derived
legacy-GUID compatibility projection;
there is no remaining `ItemInstance.Data` identity/backing field. The reader interface for this
bridge is named `IRuntimeItemCatalogReader` and exposes only typed catalog
row lookup. Behavior
@ -1197,8 +1198,10 @@ First Aetheria surfaces to publish:
- Done: remove the stale `MessagePack` assembly reference from
`Aetheria.Shared.Unity`; the remaining MessagePack reference is contained
in the typed state package's `.cc` reader.
- Convert domain references from GUID/base-class patterns to typed record
refs.
- In progress: convert domain references from GUID/base-class patterns to
typed record refs. Item instances now carry typed item keys; remaining
cargo/simulation dictionaries still derive legacy GUIDs until those
structures move to typed keys.
- Remove runtime dependency on `ItemData` DTOs as item instance owners.
5. Mesh host
@ -1300,17 +1303,21 @@ First Aetheria surfaces to publish:
- Done: demote `RuntimeItemReference.Value` to an item-definition id, then
delete `RuntimeItemReference.Projection`; item references no longer carry
hydrated `ItemData` DTOs.
- Done: add `ItemInstance.ItemId` as the direct runtime identity surface and
move live runtime/UI/catalog lookup call sites off `.Data.ItemId`. The old
`Data` field is now compatibility backing state rather than the identity
API callers use.
- Done: add `ItemInstance.ItemId` as an intermediate runtime identity
surface and move live runtime/UI/catalog lookup call sites off
`.Data.ItemId`. The old `Data` field became compatibility backing state
before it was deleted.
- Done: add `ItemInstance.Reference` as the explicit item-reference API and
move factories/cargo stacking off direct `.Data` comparisons and
assignments.
- Done: rename `RuntimeItemReference` to
`RuntimeItemDefinitionReference` and delete the `ItemInstance.Data`
compatibility field; item instances now expose item identity through
`Reference` and `ItemId` only.
compatibility field; this was the intermediate reference shape before
typed item keys became the owner.
- Done: rename `RuntimeItemDefinitionReference` to
`AetheriaRuntimeItemReference` and make the reference typed-key-first.
`ItemInstance.ItemKey` is now the primary identity surface; `ItemId` is
derived legacy compatibility for unfinished cargo and simulation paths.
- Done: delete the dead `ItemManager.GetRuntimeItemProjection<T>` bridge
after loadout generation stopped hydrating selected typed rows into
`EquippableItemData` merely to instantiate equipment.