Make prototype load ignore documents with empty values

This happens if you have a YAML file like this:

---
# commented prototype
---
# Real prototype
- type: bla

This case is generated by my (next commit) prototype file merger asset pass, and I don't see any harm in just skipping in this case.

Also improve the logging in general.
This commit is contained in:
PJB3005
2025-07-25 15:54:58 +02:00
parent 6b41be8901
commit 1ebac7c894

View File

@@ -52,21 +52,36 @@ public partial class PrototypeManager
return (file, Array.Empty<ExtractedMappingData>());
var extractedList = new List<ExtractedMappingData>();
var i = 0;
foreach (var document in DataNodeParser.ParseYamlStream(reader))
{
i += 1;
LoadedData?.Invoke(document);
var seq = (SequenceDataNode)document.Root;
foreach (var mapping in seq.Sequence)
switch (document.Root)
{
var data = ExtractMapping((MappingDataNode)mapping);
if (data != null)
{
if (ignored)
AbstractPrototype(data.Data);
case SequenceDataNode seq:
foreach (var mapping in seq.Sequence)
{
var data = ExtractMapping((MappingDataNode)mapping);
if (data != null)
{
if (ignored)
AbstractPrototype(data.Data);
extractedList.Add(data);
}
extractedList.Add(data);
}
}
break;
case ValueDataNode { Value: "" }:
// Documents with absolutely nothing in them get deserialized as this.
// How does this happen? Text file merger generates separate documents for each file.
// Just skip it.
break;
default:
sawmill.Error($"{file} document #{i} is not a sequence! Did you forget to indent your prototype with a '-'?");
break;
}
}