When handling the Nodes collection in MiniYaml, individual nodes are located via one of two methods:
// Lookup a single key with linear search.
var node = yaml.Nodes.FirstOrDefault(n => n.Key == "SomeKey");
// Convert to dictionary, expecting many key lookups.
var dict = nodes.ToDictionary();
// Lookup a single key in the dictionary.
var node = dict["SomeKey"];
To simplify lookup of individual keys via linear search, provide helper methods NodeWithKeyOrDefault and NodeWithKey. These helpers do the equivalent of Single{OrDefault} searches. Whilst this requires checking the whole list, it provides a useful correctness check. Two duplicated keys in TS yaml are fixed as a result. We can also optimize the helpers to not use LINQ, avoiding allocation of the delegate to search for a key.
Adjust existing code to use either lnear searches or dictionary lookups based on whether it will be resolving many keys. Resolving few keys can be done with linear searches to avoid building a dictionary. Resolving many keys should be done with a dictionary to avoid quaradtic runtime from repeated linear searches.
The cause of the crash was that the `RemoveSmudge` method only invokes `SharedRandom` in the else-branch of an if condition that is only taken when the `RenderPlayer` has fog visibility on the location (locations the `RenderPlayer` can see get removed from `dirty` in `TickRender`).
To add insult to injury, the `Type` field does not even need to get set since we are only using the `Sprite` field's `null` value as a marker to be picked up by the `TickRender` method. The `Type` field is only ever used twice in `AddSmudge`, in a branch of an if-condition that will not be taken when the `Sprite` field is null, which we set explicitly. The same holds true for the `Depth` field.
The actor and smudge definitions are now stored
as raw MiniYamlNodes in the map. It is now the
responsibility of the consumers to parse these
into real objects.