]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make MappingDataNode use string keys (#36111)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Fri, 18 Apr 2025 09:28:22 +0000 (19:28 +1000)
committerGitHub <noreply@github.com>
Fri, 18 Apr 2025 09:28:22 +0000 (19:28 +1000)
* MappingDataNode string keys

* a

* poke

Content.Server/Atmos/Serialization/TileAtmosCollectionSerializer.cs
Content.Server/Maps/MapMigrationSystem.cs
Content.Server/NPC/NPCBlackboardSerializer.cs
Content.Shared/Body/Prototypes/BodyPrototypeSerializer.cs
Content.Shared/Containers/ContainerFillComponent.cs
Content.Shared/Decals/DecalGridChunkCollectionTypeSerializer.cs

index 5b30d65e48e9cafa83ea325c502887eea0dbdc10..900c3cb60c4ee5c289be43edf2c8e3a1230ade87 100644 (file)
@@ -25,7 +25,7 @@ public sealed partial class TileAtmosCollectionSerializer : ITypeSerializer<Dict
         SerializationHookContext hookCtx, ISerializationContext? context = null,
         ISerializationManager.InstantiationDelegate<Dictionary<Vector2i, TileAtmosphere>>? instanceProvider = null)
     {
-        node.TryGetValue(new ValueDataNode("version"), out var versionNode);
+        node.TryGetValue("version", out var versionNode);
         var version = ((ValueDataNode?) versionNode)?.AsInt() ?? 1;
         Dictionary<Vector2i, TileAtmosphere> tiles = new();
 
@@ -59,7 +59,7 @@ public sealed partial class TileAtmosCollectionSerializer : ITypeSerializer<Dict
             var dataNode = (MappingDataNode) node["data"];
             var chunkSize = serializationManager.Read<int>(dataNode["chunkSize"], hookCtx, context);
 
-            dataNode.TryGetValue(new ValueDataNode("uniqueMixes"), out var mixNode);
+            dataNode.TryGet("uniqueMixes", out var mixNode);
             var unique = mixNode == null ? null : serializationManager.Read<List<GasMixture>?>(mixNode, hookCtx, context);
 
             if (unique != null)
@@ -67,7 +67,7 @@ public sealed partial class TileAtmosCollectionSerializer : ITypeSerializer<Dict
                 var tileNode = (MappingDataNode) dataNode["tiles"];
                 foreach (var (chunkNode, valueNode) in tileNode)
                 {
-                    var chunkOrigin = serializationManager.Read<Vector2i>(chunkNode, hookCtx, context);
+                    var chunkOrigin = serializationManager.Read<Vector2i>(tileNode.GetKeyNode(chunkNode), hookCtx, context);
                     var chunk = serializationManager.Read<TileAtmosChunk>(valueNode, hookCtx, context);
 
                     foreach (var (mix, data) in chunk.Data)
index 3341034a35655b2d1ee28c0ac120287ca04342ae..e04cfa17930ce385ef47fec32191a2e4d98633a8 100644 (file)
@@ -33,7 +33,7 @@ public sealed class MapMigrationSystem : EntitySystem
             return;
 
         // Verify that all of the entries map to valid entity prototypes.
-        foreach (var node in mappings.Values)
+        foreach (var node in mappings.Children.Values)
         {
             var newId = ((ValueDataNode) node).Value;
             if (!string.IsNullOrEmpty(newId) && newId != "null")
@@ -66,13 +66,13 @@ public sealed class MapMigrationSystem : EntitySystem
 
         foreach (var (key, value) in mappings)
         {
-            if (key is not ValueDataNode keyNode || value is not ValueDataNode valueNode)
+            if (value is not ValueDataNode valueNode)
                 continue;
 
             if (string.IsNullOrWhiteSpace(valueNode.Value) || valueNode.Value == "null")
-                ev.DeletedPrototypes.Add(keyNode.Value);
+                ev.DeletedPrototypes.Add(key);
             else
-                ev.RenamedPrototypes.Add(keyNode.Value, valueNode.Value);
+                ev.RenamedPrototypes.Add(key, valueNode.Value);
         }
     }
 }
index 56db17a0a71d8e62ac16018244c55855de36f768..a7c36dc6a5955760893eac9d9b1e7a34b4b55634 100644 (file)
@@ -23,11 +23,11 @@ public sealed class NPCBlackboardSerializer : ITypeReader<NPCBlackboard, Mapping
 
         foreach (var data in node)
         {
-            var key = data.Key.ToYamlNode().AsString();
+            var key = data.Key;
 
             if (data.Value.Tag == null)
             {
-                validated.Add(new ErrorNode(data.Key, $"Unable to validate {key}'s type"));
+                validated.Add(new ErrorNode(node.GetKeyNode(key), $"Unable to validate {key}'s type"));
                 continue;
             }
 
@@ -35,7 +35,7 @@ public sealed class NPCBlackboardSerializer : ITypeReader<NPCBlackboard, Mapping
 
             if (!reflection.TryLooseGetType(typeString, out var type))
             {
-                validated.Add(new ErrorNode(data.Key, $"Unable to find type for {typeString}"));
+                validated.Add(new ErrorNode(node.GetKeyNode(key), $"Unable to find type for {typeString}"));
                 continue;
             }
 
@@ -60,7 +60,7 @@ public sealed class NPCBlackboardSerializer : ITypeReader<NPCBlackboard, Mapping
 
         foreach (var data in node)
         {
-            var key = data.Key.ToYamlNode().AsString();
+            var key = data.Key;
 
             if (data.Value.Tag == null)
                 throw new NullReferenceException($"Found null tag for {key}");
index ae099767049b6c3e5c25c013acd04d621165439d..338e6c8ab84f977a114e4656e30f2954542ec193 100644 (file)
@@ -40,12 +40,6 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
         {
             foreach (var (key, value) in organsNode)
             {
-                if (key is not ValueDataNode)
-                {
-                    nodes.Add(new ErrorNode(key, $"Key is not a value data node"));
-                    continue;
-                }
-
                 if (value is not ValueDataNode organ)
                 {
                     nodes.Add(new ErrorNode(value, $"Value is not a value data node"));
@@ -91,12 +85,6 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
 
             foreach (var (key, value) in slots)
             {
-                if (key is not ValueDataNode)
-                {
-                    nodes.Add(new ErrorNode(key, $"Key is not a value data node"));
-                    continue;
-                }
-
                 if (value is not MappingDataNode slot)
                 {
                     nodes.Add(new ErrorNode(value, $"Slot is not a mapping data node"));
@@ -128,10 +116,9 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
         var slotNodes = node.Get<MappingDataNode>("slots");
         var allConnections = new Dictionary<string, (string? Part, HashSet<string>? Connections, Dictionary<string, string>? Organs)>();
 
-        foreach (var (keyNode, valueNode) in slotNodes)
+        foreach (var (slotId, valueNode) in slotNodes)
         {
-            var slotId = ((ValueDataNode) keyNode).Value;
-            var slot = ((MappingDataNode) valueNode);
+            var slot = (MappingDataNode) valueNode;
 
             string? part = null;
             if (slot.TryGet<ValueDataNode>("part", out var value))
@@ -155,9 +142,9 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
             {
                 organs = new Dictionary<string, string>();
 
-                foreach (var (organKeyNode, organValueNode) in slotOrgansNode)
+                foreach (var (organKey, organValueNode) in slotOrgansNode)
                 {
-                    organs.Add(((ValueDataNode) organKeyNode).Value, ((ValueDataNode) organValueNode).Value);
+                    organs.Add(organKey, ((ValueDataNode) organValueNode).Value);
                 }
             }
 
index 7ce5fa88502b63803b54d91734e0123142510ba0..aa8c98fd1ff8c1f645dc5091365b7c15cdb02418 100644 (file)
@@ -49,13 +49,11 @@ public sealed class ContainerFillSerializer : ITypeValidator<Dictionary<string,
 
         foreach (var (key, val) in node.Children)
         {
-            var keyVal = serializationManager.ValidateNode<string>(key, context);
-
             var listVal = (val is SequenceDataNode seq)
                 ? ListSerializer.Validate(serializationManager, seq, dependencies, context)
                 : new ErrorNode(val, "ContainerFillComponent prototypes must be a sequence/list");
 
-            mapping.Add(keyVal, listVal);
+            mapping.Add(new ValidatedValueNode(node.GetKeyNode(key)), listVal);
         }
 
         return new ValidatedMappingNode(mapping);
index ae4c89c9703455a324b58190bda0d873cd4678b3..f2f9e8960395efb27df38b186a08ac064324f4a0 100644 (file)
@@ -29,7 +29,7 @@ namespace Content.Shared.Decals
             IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null,
             ISerializationManager.InstantiationDelegate<DecalGridChunkCollection>? _ = default)
         {
-            node.TryGetValue(new ValueDataNode("version"), out var versionNode);
+            node.TryGetValue("version", out var versionNode);
             var version = ((ValueDataNode?) versionNode)?.AsInt() ?? 1;
             Dictionary<Vector2i, DecalChunk> dictionary;
             uint nextIndex = 0;
@@ -49,7 +49,7 @@ namespace Content.Shared.Decals
 
                     foreach (var (decalUidNode, decalData) in deckNodes)
                     {
-                        var dUid = serializationManager.Read<uint>(decalUidNode, hookCtx, context);
+                        var dUid = uint.Parse(decalUidNode, CultureInfo.InvariantCulture);
                         var coords = serializationManager.Read<Vector2>(decalData, hookCtx, context);
 
                         var chunkOrigin = SharedMapSystem.GetChunkIndices(coords, SharedDecalSystem.ChunkSize);
@@ -132,7 +132,7 @@ namespace Content.Shared.Decals
                 {
                     var decal = decalLookup[uid];
                     // Inline coordinates
-                    decks.Add(serializationManager.WriteValue(uid, alwaysWrite, context), serializationManager.WriteValue(decal.Coordinates, alwaysWrite, context));
+                    decks.Add(uid.ToString(), serializationManager.WriteValue(decal.Coordinates, alwaysWrite, context));
                 }
 
                 lookupNode.Add("decals", decks);