anno-mods / FileDBReader

A command line tool for working with a proprietary bluebyte file compression used in Anno 2205 and 1800.
15 stars 4 forks source link

Empty ReferenceArrays export without size tag #28

Closed Shad0wlife closed 1 year ago

Shad0wlife commented 1 year ago

Empty Reference arrays should export without size tag (eg. AnimalHandler->HerdAreas->None->DangerPoints). The deserializer already accepts empty/self-closing tags as Reference Arrays, but currently empty Reference Arrays export with a tag.

This used to be intended behaviour to allow Reference Arrays with a 0 tag, and the empty array would be done with a null ReferenceArray and a corresponding FileDBSerializerOption, but that leads to the effect that there is a discrepancy when deserializing data and directly serializing it again.

This change makes it so that a ReferenceArray tag with 0 can never be exported, and reading a ReferenceArray with only 1 child in the tag throws an error.

A UnitTest to confirm that an error is thrown when deserializing a ReferenceArray with exactly 1 child tag was added (ErrorOnInvalidReferenceArray). The SkipSimpleNullValues UnitTest was adapted to match the new default behaviour.

An additional UnitTest was added to ensure that deserializing and then serializing an empty ReferenceArray keeps the xml document the same.

Also, a mistake with the FileDBDocumentDeserializer was resolved, as its top layer handler should act like the ReferenceTypeHandler does (iterate over the FileDBNodes), but it acted differently (iterated over target type properties).