From 4b8e622e75ee169a7f78b026eff0b20679b7648a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 14 Jun 2026 13:46:08 +0100 Subject: [PATCH] Read typed loadouts into Unity runtime --- .voidbot/state/aetheria.cc | Bin 86336 -> 87079 bytes Aetheria.State.Unity.Smoke/Program.cs | 77 ++++++- Assets/Scripts/Gameplay/ActionGameManager.cs | 122 +++++++++++ .../Runtime/AetheriaRuntimeCatalogSnapshot.cs | 107 +++++++++ .../Runtime/AetheriaRuntimeCatalogStore.cs | 206 ++++++++++++++++++ docs/aetheria-perfect-machine-map.md | 16 +- 6 files changed, 519 insertions(+), 9 deletions(-) diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 4757dbf5c7a93f052685b6f96bb7a105de771fc5..cb4edf6fd3dfd3dabc5d723ffe23578011ef4251 100644 GIT binary patch delta 1710 zcmZ`)&u<(x6qb{wN=k)P1+ zR?B6D;D7`i&>TkM1_+u1NR<%egdhhlTz~_I=D;6NB&75ofM<_q(@?nWdY+%Z_x-Sc z{A}p<&d{AN2Tn{)%{Hg~#>J`YAEU?fp9Vf~E6s@syCMeP?yofM%J8wL2Nv&r^W3qY z|K9!WB&yGhf4GydM9A(+aQ8f6I%F~;p6;eB@M1v%k!epd60`~3DkjgN8<$(xc%-{n zvalOSqM5>qY_kBnYOGn3#&&%}iUiwMcrlChBB3F}O2aq*3mTIs*+)0?gSA>u3&}7S z9cW4dg)11oYk8|`>2FU$2^A8GZ1bwp>j)VKKBYL~THqAGl1=7`4hLW|<2p*A`ZjjYbzHNQwp$QYACA% zH5vz*B<+}Ck^wvk3i!7*xX@=YK*iepTHQlpWG4~bZTp;kBu z!6_^Lm_=u!6>c+1G8n$pxIZryP%bk&5)O&7h`LPUL>TFT@=|67OoKOy)idaH zA?DEdMT2BPDF(f%2pEtAY(xq(z8y)yfel^9N*sz&X;J(&hiZ>>7})|{bVzuOXFJ~4okyXu6xn8I6)H!t z{saf<(8n!d2d$*5{0LOXJ;NygGxYw4nn00Fg;%!gi#7+yz(Ex3Wjx`W*{*C*`pIx6 zc-+OEkO5sLi-*>8QaoB}0Zf`vy9F9Yqi8KZxY@{mA+`Jy`qc6H*G-!8v5%g3_DEe}-ToIElPv~*f*Gw5ybVGPs1i!WcRx?9^()FRK7A3b(l-pjkOzzT z--R|q{~H|`#3sZu33-^B3gh{F@A7Egd#w=!SB)7kNz*t2q@-^IDv~4uTS+ETh=@aD zm8e@&7|Ilm;3jxLes^i~Pqtw43)5@!^Q$C`3< z3+T`M>-phlI*|sa9iirMKV(Fj^4*s%q4&|bi86t0qG_0z;Mjc+U&;3tQM>r+6goLH z*_fT0DZW32#@x^MTIlS^juSx@x5m)fVtfWYS=?`-iIM8WCV6C7p qqaUhwqw&0ZNsbrGOGs49P5ZzUzb~P8`b+kO+0B;G-bjCK`uaZ)pluxh delta 1786 zcmaJ?O^6&t6sC8QxOxx*Sr^5u4>5tjPVdgn?o2WwWV432aa~t;&0!I=QvGJS-R`co zs(Ln)%OH^uNHD|}2E1uB8#NJwhadzr2QPY1kDIdxuigcH)!nsD;?MO})qCIj-uJ!Q zy1x6nk9U7{ZDh1|q*b4G8#CGOmGSKRk&BPmz~S{P&R8ZYXKkcj%Oj(^o*J32e0^xw z4}WIokNN%WgY&3;lmT;BHPZ;3X%>nOu-Jp+T?CcNHsiRZ(kNoGw|(J(`?1&rJd+58 z3Un_)ZzqF9E~KX>%dm=BqI{v@?Uc$P#i_*ez#x&L8+a(IVl$@arlFF>~KJ~^R6r6=+Gf^NV9g8+}ScE(c``X1Wx+P$@TLY$nBCRsgVwUEzH&-Mm8P#xM zF-nBg5K&V!hcGy6s5EUBXr2Xv9<+P;NK_;?Fz*$I??9g}cY|*E()6h)H^OG1eZnp= zCWhJR5J3u|-7Sr=3PgO*X}%T*x(70ibr2b9gD`}U@eOJ@h9HMVQ?W!9Dw#TkQV|Tg z#yV(#Jp{^U61^XU9c)_b~XEFDMd==a3 zgL79Uwzu8v?()8D;@oKV#)}7=+s(E6d}tidgIr>{35Im$4LM?Px#1k31fzQj*=5l; zPoFrJ2BBA|(R$MAc6d7!1~rkma>}y zJi%!qu^u@4oRy{L=2K0C7#T+_fi&^RNnRm+`($Xjl(qtq>Lk_f4K&*)=4c3gKMUV| z<<#;DQ_5z@#ZWFq`}9A}oX@wOdknZw+>!B05)Ngxi(}cF=ck!=T}TQFbbYq6@5AjZ#V zC24M!<;{E|)pB}Qv5VKtSsL6-jq$6c@xKgn8QOcdqFjRe(OA5iq_Tsz$`sWo=+NRK zm)`!Z;xrErem&tF`1>RJsq%#Va%LOm%Nd+}!THvnH}a24RQ3$qMMv0+M~aJg7M*v> VP;)l_u5Q16(z*MvjWwF/1" } }); + AetheriaRuntimeStateCommitLog.QueueLoadoutTemplate( + commitSmokeStatePath, + new AetheriaRuntimeLoadoutTemplateCommit + { + Name = "Unity Smoke Loadout", + OwnerPlayerKey = "global:aetheria.player_settings.v1", + RootEntity = new AetheriaRuntimeEntityLoadoutCommit + { + Name = "Unity Smoke Ship", + Kind = "ship", + CorporationLegacyId = "smoke:faction", + Hull = new AetheriaRuntimeLoadoutItemCommit + { + ItemDefinitionLegacyId = "smoke:hull", + Quality = 0.7, + Durability = 0.6 + }, + Equipment = new[] + { + new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 1, + Y = 2, + Item = new AetheriaRuntimeLoadoutItemCommit + { + ItemDefinitionLegacyId = "smoke:weapon", + Quality = 0.9, + Durability = 0.8 + } + } + }, + CargoContents = new[] + { + new AetheriaRuntimeCargoBayLoadoutCommit + { + Items = new[] + { + new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 3, + Y = 4, + Item = new AetheriaRuntimeLoadoutItemCommit + { + ItemDefinitionLegacyId = "smoke:ore", + Quantity = 5 + } + } + } + } + }, + DockingBayAssignments = new[] { -1 }, + WeaponGroups = new[] { new[] { 0 } } + } + }); AetheriaRuntimeStateCommitLog.QueueRunCheckpoint( commitSmokeStatePath, new AetheriaRuntimeRunCheckpointCommit @@ -297,7 +351,7 @@ try } }); var pending = AetheriaRuntimeStateCommitLog.ReadPending(commitSmokeStatePath); - if (pending.Count != 2 || + if (pending.Count != 3 || pending[0].Kind != AetheriaRuntimeCommitKind.PlayerSettings || pending[0].Schema != AetheriaRuntimeStateCommitLog.CommitSchema || pending[0].Path != commit.Path) @@ -310,13 +364,21 @@ try { var report = await AetheriaRuntimeCommitLogApplier.ApplyPendingAsync(commitNode); var settings = await commitNode.GetPlayerSettingsAsync(); + var loadout = await commitNode.GetLoadoutTemplateAsync(new("global:aetheria.loadout_template.unity-smoke-loadout.v1")); var run = await commitNode.GetRunStateAsync(new("global:aetheria.run_state.smoke-run.v1")); var zone = await commitNode.GetZoneStateAsync(new("global:aetheria.run_state.smoke-run.zone.0.v1")); var entity = await commitNode.GetEntitySnapshotAsync(new("global:aetheria.run_state.smoke-run.zone.0.entity.0.v1")); typedNodeApplied = report.AppliedPlayerSettings == 1 && + report.AppliedLoadoutTemplates == 1 && report.AppliedRunCheckpoints == 1 && settings?.PlayerName == "Unity smoke" && settings.Input.ActionBarInputs.Length == 1 && + loadout?.Name == "Unity Smoke Loadout" && + loadout.RootEntity.Hull.ItemKey == "aetheria.item_definition:legacy:smoke:hull" && + loadout.RootEntity.Equipment.Length == 1 && + loadout.RootEntity.Equipment[0].Position.X == 1 && + loadout.RootEntity.CargoContents.Length == 1 && + loadout.RootEntity.CargoContents[0].Items[0].Item.Quantity == 5 && run?.ZoneKeys.Length == 1 && run.ActionBarBindings.Length == 2 && run.ActionBarBindings[0].ControlPath == "/1" && @@ -349,14 +411,19 @@ try } var packageSettings = AetheriaRuntimeCatalogStore.ReadPlayerSettings(commitSmokeStatePath); + var packageLoadouts = AetheriaRuntimeCatalogStore.ReadLoadoutTemplates(commitSmokeStatePath); if (!typedNodeApplied || packageSettings?.PlayerName != "Unity smoke" || packageSettings.TutorialPassed != true || - packageSettings.ActionBarInputs.Count != 1) + packageSettings.ActionBarInputs.Count != 1 || + packageLoadouts.Count != 1 || + packageLoadouts[0].RootEntity.Hull.ItemKey != "aetheria.item_definition:legacy:smoke:hull" || + packageLoadouts[0].RootEntity.Equipment[0].X != 1 || + packageLoadouts[0].RootEntity.CargoContents[0].Items[0].Item.Quantity != 5) { throw new InvalidOperationException( - "Runtime state commit log did not apply queued settings/run snapshots through the typed state node. " + - $"typedNodeApplied={typedNodeApplied}, packageSettings={(packageSettings == null ? "null" : $"{packageSettings.PlayerName}/{packageSettings.TutorialPassed}/{packageSettings.ActionBarInputs.Count}")}"); + "Runtime state commit log did not apply queued settings/loadout/run snapshots through the typed state node. " + + $"typedNodeApplied={typedNodeApplied}, packageSettings={(packageSettings == null ? "null" : $"{packageSettings.PlayerName}/{packageSettings.TutorialPassed}/{packageSettings.ActionBarInputs.Count}")}, packageLoadouts={packageLoadouts.Count}"); } var eveCommand = AetheriaRuntimeEveCommandLog.QueueCommand( @@ -397,5 +464,5 @@ Console.WriteLine($"Behavior payload sample: {behaviorHost.Name} {behaviorPayloa Console.WriteLine($"Behavior sample: {behaviorKind}"); Console.WriteLine($"Eve surface: {surface.Surface.Id}"); Console.WriteLine($"Package Eve surfaces: {packageSurfaces.Count}"); -Console.WriteLine("Runtime state commit log smoke: settings, action-bar bindings, faction relationships, and run zone/entity snapshots queued, applied, and cleared"); +Console.WriteLine("Runtime state commit log smoke: settings, loadouts, action-bar bindings, faction relationships, and run zone/entity snapshots queued, applied, and cleared"); Console.WriteLine("Runtime Eve command log smoke: surface command queued separately from state commits"); diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index bb566e9f1..06559932d 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -161,6 +161,127 @@ public class ActionGameManager : MonoBehaviour } } + private void LoadRuntimeLoadoutTemplates(string stateFilePath) + { + try + { + var loadouts = AetheriaRuntimeCatalogStore.ReadLoadoutTemplates(stateFilePath); + LoadoutBlueprints.Clear(); + foreach (var loadout in loadouts) + { + var blueprint = CreateRuntimeBlueprint(loadout.RootEntity); + if (blueprint == null) + continue; + + if (string.IsNullOrWhiteSpace(blueprint.Name)) + blueprint.Name = loadout.Name; + + LoadoutBlueprints.Add(blueprint); + } + + if (LoadoutBlueprints.Count > 0) + Debug.Log($"Loaded {LoadoutBlueprints.Count} Aetheria Verse loadout templates from typed state."); + } + catch (FileNotFoundException) + { + } + catch (Exception ex) + { + Debug.LogWarning($"Failed to load Aetheria Verse loadout templates from typed state: {ex}"); + } + } + + private RuntimeEntityBlueprint CreateRuntimeBlueprint(AetheriaRuntimeEntityLoadoutSnapshot entity) + { + var hull = CreateEquippableLoadoutItem(entity.Hull); + if (hull == null) + return null; + + RuntimeEntityBlueprint blueprint = string.Equals(entity.Kind, "orbital", StringComparison.OrdinalIgnoreCase) + ? new RuntimeOrbitalEntityBlueprint() + : new RuntimeShipBlueprint + { + Direction = new float2(0, 1) + }; + + blueprint.Name = entity.Name; + blueprint.Faction = ParseLegacyGuidFromReferenceKey(entity.FactionKey, "aetheria.corporation"); + blueprint.Hull = hull; + blueprint.Equipment = CreateEquippableSlots(entity.Equipment); + blueprint.CargoBays = CreateEquippableSlots(entity.CargoBays); + blueprint.DockingBays = CreateEquippableSlots(entity.DockingBays); + blueprint.CargoContents = CreateCargoBayContents(entity.CargoContents); + blueprint.DockingBayContents = CreateCargoBayContents(entity.DockingBayContents); + blueprint.DockingBayAssignments = entity.DockingBayAssignments.ToArray(); + blueprint.WeaponGroups = entity.WeaponGroups.Select(group => group.ToArray()).ToArray(); + blueprint.Children = entity.Children + .Select(CreateRuntimeBlueprint) + .Where(child => child != null) + .ToArray(); + return blueprint; + } + + private (int2 position, EquippableItem item)[] CreateEquippableSlots( + IReadOnlyList slots) + { + return slots + .Select(slot => (position: new int2(slot.X, slot.Y), item: CreateEquippableLoadoutItem(slot.Item))) + .Where(slot => slot.item != null) + .ToArray(); + } + + private (int2 position, ItemInstance item)[][] CreateCargoBayContents( + IReadOnlyList bays) + { + return bays + .Select(bay => bay.Items + .Select(slot => (position: new int2(slot.X, slot.Y), item: CreateLoadoutItem(slot.Item))) + .Where(slot => slot.item != null) + .ToArray()) + .ToArray(); + } + + private EquippableItem CreateEquippableLoadoutItem(AetheriaRuntimeLoadoutItemSnapshot item) + { + var instance = CreateLoadoutItem(item) as EquippableItem; + if (instance != null && item.Durability > 0) + instance.Durability = (float)item.Durability; + return instance; + } + + private ItemInstance CreateLoadoutItem(AetheriaRuntimeLoadoutItemSnapshot item) + { + var legacyId = ParseLegacyIdFromReferenceKey(item.ItemKey, "aetheria.item_definition"); + var typedItem = RuntimeCatalog?.FindItemByLegacyId(legacyId); + if (typedItem == null) + return null; + + if (typedItem.Stackable) + return ItemManager.CreateSimpleCommodityInstance(typedItem, Math.Max(1, item.Quantity)); + + var instance = ItemManager.CreateCraftedInstance(typedItem, (float)item.Quality); + if (instance is EquippableItem equippable && item.Durability > 0) + equippable.Durability = (float)item.Durability; + return instance; + } + + private static Guid ParseLegacyGuidFromReferenceKey(string key, string documentName) + { + var legacyId = ParseLegacyIdFromReferenceKey(key, documentName); + return Guid.TryParse(legacyId, out var id) ? id : Guid.Empty; + } + + private static string ParseLegacyIdFromReferenceKey(string key, string documentName) + { + if (string.IsNullOrWhiteSpace(key)) + return ""; + + var prefix = $"{documentName}:legacy:"; + return key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) + ? key.Substring(prefix.Length) + : key; + } + public static Galaxy CurrentGalaxy; public static bool IsTutorial; public static AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; private set; } @@ -819,6 +940,7 @@ public class ActionGameManager : MonoBehaviour runtimeItemCatalog, Settings.GameplaySettings, Debug.Log); + LoadRuntimeLoadoutTemplates(stateBoot.StateFilePath); ZoneRenderer.ItemManager = ItemManager; // If hiding minimap asteroids, turn them off to start with diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs index 549d81154..75879f5fb 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs @@ -566,4 +566,111 @@ namespace GameCult.Aetheria.State.Unity public int BindingIndex { get; } public string BindingPath { get; } } + + public sealed class AetheriaRuntimeLoadoutTemplateSnapshot + { + public AetheriaRuntimeLoadoutTemplateSnapshot( + string name, + string ownerPlayerKey, + AetheriaRuntimeEntityLoadoutSnapshot rootEntity, + string createdAtUtc, + string updatedAtUtc) + { + Name = name; + OwnerPlayerKey = ownerPlayerKey; + RootEntity = rootEntity; + CreatedAtUtc = createdAtUtc; + UpdatedAtUtc = updatedAtUtc; + } + + public string Name { get; } + public string OwnerPlayerKey { get; } + public AetheriaRuntimeEntityLoadoutSnapshot RootEntity { get; } + public string CreatedAtUtc { get; } + public string UpdatedAtUtc { get; } + } + + public sealed class AetheriaRuntimeEntityLoadoutSnapshot + { + public AetheriaRuntimeEntityLoadoutSnapshot( + string name, + string kind, + string factionKey, + AetheriaRuntimeLoadoutItemSnapshot hull, + IReadOnlyList equipment, + IReadOnlyList cargoBays, + IReadOnlyList dockingBays, + IReadOnlyList cargoContents, + IReadOnlyList dockingBayContents, + IReadOnlyList dockingBayAssignments, + IReadOnlyList> weaponGroups, + IReadOnlyList children) + { + Name = name; + Kind = kind; + FactionKey = factionKey; + Hull = hull; + Equipment = equipment; + CargoBays = cargoBays; + DockingBays = dockingBays; + CargoContents = cargoContents; + DockingBayContents = dockingBayContents; + DockingBayAssignments = dockingBayAssignments; + WeaponGroups = weaponGroups; + Children = children; + } + + public string Name { get; } + public string Kind { get; } + public string FactionKey { get; } + public AetheriaRuntimeLoadoutItemSnapshot Hull { get; } + public IReadOnlyList Equipment { get; } + public IReadOnlyList CargoBays { get; } + public IReadOnlyList DockingBays { get; } + public IReadOnlyList CargoContents { get; } + public IReadOnlyList DockingBayContents { get; } + public IReadOnlyList DockingBayAssignments { get; } + public IReadOnlyList> WeaponGroups { get; } + public IReadOnlyList Children { get; } + } + + public sealed class AetheriaRuntimeLoadoutItemSnapshot + { + public AetheriaRuntimeLoadoutItemSnapshot(string itemKey, double quality, double durability, int quantity) + { + ItemKey = itemKey; + Quality = quality; + Durability = durability; + Quantity = quantity; + } + + public string ItemKey { get; } + public double Quality { get; } + public double Durability { get; } + public int Quantity { get; } + } + + public sealed class AetheriaRuntimeLoadoutItemSlotSnapshot + { + public AetheriaRuntimeLoadoutItemSlotSnapshot(int x, int y, AetheriaRuntimeLoadoutItemSnapshot item) + { + X = x; + Y = y; + Item = item; + } + + public int X { get; } + public int Y { get; } + public AetheriaRuntimeLoadoutItemSnapshot Item { get; } + } + + public sealed class AetheriaRuntimeCargoBayLoadoutSnapshot + { + public AetheriaRuntimeCargoBayLoadoutSnapshot(IReadOnlyList items) + { + Items = items; + } + + public IReadOnlyList Items { get; } + } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs index 98b7275f9..faf3227ec 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs @@ -17,6 +17,7 @@ namespace GameCult.Aetheria.State.Unity private const string NameFileSchema = "aetheria.name_file"; private const string EveSurfaceSchema = "gamecult.eve.surface"; private const string PlayerSettingsSchema = "aetheria.player_settings"; + private const string LoadoutTemplateSchema = "aetheria.loadout_template"; private const string PlayerSettingsKey = "global:aetheria.player_settings.v1"; public static AetheriaRuntimeCatalogSnapshot OpenReadOnly(string stateFilePath) @@ -86,6 +87,27 @@ namespace GameCult.Aetheria.State.Unity return settings; } + public static IReadOnlyList ReadLoadoutTemplates(string stateFilePath) + { + if (string.IsNullOrWhiteSpace(stateFilePath)) + throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath)); + + var catalog = ReadSchemaCatalog(stateFilePath); + var loadouts = new List(); + foreach (var record in ReadRecords(stateFilePath)) + { + if (!catalog.TryGetValue(record.SchemaId, out var schemaName) || + schemaName != LoadoutTemplateSchema) + continue; + + loadouts.Add(ReadLoadoutTemplatePayload(record.Payload)); + } + + return loadouts + .OrderBy(loadout => loadout.Name, StringComparer.Ordinal) + .ToArray(); + } + private static Dictionary ReadSchemaCatalog(string stateFilePath) { if (!File.Exists(stateFilePath)) @@ -347,6 +369,24 @@ namespace GameCult.Aetheria.State.Unity input.ActionBarInputs); } + private static AetheriaRuntimeLoadoutTemplateSnapshot ReadLoadoutTemplatePayload(byte[] payload) + { + var reader = new MessagePackReader(payload); + var fields = reader.ReadArrayHeader(); + var name = ReadFieldString(ref reader, fields, 0); + var ownerPlayerKey = ReadFieldString(ref reader, fields, 1); + var rootEntity = ReadFieldEntityLoadout(ref reader, fields, 2); + var createdAtUtc = ReadFieldString(ref reader, fields, 3); + var updatedAtUtc = ReadFieldString(ref reader, fields, 4); + SkipRemaining(ref reader, fields, 5); + return new AetheriaRuntimeLoadoutTemplateSnapshot( + name, + ownerPlayerKey, + rootEntity, + createdAtUtc, + updatedAtUtc); + } + private static string ReadFieldString(ref MessagePackReader reader, int fields, int index) { return index >= fields ? "" : ReadString(ref reader); @@ -457,6 +497,159 @@ namespace GameCult.Aetheria.State.Unity return bindings; } + private static AetheriaRuntimeEntityLoadoutSnapshot ReadFieldEntityLoadout(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return EmptyEntityLoadout(); + return ReadEntityLoadout(ref reader); + } + + private static IReadOnlyList ReadFieldEntityLoadouts(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return Array.Empty(); + var count = reader.ReadArrayHeader(); + var entities = new AetheriaRuntimeEntityLoadoutSnapshot[count]; + for (var entity = 0; entity < count; entity++) + entities[entity] = ReadEntityLoadout(ref reader); + return entities; + } + + private static AetheriaRuntimeEntityLoadoutSnapshot ReadEntityLoadout(ref MessagePackReader reader) + { + var fields = reader.ReadArrayHeader(); + var name = ReadFieldString(ref reader, fields, 0); + var kind = ReadFieldString(ref reader, fields, 1); + var factionKey = ReadFieldString(ref reader, fields, 2); + var hull = ReadFieldLoadoutItem(ref reader, fields, 3); + var equipment = ReadFieldLoadoutItemSlots(ref reader, fields, 4); + var cargoBays = ReadFieldLoadoutItemSlots(ref reader, fields, 5); + var dockingBays = ReadFieldLoadoutItemSlots(ref reader, fields, 6); + var cargoContents = ReadFieldCargoBayLoadouts(ref reader, fields, 7); + var dockingBayContents = ReadFieldCargoBayLoadouts(ref reader, fields, 8); + var dockingBayAssignments = ReadFieldInt32Array(ref reader, fields, 9); + var weaponGroups = ReadFieldInt32Arrays(ref reader, fields, 10); + var children = ReadFieldEntityLoadouts(ref reader, fields, 11); + SkipRemaining(ref reader, fields, 12); + return new AetheriaRuntimeEntityLoadoutSnapshot( + name, + kind, + factionKey, + hull, + equipment, + cargoBays, + dockingBays, + cargoContents, + dockingBayContents, + dockingBayAssignments, + weaponGroups, + children); + } + + private static AetheriaRuntimeEntityLoadoutSnapshot EmptyEntityLoadout() + { + return new AetheriaRuntimeEntityLoadoutSnapshot( + "", + "", + "", + EmptyLoadoutItem(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty>(), + Array.Empty()); + } + + private static AetheriaRuntimeLoadoutItemSnapshot ReadFieldLoadoutItem(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return EmptyLoadoutItem(); + var itemFields = reader.ReadArrayHeader(); + var itemKey = ReadFieldString(ref reader, itemFields, 0); + var quality = ReadFieldDouble(ref reader, itemFields, 1, 1); + var durability = ReadFieldDouble(ref reader, itemFields, 2, 1); + var quantity = ReadFieldInt32(ref reader, itemFields, 3); + SkipRemaining(ref reader, itemFields, 4); + return new AetheriaRuntimeLoadoutItemSnapshot(itemKey, quality, durability, quantity); + } + + private static AetheriaRuntimeLoadoutItemSnapshot EmptyLoadoutItem() + { + return new AetheriaRuntimeLoadoutItemSnapshot("", 1, 1, 1); + } + + private static IReadOnlyList ReadFieldLoadoutItemSlots(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return Array.Empty(); + var count = reader.ReadArrayHeader(); + var slots = new AetheriaRuntimeLoadoutItemSlotSnapshot[count]; + for (var slot = 0; slot < count; slot++) + slots[slot] = ReadLoadoutItemSlot(ref reader); + return slots; + } + + private static AetheriaRuntimeLoadoutItemSlotSnapshot ReadLoadoutItemSlot(ref MessagePackReader reader) + { + var slotFields = reader.ReadArrayHeader(); + var position = ReadFieldGridCoord(ref reader, slotFields, 0); + var item = ReadFieldLoadoutItem(ref reader, slotFields, 1); + SkipRemaining(ref reader, slotFields, 2); + return new AetheriaRuntimeLoadoutItemSlotSnapshot(position.X, position.Y, item); + } + + private static GridCoord ReadFieldGridCoord(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return new GridCoord(0, 0); + var coordFields = reader.ReadArrayHeader(); + var x = ReadFieldInt32(ref reader, coordFields, 0); + var y = ReadFieldInt32(ref reader, coordFields, 1); + SkipRemaining(ref reader, coordFields, 2); + return new GridCoord(x, y); + } + + private static IReadOnlyList ReadFieldCargoBayLoadouts(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return Array.Empty(); + var count = reader.ReadArrayHeader(); + var bays = new AetheriaRuntimeCargoBayLoadoutSnapshot[count]; + for (var bay = 0; bay < count; bay++) + { + var bayFields = reader.ReadArrayHeader(); + var items = ReadFieldLoadoutItemSlots(ref reader, bayFields, 0); + SkipRemaining(ref reader, bayFields, 1); + bays[bay] = new AetheriaRuntimeCargoBayLoadoutSnapshot(items); + } + + return bays; + } + + private static IReadOnlyList ReadFieldInt32Array(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return Array.Empty(); + var count = reader.ReadArrayHeader(); + var values = new int[count]; + for (var item = 0; item < count; item++) + values[item] = reader.ReadInt32(); + return values; + } + + private static IReadOnlyList> ReadFieldInt32Arrays(ref MessagePackReader reader, int fields, int index) + { + if (index >= fields) return Array.Empty>(); + var count = reader.ReadArrayHeader(); + var values = new IReadOnlyList[count]; + for (var item = 0; item < count; item++) + { + var groupCount = reader.ReadArrayHeader(); + var group = new int[groupCount]; + for (var groupItem = 0; groupItem < groupCount; groupItem++) + group[groupItem] = reader.ReadInt32(); + values[item] = group; + } + + return values; + } + private static IReadOnlyList ReadFieldShapeCells(ref MessagePackReader reader, int fields, int index) { return index >= fields ? Array.Empty() : ReadShapeCells(ref reader); @@ -859,5 +1052,18 @@ namespace GameCult.Aetheria.State.Unity public IReadOnlyList ActionBarInputs { get; } } + + private readonly struct GridCoord + { + public GridCoord(int x, int y) + { + X = x; + Y = y; + } + + public int X { get; } + + public int Y { get; } + } } } diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 8d50e490c..dcbd476d3 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -147,8 +147,11 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. equipment, cargo bay, docking bay, child-entity, assignment, and weapon-group state through record-key references and typed value slots instead of opaque runtime blueprint serialization. Unity's save/loadout UI now projects its - in-memory `RuntimeEntityBlueprint` into a typed Verse commit command; the - in-memory list remains a UI/session cache, not durable authority. + in-memory `RuntimeEntityBlueprint` into a typed Verse commit command, and + gameplay boot reads typed loadout templates back from `aetheria-world.cc` + through `AetheriaRuntimeCatalogStore` before lowering them into runtime + construction blueprints for the restore menu. The in-memory list remains a + UI/session cache, not durable authority. - `ActionGameManager` opens `AetheriaRuntimeCatalogStore` over `aetheria-world.cc`, projects it through `AetheriaRuntimeItemCatalog`, and gives `ItemManager` explicit item lookup authority. Item instances carry @@ -730,6 +733,9 @@ First Aetheria surfaces to publish: values. - Done: add typed `AetheriaLoadoutTemplate` documents and smoke coverage so `.loadout` no longer lacks a durable Verse replacement. + - Done: add the Unity runtime read projection for typed loadout templates, + so the restore menu can rehydrate saved loadouts from CultCache instead + of relying on the in-memory session list after restart. - Done: add typed node ports and smoke coverage for run -> zone -> entity snapshots so `.zone` no longer lacks a durable Verse replacement graph. - Done: extend run checkpoint commits and smoke coverage to carry typed @@ -1145,8 +1151,10 @@ First Aetheria surfaces to publish: replacement, loadout templates as the `.loadout` replacement, and a run -> zone -> entity snapshot graph as the `.zone` replacement. The zone smoke includes orbit/body rows for generated celestial state, and the entity smoke - includes typed simulation stat grids. It also proves `aetheria.runtime_session.v1` - is advertised and survives reopen as the typed daemon-session signal. + includes typed simulation stat grids. The Unity runtime smoke also proves + package-owned readback of typed loadout templates from `.cc` records. It also + proves `aetheria.runtime_session.v1` is advertised and survives reopen as the + typed daemon-session signal. - CultMesh smoke proves node start, typed put/get, subscription, flush, and reopen. - Eve surface smoke proves provider-owned surface documents are generated from