Fix warnings in Content.Tools module (#17862)

This commit is contained in:
TemporalOroboros
2023-07-10 00:39:21 -07:00
committed by GitHub
parent 4cc771f539
commit 7ec8bea20f
4 changed files with 32 additions and 31 deletions

View File

@@ -14,7 +14,7 @@ namespace Content.Tools
var based = new Map(args[1]); // On what? var based = new Map(args[1]); // On what?
var other = new Map(args[2]); 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"); Console.WriteLine("one or more files had an amount of grids not equal to 1");
Environment.Exit(1); Environment.Exit(1);

View File

@@ -111,7 +111,7 @@ namespace Content.Tools
var cI = MapTileId(cR.ReadUInt32(), TileMapFromOtherToOurs); var cI = MapTileId(cR.ReadUInt32(), TileMapFromOtherToOurs);
// cI needs translation. // cI needs translation.
uint result = aI; var result = aI;
if (aI == bI) if (aI == bI)
{ {
// If aI == bI then aI did not change anything, so cI always wins // If aI == bI then aI did not change anything, so cI always wins
@@ -138,12 +138,12 @@ namespace Content.Tools
} }
} }
public uint MapTileId(uint src, Dictionary<uint, uint> mapping) public static uint MapTileId(uint src, Dictionary<uint, uint> mapping)
{ {
return (src & 0xFFFF0000) | mapping[src & 0xFFFF]; return (src & 0xFFFF0000) | mapping[src & 0xFFFF];
} }
public Dictionary<string, YamlMappingNode> ConvertTileChunks(YamlSequenceNode chunks) public static Dictionary<string, YamlMappingNode> ConvertTileChunks(YamlSequenceNode chunks)
{ {
var map = new Dictionary<string, YamlMappingNode>(); var map = new Dictionary<string, YamlMappingNode>();
foreach (var chunk in chunks) foreach (var chunk in chunks)
@@ -151,7 +151,7 @@ namespace Content.Tools
return map; return map;
} }
public byte[] GetChunkBytes(Dictionary<string, YamlMappingNode> chunks, string ind) public static byte[] GetChunkBytes(Dictionary<string, YamlMappingNode> chunks, string ind)
{ {
if (!chunks.ContainsKey(ind)) if (!chunks.ContainsKey(ind))
return new byte[ExpectedChunkSize]; return new byte[ExpectedChunkSize];
@@ -197,7 +197,7 @@ namespace Content.Tools
public bool MergeEntities() public bool MergeEntities()
{ {
bool success = true; var success = true;
foreach (var kvp in EntityMapFromOtherToOurs) foreach (var kvp in EntityMapFromOtherToOurs)
{ {
// For debug use. // For debug use.
@@ -220,10 +220,13 @@ namespace Content.Tools
else else
{ {
oursEnt = (YamlMappingNode) YamlTools.CopyYamlNodes(MapOther.Entities[kvp.Key]); oursEnt = (YamlMappingNode) YamlTools.CopyYamlNodes(MapOther.Entities[kvp.Key]);
if (!MapEntity(oursEnt)) { if (!MapEntity(oursEnt))
{
Console.WriteLine("Unable to successfully import entity C/" + kvp.Key); Console.WriteLine("Unable to successfully import entity C/" + kvp.Key);
success = false; success = false;
} else { }
else
{
MapOurs.Entities[kvp.Value] = oursEnt; MapOurs.Entities[kvp.Value] = oursEnt;
} }
} }
@@ -240,7 +243,7 @@ namespace Content.Tools
return false; return false;
// Merge stuff that isn't components // Merge stuff that isn't components
var path = "Entity" + other["uid"]; var path = "Entity" + other["uid"];
YamlTools.MergeYamlMappings(ours, based, otherMapped, path, new[] {"components"}); YamlTools.MergeYamlMappings(ours, based, otherMapped, path, new[] { "components" });
// Components are special // Components are special
var ourComponents = new Dictionary<string, YamlMappingNode>(); var ourComponents = new Dictionary<string, YamlMappingNode>();
var basedComponents = new Dictionary<string, YamlMappingNode>(); var basedComponents = new Dictionary<string, YamlMappingNode>();
@@ -301,10 +304,11 @@ namespace Content.Tools
public bool MapEntityProperty(YamlMappingNode node, string property, string path) public bool MapEntityProperty(YamlMappingNode node, string property, string path)
{ {
if (node.Children.ContainsKey(property)) { if (node.Children.ContainsKey(property))
{
var prop = node[property]; var prop = node[property];
if (prop is YamlScalarNode) if (prop is YamlScalarNode yamlProp)
return MapEntityProperty((YamlScalarNode) prop, path + "/" + property); return MapEntityProperty(yamlProp, path + "/" + property);
} }
return true; return true;
} }
@@ -333,7 +337,7 @@ namespace Content.Tools
case YamlSequenceNode subSequence: case YamlSequenceNode subSequence:
var idx = 0; var idx = 0;
foreach (var val in subSequence) foreach (var val in subSequence)
if (!MapEntityRecursiveAndBadly(val, path + "/" + (idx++))) if (!MapEntityRecursiveAndBadly(val, path + "/" + idx++))
return false; return false;
return true; return true;
case YamlMappingNode subMapping: case YamlMappingNode subMapping:

View File

@@ -7,7 +7,7 @@ namespace Content.Tools
{ {
public TypeTagPreserver(IEmitter emitter) public TypeTagPreserver(IEmitter emitter)
{ {
Emitter = emitter; Emitter = emitter;
} }
private IEmitter Emitter { get; } private IEmitter Emitter { get; }

View File

@@ -11,15 +11,15 @@ namespace Content.Tools
switch (other) switch (other)
{ {
case YamlSequenceNode subSequence: case YamlSequenceNode subSequence:
YamlSequenceNode tmp1 = new YamlSequenceNode(); var tmp1 = new YamlSequenceNode();
MergeYamlSequences(tmp1, new YamlSequenceNode(), subSequence, ""); MergeYamlSequences(tmp1, new YamlSequenceNode(), subSequence, "");
return tmp1; return tmp1;
case YamlMappingNode subMapping: case YamlMappingNode subMapping:
YamlMappingNode tmp2 = new YamlMappingNode(); var tmp2 = new YamlMappingNode();
MergeYamlMappings(tmp2, new YamlMappingNode(), subMapping, "", new string[] {}); MergeYamlMappings(tmp2, new YamlMappingNode(), subMapping, "", Array.Empty<string>());
return tmp2; return tmp2;
case YamlScalarNode subScalar: case YamlScalarNode subScalar:
YamlScalarNode tmp3 = new YamlScalarNode(); var tmp3 = new YamlScalarNode();
CopyYamlScalar(tmp3, subScalar); CopyYamlScalar(tmp3, subScalar);
return tmp3; return tmp3;
default: default:
@@ -47,7 +47,7 @@ namespace Content.Tools
MergeYamlSequences((YamlSequenceNode) ours, (YamlSequenceNode) based, subSequence, path); MergeYamlSequences((YamlSequenceNode) ours, (YamlSequenceNode) based, subSequence, path);
break; break;
case YamlMappingNode subMapping: case YamlMappingNode subMapping:
MergeYamlMappings((YamlMappingNode) ours, (YamlMappingNode) based, subMapping, path, new string[] {}); MergeYamlMappings((YamlMappingNode) ours, (YamlMappingNode) based, subMapping, path, Array.Empty<string>());
break; break;
case YamlScalarNode subScalar: case YamlScalarNode subScalar:
// Console.WriteLine(path + " - " + ours + " || " + based + " || " + other); // Console.WriteLine(path + " - " + ours + " || " + based + " || " + other);
@@ -67,7 +67,7 @@ namespace Content.Tools
public static void MergeYamlSequences(YamlSequenceNode ours, YamlSequenceNode based, YamlSequenceNode other, string path) 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 // this is terrible and doesn't do proper rearrange detection
// but it looks as if vectors might be arrays // but it looks as if vectors might be arrays
@@ -95,7 +95,7 @@ namespace Content.Tools
var localPath = path + "/" + kvp.Key; var localPath = path + "/" + kvp.Key;
var deletedByOurs = !ours.Children.ContainsKey(kvp.Key); var deletedByOurs = !ours.Children.ContainsKey(kvp.Key);
var deletedByOther = !other.Children.ContainsKey(kvp.Key); var deletedByOther = !other.Children.ContainsKey(kvp.Key);
if (deletedByOther && (!deletedByOurs)) if (deletedByOther && !deletedByOurs)
{ {
// Delete // Delete
ours.Children.Remove(kvp.Key); ours.Children.Remove(kvp.Key);
@@ -157,17 +157,14 @@ namespace Content.Tools
{ {
if (a.GetType() != b.GetType()) if (a.GetType() != b.GetType())
return 0.0f; return 0.0f;
switch (a)
return a switch
{ {
case YamlSequenceNode x: YamlSequenceNode x => YamlSequencesHeuristic(x, (YamlSequenceNode) b),
return YamlSequencesHeuristic(x, (YamlSequenceNode) b); YamlMappingNode y => YamlMappingsHeuristic(y, (YamlMappingNode) b),
case YamlMappingNode y: YamlScalarNode z => (z.Value == ((YamlScalarNode) b).Value) ? 1.0f : 0.0f,
return YamlMappingsHeuristic(y, (YamlMappingNode) b); _ => throw new ArgumentException($"Unrecognized YAML node type: {a.GetType()}", nameof(a))
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));
}
} }
public static float YamlSequencesHeuristic(YamlSequenceNode a, YamlSequenceNode b) public static float YamlSequencesHeuristic(YamlSequenceNode a, YamlSequenceNode b)