Currently the Python plugin depends on Python 2.7. This version is increasingly old, as one can read on the Python website:
Short version: Python 2.x is legacy, Python 3.x is the present and future of the language
The Python plugin shipping with Tiled was originally developed by @stt. I've since made minor changes, mostly to keep it compiling and to adjust it to changes to the interfaces it implements. But it has never seen proper maintenance, and I'm personally too occupied with other issues to spend time making sure the Plugin is really usable (there are no autotests), to document its use (it's currently not mentioned in the manual at all). The plugin is also not shipping with the 64-bit version of Tiled for Windows, which actually happens to be the most popular download (this is because I haven't figured out how to set up the project files to enable the plugin for Visual Studio builds).
So, there is actually a lot to do on this plugin, but I think updating it to the latest version of Python would be a good first step. Here's a list of issues covering the other things:
Note that if possible this should be done without relying on any compatibility flags (not sure if they have any).
I want to start to work on it, but now plugin is broken, when you changed Tileset constructor to Tileset::create method that return SharedTileset:
https://github.com/bjorn/tiled/commit/76ff87ef000cce3fc1d42cb7f731d83539b55ab7#diff-591ba88253b6f97f78a5056aa45dd84c
All python scripts calls old constructor of Tileset, that don't exist.
I didn't find a way to auto-conversion from SharedTileset to Tileset back in pybindgen
(looks like cls_sharedtileset.implicitly_converts_to(cls_tileset) must do it, but it didn't work for me - http://pythonhosted.org/PyBindGen/cppclass.html), so I just wrap .data() function of SharedPointer
If this is normal way, you can apply my patch for it
fix_converstion.zip
And then, I'll rewrite all example scripts to fix them, for example, for fotf.py, code will looks like:
t = Tiled.Tileset.create('DECOR', 16,16, 0, 0)
t.data().loadFromImage(fr.readtilegfx(gfxf), '') #convert from SharedTileset to Tileset
After that it will be possible to update python version and to do other stuff
Hey @spiiin, thanks for your interest in helping with this!
I probably knew I would break some stuff when I added that "create" method, but I totally forgot to update the plugins. Of course, I'd prefer this to be implicit on the Python side, but the explicit approach would already be an improvement over the current broken state. Can you open a PR with your patch and adjustments of the example scripts?
https://github.com/bjorn/tiled/pull/1769
It's my first pull request, so I hope, I am doing it right :)
I'll continue to work on original issue
Hey guys, missed the github notification of this in October and just happened to notice it now. Wasn't really involved with games for a few years and kinda forgot about the plugin. Added the py3 support in my fork, making a pull req in a bit.
The Visual Studio environment that the builds in 2012 were made with is gone but I don't remember there being anything that special involved, will take a look.
I also made python 3 support already, but stuck on porting example scripts for games to python 3. It's really hard to port it for me.
Ah, well, the two common things in the scripts that needed changing would've probably been caught by 2to3 tool (print is now a function and dict.has_key has been replaced by in-operator).
Only functional difference to py3 is with file handles opened in binary mode, calling read() returns a bytes-object. Asking a bytes object for index gives numeric value while we'd like to have bytes for processing purposes, we can use a slice for that (i.e. bytes([1,2,3])[0] == 1 vs. bytes([1,2,3])[0:1] == b'\x01').
The other changes weren't strictly necessary, but it was nice to finally to get around to forcing pybindgen to sort the class method output instead of random order, so the C++ diffs are cleaner in future.
The other changes weren't strictly necessary, but it was nice to finally to get around to forcing pybindgen to sort the class method output instead of random order, so the C++ diffs are cleaner in future.
It's weird how this is necessary... actually I think the situation was worse before, but indeed it was still changing order when adding/removing stuff. Thanks for finding a workaround to that!
Also, thanks a lot for returning to this plugin for the update! I'll try to get around to reviewing the changes soon.