Do you want to work on this issue?
You can request for a bounty in order to promote it!
Include the type for custom classes in JSON #3820
ForeverZer0 posted onGitHub
Describe the bug The JSON output for custom classes lacks detailed information about the custom class, and is given simply as a list of key/value pairs. This differs from XML-based format, where they are given as complete property definitions.
Consider the following possible JSON output of a property with a custom class:
{
"name":"Something",
"propertytype":"MyClass",
"type":"class",
"value": {
"SomeString":"#ff000000",
"SomeNumber": 0
}
}
Without first reading the "propertytypes.json", which appears to be a editor-specific file, and not part of the TMX spec, how would one determine these value types? Is SomeString
a string or a color? Is SomeNumber
a float or an integer? This poses a problem when parsing, especially with statically-typed languages.
I am writing general-purpose parser, and encountered this issue when implementing the JSON format it. The XML-based format includes this information, and does not require reading "propertytypes.xml". Compare to the equivalent XML output:
<property name="Something" type="class" propertytype="MyClass">
<properties>
<property name="SomeString" value="#ff000000"/>
<property name="SomeNumber" type="int" value="0"/>
</properties>
</property>
There is no ambiguity here, nor need to require the user to provide additional files to load or class definitions in order to determine the custom class types. One can easily parse it out exactly as they would parse any other <properties>
tag.
While the "propertytypes" outputs are pretty much self-documenting, they are not part of the format documentation, and seem like misc. project files related to Tiled, not something to be shipped with a game, etc. This make it somewhat unclear if loading them is indeed the idiomatic way to process the JSON format. Considering the XML format would not need them, and they use the more generic xml/json extensions, the documentation may benefit from some additional clarity regarding them.
To Reproduce Steps to reproduce the behavior:
- Create a custom class.
- Save it as JSON.
Expected behavior The value of the property contains full property definitions like its XML counterpart, and not abbreviated key/value pairs.
Specifications:
- OS: Arch Linux (btw)
- Tiled Version: 1.10.2