From 74007281f7ed21fb624040b4820d27782e147484 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 13 Jun 2026 04:00:10 +0100 Subject: [PATCH] Add typed Verse save documents --- .voidbot/state/aetheria.cc | Bin 10716 -> 11308 bytes Aetheria.State.Smoke/Program.cs | 39 +++ Aetheria.State/AetheriaDocumentRegistry.cs | 12 +- Aetheria.State/AetheriaStateNode.cs | 20 ++ .../Documents/AetheriaSaveDocuments.cs | 225 ++++++++++++++++++ .../Migration/LegacyMigrationBoundary.cs | 3 + Aetheria.State/README.md | 5 + 7 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 Aetheria.State/Documents/AetheriaSaveDocuments.cs diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 803e5b614a3c7e6af3af9d003ce8a0563265a646..0c635de546e5822ec326aa131caad5df52e658ec 100644 GIT binary patch delta 1766 zcmZ`)&u<$=6vk=Q2EipIkVLKFL4?vGXWh6>LR@-?Ld1ols18z?NKhn@xuPNtT)1#8DyRMhT)37uvp*77;%2|y`QG=w?|ZY4I}dLC zcr^85tG&9>ZmoH%s~dY?)Lzb>*3V>rOx>&MYgezjx;%AQ)!trTakc5w^{Mm!WJ{-y zM)x<-^igr&*9aU)Ox{IB9z;V3Bx2M?K&nbTe;>#ynXtPlLc)etNbP+~ zj%e!m=;4RL8l?@7A{da81Ue~-H>%9>CS33;8#MHkjA7HwXwAF91Pf6$KuaL?O4nnG zMVSdryyXE3N=K!7k*{uQ++agA_H-R6QHI9|av)GakEXMre#8kcOWv5h^yC9PG~m-Y zG9rxvh}k|uKAKOurgYdI(b>Oe7e{0XrP%uE^4zq)CTDh~_w&fP-`00Rpp#+0NPQWh zf^;B#>LMs+HlYE=l6u&lH&AO5V~67HGOL&D9>hE(A8jPKNQk!-(a`&j37_J86MOpc zbMxchrup>tcDZvwzIb?;NKGasZh=4-8|1obyFAOJ77%1JB>DOnC8+ecH`AUw9X7X^meX?Qk z?%h||d$g9tGxb-RrL6Yx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State.Smoke/Program.cs +++ b/Aetheria.State.Smoke/Program.cs @@ -7,6 +7,7 @@ var root = args.Length > 0 ? args[0] : Directory.GetCurrentDirectory(); var statePath = AetheriaStatePaths.ResolveDefaultStatePath(root); var now = DateTimeOffset.UtcNow.ToString("O"); var itemKey = new CultRecordKey("item:smoke-aether-drive"); +var runKey = new CultRecordKey("run:smoke"); await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-state-smoke")) { @@ -48,6 +49,32 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s Notes = ["Smoke proves the new state owner can write, flush, reopen, and read without old JSON/Rethink authority."] }); + await node.PutSavedRunAsync(runKey, new AetheriaSavedRun + { + RunId = "smoke", + IsTutorial = false, + EntranceZoneIndex = 0, + ExitZoneIndex = 1, + CurrentZoneIndex = 0, + CurrentZoneEntityIndex = 0, + DiscoveredZoneIndices = [0], + ActionBarBindings = + [ + new AetheriaActionBarBinding + { + Kind = "weapon-group", + WeaponGroup = 0 + } + ], + UpdatedAtUtc = now + }); + + await node.PutPlayerSettingsAsync(new AetheriaPlayerSettings + { + ActiveRunKey = runKey.ToString(), + LastUpdatedAtUtc = now + }); + await node.FlushAsync(); } @@ -55,6 +82,8 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether { var world = await reopened.GetWorldAsync(); var item = await reopened.GetItemDefinitionAsync(itemKey); + var playerSettings = await reopened.GetPlayerSettingsAsync(); + var savedRun = await reopened.GetSavedRunAsync(runKey); if (world?.WorldId != "aetheria") { @@ -65,6 +94,16 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether { throw new InvalidOperationException("Item definition did not survive flush/reopen."); } + + if (playerSettings?.ActiveRunKey != runKey.ToString()) + { + throw new InvalidOperationException("Player settings did not survive flush/reopen."); + } + + if (savedRun?.RunId != "smoke" || savedRun.ActionBarBindings.Length != 1) + { + throw new InvalidOperationException("Saved run did not survive flush/reopen."); + } } Console.WriteLine($"Aetheria typed state smoke passed: {statePath}"); diff --git a/Aetheria.State/AetheriaDocumentRegistry.cs b/Aetheria.State/AetheriaDocumentRegistry.cs index f6e9359e5..24e313e18 100644 --- a/Aetheria.State/AetheriaDocumentRegistry.cs +++ b/Aetheria.State/AetheriaDocumentRegistry.cs @@ -29,7 +29,11 @@ public static class AetheriaDocumentRegistry CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), - CultNetDocumentBinding.ForDocument(registry) + CultNetDocumentBinding.ForDocument(registry), + CultNetDocumentBinding.ForDocument(registry), + CultNetDocumentBinding.ForDocument(registry), + CultNetDocumentBinding.ForDocument(registry), + CultNetDocumentBinding.ForDocument(registry) }); } @@ -40,6 +44,10 @@ public static class AetheriaDocumentRegistry typeof(AetheriaCorporation), typeof(AetheriaPlayerProfile), typeof(AetheriaRuntimeSession), - typeof(AetheriaMigrationLedger) + typeof(AetheriaMigrationLedger), + typeof(AetheriaPlayerSettings), + typeof(AetheriaSavedRun), + typeof(AetheriaSavedZone), + typeof(AetheriaEntitySnapshot) ]; } diff --git a/Aetheria.State/AetheriaStateNode.cs b/Aetheria.State/AetheriaStateNode.cs index 2e40ec927..6758cb072 100644 --- a/Aetheria.State/AetheriaStateNode.cs +++ b/Aetheria.State/AetheriaStateNode.cs @@ -88,6 +88,26 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable return Database.GetAsync(key); } + public Task> PutPlayerSettingsAsync(AetheriaPlayerSettings settings) + { + return Database.PutAsync(new CultRecordKey("global:aetheria.player_settings.v1"), settings); + } + + public Task GetPlayerSettingsAsync() + { + return Database.GetAsync(new CultRecordKey("global:aetheria.player_settings.v1")); + } + + public Task> PutSavedRunAsync(CultRecordKey key, AetheriaSavedRun run) + { + return Database.PutAsync(key, run); + } + + public Task GetSavedRunAsync(CultRecordKey key) + { + return Database.GetAsync(key); + } + public Task FlushAsync(bool soft = false) { return _node.FlushAsync(soft); diff --git a/Aetheria.State/Documents/AetheriaSaveDocuments.cs b/Aetheria.State/Documents/AetheriaSaveDocuments.cs new file mode 100644 index 000000000..cdb6af7d6 --- /dev/null +++ b/Aetheria.State/Documents/AetheriaSaveDocuments.cs @@ -0,0 +1,225 @@ +using GameCult.Caching; +using MessagePack; + +namespace Aetheria.State.Documents; + +[CultDocument("aetheria.player_settings", "aetheria.player_settings.v1")] +[CultGlobal] +[MessagePackObject] +public sealed class AetheriaPlayerSettings +{ + [Key(0)] + [CultName] + public string Name { get; set; } = "Aetheria player settings"; + + [Key(1)] + [CultReference(typeof(AetheriaSavedRun))] + public string ActiveRunKey { get; set; } = ""; + + [Key(2)] + public string LastUpdatedAtUtc { get; set; } = ""; +} + +[CultDocument("aetheria.saved_run", "aetheria.saved_run.v1")] +[MessagePackObject] +public sealed class AetheriaSavedRun +{ + [Key(0)] + [CultName] + public string RunId { get; set; } = ""; + + [Key(1)] + public bool IsTutorial { get; set; } + + [Key(2)] + public int EntranceZoneIndex { get; set; } + + [Key(3)] + public int ExitZoneIndex { get; set; } + + [Key(4)] + public int CurrentZoneIndex { get; set; } + + [Key(5)] + public int CurrentZoneEntityIndex { get; set; } + + [Key(6)] + public int[] DiscoveredZoneIndices { get; set; } = []; + + [Key(7)] + [CultReference(typeof(AetheriaSavedZone), many: true)] + public string[] ZoneKeys { get; set; } = []; + + [Key(8)] + public AetheriaActionBarBinding[] ActionBarBindings { get; set; } = []; + + [Key(9)] + public AetheriaFactionRelationshipState[] FactionRelationships { get; set; } = []; + + [Key(10)] + public string UpdatedAtUtc { get; set; } = ""; +} + +[CultDocument("aetheria.saved_zone", "aetheria.saved_zone.v1")] +[MessagePackObject] +public sealed class AetheriaSavedZone +{ + [Key(0)] + [CultName] + public string Name { get; set; } = ""; + + [Key(1)] + public AetheriaVector2 Position { get; set; } = new(); + + [Key(2)] + public int[] AdjacentZoneIndices { get; set; } = []; + + [Key(3)] + public int[] FactionIndices { get; set; } = []; + + [Key(4)] + public int OwnerFactionIndex { get; set; } = -1; + + [Key(5)] + [CultReference(typeof(AetheriaEntitySnapshot), many: true)] + public string[] EntityKeys { get; set; } = []; +} + +[CultDocument("aetheria.entity_snapshot", "aetheria.entity_snapshot.v1")] +[MessagePackObject] +public sealed class AetheriaEntitySnapshot +{ + [Key(0)] + [CultName] + public string Name { get; set; } = ""; + + [Key(1)] + [CultIndex("kind")] + public string Kind { get; set; } = ""; + + [Key(2)] + public AetheriaVector3 Position { get; set; } = new(); + + [Key(3)] + public AetheriaVector2 Direction { get; set; } = new(); + + [Key(4)] + public string FactionKey { get; set; } = ""; + + [Key(5)] + public string HullItemKey { get; set; } = ""; + + [Key(6)] + public AetheriaEntityItemSlot[] Equipment { get; set; } = []; + + [Key(7)] + public AetheriaEntityItemSlot[] CargoBays { get; set; } = []; + + [Key(8)] + public AetheriaEntityItemSlot[] DockingBays { get; set; } = []; + + [Key(9)] + [CultReference(typeof(AetheriaEntitySnapshot), many: true)] + public string[] ChildEntityKeys { get; set; } = []; + + [Key(10)] + public AetheriaWeaponGroupSnapshot[] WeaponGroups { get; set; } = []; + + [Key(11)] + public AetheriaEntityStatGrid[] StatGrids { get; set; } = []; +} + +[MessagePackObject] +public sealed class AetheriaEntityItemSlot +{ + [Key(0)] + public AetheriaGridCoord Position { get; set; } = new(); + + [Key(1)] + public string ItemKey { get; set; } = ""; +} + +[MessagePackObject] +public sealed class AetheriaWeaponGroupSnapshot +{ + [Key(0)] + public int[] EquipmentIndices { get; set; } = []; +} + +[MessagePackObject] +public sealed class AetheriaEntityStatGrid +{ + [Key(0)] + public string Name { get; set; } = ""; + + [Key(1)] + public int Width { get; set; } + + [Key(2)] + public int Height { get; set; } + + [Key(3)] + public double[] Values { get; set; } = []; +} + +[MessagePackObject] +public sealed class AetheriaActionBarBinding +{ + [Key(0)] + public string Kind { get; set; } = ""; + + [Key(1)] + public string TargetKey { get; set; } = ""; + + [Key(2)] + public int EquipmentIndex { get; set; } = -1; + + [Key(3)] + public int BehaviorIndex { get; set; } = -1; + + [Key(4)] + public int WeaponGroup { get; set; } = -1; +} + +[MessagePackObject] +public sealed class AetheriaFactionRelationshipState +{ + [Key(0)] + public string FactionKey { get; set; } = ""; + + [Key(1)] + public double Standing { get; set; } +} + +[MessagePackObject] +public sealed class AetheriaVector2 +{ + [Key(0)] + public double X { get; set; } + + [Key(1)] + public double Y { get; set; } +} + +[MessagePackObject] +public sealed class AetheriaVector3 +{ + [Key(0)] + public double X { get; set; } + + [Key(1)] + public double Y { get; set; } + + [Key(2)] + public double Z { get; set; } +} + +[MessagePackObject] +public sealed class AetheriaGridCoord +{ + [Key(0)] + public int X { get; set; } + + [Key(1)] + public int Y { get; set; } +} diff --git a/Aetheria.State/Migration/LegacyMigrationBoundary.cs b/Aetheria.State/Migration/LegacyMigrationBoundary.cs index 2337bab00..b4f13e72d 100644 --- a/Aetheria.State/Migration/LegacyMigrationBoundary.cs +++ b/Aetheria.State/Migration/LegacyMigrationBoundary.cs @@ -5,6 +5,9 @@ public static class LegacyMigrationBoundary public const string LegacyCacheNamespace = "Assets/Scripts/ServerShared/CultCache"; public const string LegacyRethinkNamespace = "Assets/Scripts/ServerShared/NIH/RethinkDb"; public const string LegacyGameDataFile = "GameData/AetherDB.msgpack"; + public const string LegacyPlayerSettingsFile = "GameData/PlayerSettings.msgpack"; + public const string LegacyLoadoutExtension = ".loadout"; + public const string LegacyZoneExtension = ".zone"; public static string[] ForbiddenLiveAuthorities { get; } = [ diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index ccf6d1ae0..5c368eca9 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -9,6 +9,11 @@ tree, RethinkDB, JsonKnownTypes, or Newtonsoft.Json. The first live state file is `GameData/aetheria-world.cc`. Legacy files such as `GameData/AetherDB.msgpack` are migration inputs only. +The typed save model is split into player settings, saved runs, saved zones, +entity snapshots, item slots, weapon groups, action-bar bindings, and stat +grids. Do not preserve `SavedGame` or `EntityPack` as opaque payloads in the +new store; they are source shapes for migration, not portable state authority. + Current rebuild notes: - `MessagePack` 3.1.4 is pulled transitively through CultLib and is currently