Fix warnings in Content.Tools module (#17862)
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Content.Tools
|
||||
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);
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Content.Tools
|
||||
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 @@ 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];
|
||||
}
|
||||
|
||||
public Dictionary<string, YamlMappingNode> ConvertTileChunks(YamlSequenceNode chunks)
|
||||
public static Dictionary<string, YamlMappingNode> ConvertTileChunks(YamlSequenceNode chunks)
|
||||
{
|
||||
var map = new Dictionary<string, YamlMappingNode>();
|
||||
foreach (var chunk in chunks)
|
||||
@@ -151,7 +151,7 @@ namespace Content.Tools
|
||||
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))
|
||||
return new byte[ExpectedChunkSize];
|
||||
@@ -197,7 +197,7 @@ namespace Content.Tools
|
||||
|
||||
public bool MergeEntities()
|
||||
{
|
||||
bool success = true;
|
||||
var success = true;
|
||||
foreach (var kvp in EntityMapFromOtherToOurs)
|
||||
{
|
||||
// For debug use.
|
||||
@@ -220,10 +220,13 @@ namespace Content.Tools
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -301,10 +304,11 @@ namespace Content.Tools
|
||||
|
||||
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 @@ namespace Content.Tools
|
||||
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:
|
||||
|
||||
@@ -11,15 +11,15 @@ namespace Content.Tools
|
||||
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<string>());
|
||||
return tmp2;
|
||||
case YamlScalarNode subScalar:
|
||||
YamlScalarNode tmp3 = new YamlScalarNode();
|
||||
var tmp3 = new YamlScalarNode();
|
||||
CopyYamlScalar(tmp3, subScalar);
|
||||
return tmp3;
|
||||
default:
|
||||
@@ -47,7 +47,7 @@ namespace Content.Tools
|
||||
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<string>());
|
||||
break;
|
||||
case YamlScalarNode subScalar:
|
||||
// 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)
|
||||
{
|
||||
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 @@ namespace Content.Tools
|
||||
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 @@ namespace Content.Tools
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user