mapeditor/tiled

CLI has no access to project information like custom types. #3797

howprice posted onGitHub

Describe the bug Due to lack of project information "Resolve object types and properties" export behaviour differs between GUI and command line. When a map is exported from the commmand line with the --resolve-types-and-properties option, default class property values - from the .tiled-project file - are not available, so are not written into the .tmx file. The properties are present when exported from the GUI with the equivalent option.

This limits the usefulness of the CLI for asset build scripts.

To Reproduce

Please see attached zip for simple repro

property-export-bug.zip

Steps to reproduce the behavior:

Create a project with a custom class and object using default properties:

  1. Open Tiled
  2. New Project
  3. Open the Custom Types Editor. Add Class "Enemy".
  4. Add string Member "Name" Value "DefaultEnemyName"
  5. Close Custom Types Editor
  6. New Map (use defaults)
  7. New Object Layer
  8. Insert Rectangle. Name: "Enemy1" Class: "Enemy". Important: Do not modify the Name property - leave as default.
  9. Save Map as map.tmx

Export from the Tiled GUI:

  1. Edit > Preferences... > General > Export Options > Check only "Resolve object types and properties"
  2. File > Export As... Save as type: Tiled map files File name: map_export_gui.tmx

Export from the Windows command line:

  1. Open Windows command line
  2. CD to project directory
  3. "C:\Program Files\Tiled\tiled.exe" --export-map tmx --resolve-types-and-properties map.tmx map_export_cmd.tmx

Compare/diff map_export_gui.tmx vs map_export_cmd.tmx

Expected behavior I would expect map_export_gui.tmx to be identical to map_export_cmd.tmx

In the above (and attached) repro case, the GUI-exported file contains the default resolved properties:

<object id="1" name="Enemy1" type="Enemy" x="160" y="64">
    <properties>
        <property name="Name" value="DefaultEnemyName"/>
    </properties>
</object>

Whereas the command line exported file contains the object, but with no properties:

<object id="1" name="Enemy1" type="Enemy" x="160" y="64"/>

Media Please see attached zip for repro

property-export-bug.zip

Specifications:

  • OS: Windows 10
  • Tiled Version: 1.10.1

This is a known issue. When you use the CLI, there's no project loaded, so it can't know what properties go with your classes. The solution to this would be to provide something like a --project parameter so you can specify the project file to use.

A workaround for now is to use a custom export format that makes a copy of the map, resolves the values (e.g. by parsing the project file, or having the values hard-coded), and then writes out the file in the actually desired format (you can access an existing format you want via tiled.mapFormat(shortname), and you can write the map using the MapFormat's write(map, fileName) method).

posted by eishiya over 1 year ago

Thanks. That explanation makes perfect sense. I should have thought of that.

Thanks for the workaround. I'll have a look at the existing exporter and command line interface and see if I can figure something out. Hopefully someone will be able to share a fix before I get started!

posted by howprice over 1 year ago

Regarding the workaround, I fear I didn't make it very clear: this would have to be a custom format script, using the scripting API. This is not something you can do via the CLI parameters, and the existing TMX code will probably not have anything you need because it's doing different work, and is a different language (C++, whereas scripting is JavaScript).

This script for copying/pasting layers may be of use in writing code to clone the map (necessary because the TileMap passed into write() is read-only), but I am not aware of any public script for resolving the class properties, though I know people have tackled that issue via scripting.

posted by eishiya over 1 year ago

Hm. Thanks. I'm really a C++ programmer and I don't want to get too distracted if this turns out to be a big task. I'll have a look though.

The simplest workaround is to manually export all the maps from the GUI. Not ideal, but I might be able to live with it. Is it possible to write simple script to control the GUI? Perhaps I could add a command that Exports on Save, or a script to export all tmx files in the project (or from a list in a file). Is this possible?

posted by howprice over 1 year ago

Yes, that's doable via scripting, but there's also a built-in "Repeat last export on save" option in the Preferences that may do what you need.

posted by eishiya over 1 year ago

Haha. Perfect! I'll just use that preference for now.

It sounds like the lack off access to the project on the command line is the issue that really needs fixing; is there a pre-existing issue I can follow, or is this it?

posted by howprice over 1 year ago

I think this issue might be it. It's been discussed multiples times elsewhere, but I don't think anyone's opened an actual issue before. At least, I couldn't find one.

For clarity, it might be good to edit the title and first post of this one to reflect the specific problem, i.e. that CLI has no access to project information like custom types.

posted by eishiya over 1 year ago

Done. Thank you very much for your support.

posted by howprice over 1 year ago

I've added the --project command-line parameter in #3802. Any help with testing it would be appreciated. I verified on Linux that it allowed me to use file formats defined in the project-specific extensions folder as well as basic handling of custom classes and enums.

Given that I planned for the next release to be a 1.10.2 patch release, I'll wait with merging this until after the release, to be included in Tiled 1.11.

posted by bjorn over 1 year ago

Hi Thorbjørn. Many thanks for this. I'll test on Windows as soon as I can.

posted by howprice over 1 year ago

I've added the --project command-line parameter in #3802. Any help with testing it would be appreciated.

Is the Tiled installer (Windows (64-bit, Qt 6) I guess) from this build available, or will I need to build locally?

posted by howprice over 1 year ago

Is the Tiled installer (Windows (64-bit, Qt 6) I guess) from this build available, or will I need to build locally?

You can download the auto-builds here: https://github.com/mapeditor/tiled/actions/runs/5753294396?pr=3802 (scroll down)

posted by eishiya over 1 year ago

@bjorn I've tested this on Windows and it seems to be working just fine thanks. I don't have any custom file formats, but it seems to be working fine for the custom enums and classes I use.

For my set of levels, the output from the CLI is now identical to that from the GUI (except for tiledversion obviously).

Please let me know if I need to do anything on this issue or the pull request.

posted by howprice over 1 year ago

@howprice Thanks for testing! I've finally merged it for the next release now. :-)

posted by bjorn over 1 year ago

Thanks for implementing this. I'll keep an eye out for the next release. What is the best way to receive notifications or new releases?

posted by howprice over 1 year ago

@howprice Tiled itself would notify you about a new release in its taskbar, unless disabled. To get a notification in your email, you can subscribe to the "Releases" on GitHub here:

image

At least, if you have GitHub configured to send you emails on notifications.

If you log in to itch.io, you can also follow me there to get notified about releases: https://thorbjorn.itch.io/tiled (top right corner).

posted by bjorn over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests