diff --git a/Content.Tools/MappingMergeDriver.cs b/Content.Tools/MappingMergeDriver.cs index eb0396db54a..1f3b56cd05e 100644 --- a/Content.Tools/MappingMergeDriver.cs +++ b/Content.Tools/MappingMergeDriver.cs @@ -14,7 +14,7 @@ public static void Main(string[] args) var based = new Map(args[1]); // On what? var other = new Map(args[2]); - if ((ours.GridsNode.Children.Count != 1) || (based.GridsNode.Children.Count != 1) || (other.GridsNode.Children.Count != 1)) + if (ours.GridsNode.Children.Count != 1 || based.GridsNode.Children.Count != 1 || other.GridsNode.Children.Count != 1) { Console.WriteLine("one or more files had an amount of grids not equal to 1"); Environment.Exit(1); diff --git a/Content.Tools/Merger.cs b/Content.Tools/Merger.cs index 44fa2c20fef..9ca490504f4 100644 --- a/Content.Tools/Merger.cs +++ b/Content.Tools/Merger.cs @@ -111,7 +111,7 @@ public void MergeTileChunks(YamlSequenceNode aChunks, YamlSequenceNode bChunks, var cI = MapTileId(cR.ReadUInt32(), TileMapFromOtherToOurs); // cI needs translation. - uint result = aI; + var result = aI; if (aI == bI) { // If aI == bI then aI did not change anything, so cI always wins @@ -138,12 +138,12 @@ public void MergeTileChunks(YamlSequenceNode aChunks, YamlSequenceNode bChunks, } } - public uint MapTileId(uint src, Dictionary mapping) + public static uint MapTileId(uint src, Dictionary mapping) { return (src & 0xFFFF0000) | mapping[src & 0xFFFF]; } - public Dictionary ConvertTileChunks(YamlSequenceNode chunks) + public static Dictionary ConvertTileChunks(YamlSequenceNode chunks) { var map = new Dictionary(); foreach (var chunk in chunks) @@ -151,7 +151,7 @@ public Dictionary ConvertTileChunks(YamlSequenceNode ch return map; } - public byte[] GetChunkBytes(Dictionary chunks, string ind) + public static byte[] GetChunkBytes(Dictionary chunks, string ind) { if (!chunks.ContainsKey(ind)) return new byte[ExpectedChunkSize]; @@ -197,7 +197,7 @@ public void PlanEntityMapping() public bool MergeEntities() { - bool success = true; + var success = true; foreach (var kvp in EntityMapFromOtherToOurs) { // For debug use. @@ -220,10 +220,13 @@ public bool MergeEntities() else { oursEnt = (YamlMappingNode) YamlTools.CopyYamlNodes(MapOther.Entities[kvp.Key]); - if (!MapEntity(oursEnt)) { + if (!MapEntity(oursEnt)) + { Console.WriteLine("Unable to successfully import entity C/" + kvp.Key); success = false; - } else { + } + else + { MapOurs.Entities[kvp.Value] = oursEnt; } } @@ -240,7 +243,7 @@ public bool MergeEntityNodes(YamlMappingNode ours, YamlMappingNode based, YamlMa return false; // Merge stuff that isn't components var path = "Entity" + other["uid"]; - YamlTools.MergeYamlMappings(ours, based, otherMapped, path, new[] {"components"}); + YamlTools.MergeYamlMappings(ours, based, otherMapped, path, new[] { "components" }); // Components are special var ourComponents = new Dictionary(); var basedComponents = new Dictionary(); @@ -301,10 +304,11 @@ public bool MapEntity(YamlMappingNode other) public bool MapEntityProperty(YamlMappingNode node, string property, string path) { - if (node.Children.ContainsKey(property)) { + if (node.Children.ContainsKey(property)) + { var prop = node[property]; - if (prop is YamlScalarNode) - return MapEntityProperty((YamlScalarNode) prop, path + "/" + property); + if (prop is YamlScalarNode yamlProp) + return MapEntityProperty(yamlProp, path + "/" + property); } return true; } @@ -333,7 +337,7 @@ public bool MapEntityRecursiveAndBadly(YamlNode node, string path) case YamlSequenceNode subSequence: var idx = 0; foreach (var val in subSequence) - if (!MapEntityRecursiveAndBadly(val, path + "/" + (idx++))) + if (!MapEntityRecursiveAndBadly(val, path + "/" + idx++)) return false; return true; case YamlMappingNode subMapping: diff --git a/Content.Tools/TypeTagPreserver.cs b/Content.Tools/TypeTagPreserver.cs index 54653ec7376..6dda5b92c21 100644 --- a/Content.Tools/TypeTagPreserver.cs +++ b/Content.Tools/TypeTagPreserver.cs @@ -7,7 +7,7 @@ public sealed class TypeTagPreserver : IEmitter { public TypeTagPreserver(IEmitter emitter) { - Emitter = emitter; + Emitter = emitter; } private IEmitter Emitter { get; } diff --git a/Content.Tools/YamlTools.cs b/Content.Tools/YamlTools.cs index 0074cd652ed..e59d61efa4e 100644 --- a/Content.Tools/YamlTools.cs +++ b/Content.Tools/YamlTools.cs @@ -11,15 +11,15 @@ public static YamlNode CopyYamlNodes(YamlNode other) switch (other) { case YamlSequenceNode subSequence: - YamlSequenceNode tmp1 = new YamlSequenceNode(); + var tmp1 = new YamlSequenceNode(); MergeYamlSequences(tmp1, new YamlSequenceNode(), subSequence, ""); return tmp1; case YamlMappingNode subMapping: - YamlMappingNode tmp2 = new YamlMappingNode(); - MergeYamlMappings(tmp2, new YamlMappingNode(), subMapping, "", new string[] {}); + var tmp2 = new YamlMappingNode(); + MergeYamlMappings(tmp2, new YamlMappingNode(), subMapping, "", Array.Empty()); return tmp2; case YamlScalarNode subScalar: - YamlScalarNode tmp3 = new YamlScalarNode(); + var tmp3 = new YamlScalarNode(); CopyYamlScalar(tmp3, subScalar); return tmp3; default: @@ -47,7 +47,7 @@ public static void MergeYamlNodes(YamlNode ours, YamlNode based, YamlNode other, MergeYamlSequences((YamlSequenceNode) ours, (YamlSequenceNode) based, subSequence, path); break; case YamlMappingNode subMapping: - MergeYamlMappings((YamlMappingNode) ours, (YamlMappingNode) based, subMapping, path, new string[] {}); + MergeYamlMappings((YamlMappingNode) ours, (YamlMappingNode) based, subMapping, path, Array.Empty()); break; case YamlScalarNode subScalar: // Console.WriteLine(path + " - " + ours + " || " + based + " || " + other); @@ -67,7 +67,7 @@ public static void MergeYamlNodes(YamlNode ours, YamlNode based, YamlNode other, public static void MergeYamlSequences(YamlSequenceNode ours, YamlSequenceNode based, YamlSequenceNode other, string path) { - if ((ours.Children.Count == based.Children.Count) && (other.Children.Count == ours.Children.Count)) + if (ours.Children.Count == based.Children.Count && other.Children.Count == ours.Children.Count) { // this is terrible and doesn't do proper rearrange detection // but it looks as if vectors might be arrays @@ -95,7 +95,7 @@ public static void MergeYamlMappings(YamlMappingNode ours, YamlMappingNode based var localPath = path + "/" + kvp.Key; var deletedByOurs = !ours.Children.ContainsKey(kvp.Key); var deletedByOther = !other.Children.ContainsKey(kvp.Key); - if (deletedByOther && (!deletedByOurs)) + if (deletedByOther && !deletedByOurs) { // Delete ours.Children.Remove(kvp.Key); @@ -157,17 +157,14 @@ public static float YamlNodesHeuristic(YamlNode a, YamlNode b) { if (a.GetType() != b.GetType()) return 0.0f; - switch (a) + + return a switch { - case YamlSequenceNode x: - return YamlSequencesHeuristic(x, (YamlSequenceNode) b); - case YamlMappingNode y: - return YamlMappingsHeuristic(y, (YamlMappingNode) b); - case YamlScalarNode z: - return (z.Value == ((YamlScalarNode) b).Value) ? 1.0f : 0.0f; - default: - throw new ArgumentException($"Unrecognized YAML node type: {a.GetType()}", nameof(a)); - } + YamlSequenceNode x => YamlSequencesHeuristic(x, (YamlSequenceNode) b), + YamlMappingNode y => YamlMappingsHeuristic(y, (YamlMappingNode) b), + YamlScalarNode z => (z.Value == ((YamlScalarNode) b).Value) ? 1.0f : 0.0f, + _ => throw new ArgumentException($"Unrecognized YAML node type: {a.GetType()}", nameof(a)) + }; } public static float YamlSequencesHeuristic(YamlSequenceNode a, YamlSequenceNode b)