dcronqvist / DotTiled

📚 A .NET library for loading Tiled maps and tilesets
https://dcronqvist.github.io/DotTiled
MIT License
20 stars 4 forks source link

TMX custom string properties with newlines are not properly handled #45

Open Metraberryy opened 1 week ago

Metraberryy commented 1 week ago

I have a custom string property on an object When the string is only one line, it has a value property as the parser expects:

<properties>
  <property name="Text" value="test"/>
</properties>

but when I add a newline in Tiled, the string becomes content of the tag:

<properties>
  <property name="Text">test
text</property>
</properties>

and an exception is thrown when DotTiled tries to parse it:

Unhandled exception. System.Xml.XmlException: value attribute is required
   at DotTiled.Serialization.Tmx.ExtensionsXmlReader.GetRequiredAttribute(XmlReader reader, String attribute)
   at DotTiled.Serialization.Tmx.TmxReaderBase.<ReadProperties>b__33_0(XmlReader r)
   at DotTiled.Serialization.Tmx.ExtensionsXmlReader.ReadList[T](XmlReader reader, String wrapper, String elementName, Func`2 readElement)
   at DotTiled.Serialization.Tmx.TmxReaderBase.ReadProperties()
   at DotTiled.Serialization.Tmx.TmxReaderBase.<>c__DisplayClass19_0.<ReadObject>b__1()
   at DotTiled.Serialization.Tmx.ExtensionsXmlReader.ProcessChildren(XmlReader reader, String wrapper, Func`3 getProcessAction)
   at DotTiled.Serialization.Tmx.TmxReaderBase.ReadObject()
   at DotTiled.Serialization.Tmx.TmxReaderBase.<>c__DisplayClass18_0.<ReadObjectLayer>b__3()  
   at DotTiled.Serialization.Tmx.ExtensionsXmlReader.ProcessChildren(XmlReader reader, String wrapper, Func`3 getProcessAction)
   at DotTiled.Serialization.Tmx.TmxReaderBase.ReadObjectLayer()
   at DotTiled.Serialization.Tmx.TmxReaderBase.<>c__DisplayClass17_0.<ReadMap>b__8()
   at DotTiled.Serialization.Tmx.ExtensionsXmlReader.ProcessChildren(XmlReader reader, String wrapper, Func`3 getProcessAction)
   at DotTiled.Serialization.Tmx.TmxReaderBase.ReadMap()
   at DotTiled.Serialization.Tmx.TmxMapReader.ReadMap()
   at DotTiled.Serialization.MapReader.ReadMap()
   at DotTiled.Serialization.Loader.LoadMap(String mapPath)
dcronqvist commented 1 week ago

Nice find! Currently away on vacation but will take a look in a few days :)