Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
howprice opened this issue Jul 30, 2023 · 16 comments · Fixed by #3802
Closed

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

howprice opened this issue Jul 30, 2023 · 16 comments · Fixed by #3802
Assignees
Labels
bug Broken behavior.

Comments

@howprice
Copy link

howprice commented Jul 30, 2023

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
@howprice howprice added the bug Broken behavior. label Jul 30, 2023
@howprice howprice changed the title "Resolve object types and properties" behaviour differs between GUI and command line "Resolve object types and properties" export behaviour differs between GUI and command line Jul 30, 2023
@eishiya
Copy link
Contributor

eishiya commented Jul 30, 2023

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).

@howprice
Copy link
Author

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!

@eishiya
Copy link
Contributor

eishiya commented Jul 30, 2023

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.

@howprice
Copy link
Author

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?

@eishiya
Copy link
Contributor

eishiya commented Jul 30, 2023

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.

@howprice
Copy link
Author

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?

@eishiya
Copy link
Contributor

eishiya commented Jul 30, 2023

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.

@howprice howprice changed the title "Resolve object types and properties" export behaviour differs between GUI and command line CLI has no access to project information like custom types. Jul 30, 2023
@howprice
Copy link
Author

Done. Thank you very much for your support.

@bjorn bjorn self-assigned this Aug 3, 2023
bjorn added a commit to bjorn/tiled-dev that referenced this issue Aug 3, 2023
This allows the --export-map and --export-tileset parameters to use file
formats defined by extensions in the project, and also enables handling
of custom types.

Closes mapeditor#3797
@bjorn
Copy link
Member

bjorn commented Aug 3, 2023

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.

@howprice
Copy link
Author

howprice commented Aug 4, 2023

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

@howprice
Copy link
Author

howprice commented Aug 8, 2023

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?

@eishiya
Copy link
Contributor

eishiya commented Aug 8, 2023

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)

@howprice
Copy link
Author

howprice commented Aug 8, 2023

@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.

@bjorn bjorn closed this as completed in 018dd3a Jan 12, 2024
@bjorn
Copy link
Member

bjorn commented Jan 12, 2024

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

@howprice
Copy link
Author

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?

@bjorn
Copy link
Member

bjorn commented Jan 13, 2024

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Broken behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants