Unable to load tileset image through scripting

I try to create a plugin to load rpg maker xp maps/tilesets. One of the issues I run into is that it seems that I’m unable to load the tileset image? I have build a small testcase and tested it against the latest snapshot (Version 2020.01.22). I use Windows 10. Both relative and absolute paths don’t seem to work.

tiled testcase.zip (1023 Bytes)

Other issues I’m running into are (though to be fair I haven’t tested these in the latest snapshot):

  • Cannot load multiple tilesets at once when opening a single file (rmxp has ~50 tilesets in the file ‘Tilesets.rxdata’). Possible workarounds are ask for an id to open, or create lots of new tilesets

  • Arrow function expressions makes the keyword ‘this’ undefined. Workaround before arrow function use ‘const ctx = this;’. Kind of the defeats the purpose of arrow functions though.

  • console.log doesn’t accept %s and %o. Workaround: just use + variable +.

  • I get a type error while trying to set the name of an error object:
    class CustomError extends Error {
    constructor(message) {
    super(message);
    // This doesn’t seem to work for some reason:
    this.name = this.constructor.name;
    }
    }

    throw new CustomError(‘Test’);

Workaround: Don’t set the name of custom errors…

Hmm, while relative for sure is unlikely to work, the absolute path should work. I just tested this on Linux and when enabling the absolute code path the image loaded for me:

        //const finalPath = './tileset.png';
        const finalPath = path + '/tileset.png';

Console output:

qml: /home/bjorn/tiled-tests/open_me.txt
qml: Filename tileset: /home/bjorn/tiled-tests/open_me.txt
qml: Path: /home/bjorn/tiled-tests
qml: Filename image: /home/bjorn/tiled-tests/tileset.png

Then, I tested it again with Qt 5.12 instead of 5.14, and then it stopped working. It appears that Qt 5.12 is not able to load this particular PNG (I also can’t open it in my image viewer). In fact, while you named this png it doesn’t actually seem to be a PNG:

bjorn@thor:~/tiled-tests$ file tileset.png 
tileset.png: PC bitmap, Windows 3.x format, 64 x 32 x 24

I would suggest to try with a valid PNG file.

Right, there would need to be some way to indicate which tileset to load in that case, but we just have the file name. Can potentially be worked around by creating small dummy files like foo.rxtileset with contents:

{
    "data": "Tilesets.rxdata",
    "tileset": "foo"
}

These could be generated on-demand by the plugin, and the plugin could then load these files as tilesets.

Potential JavaScript engine issue. Worth trying if it is fixed in Qt 5.14 (current binaries are built against Qt 5.12.6). However, I couldn’t really reproduce it using either version. Do you have an example of where this breaks?

Are you sure this is part of ECMAScript 6? In any case, you can use template literals if you prefer (`foo ${variable} bar`).

Puh, that’s a bit weird I guess, especially since Qt does have the name property on the error objects (https://doc.qt.io/qt-5/qjsengine.html#script-exceptions). I still see this problem in Qt 5.14.1. If it’s important you could consider opening an issue on the Qt bug tracker.

In any case, that’s really great that you’re trying to write a loader for RPG Maker maps & tilesets! Please let me know if I can help in any other way.