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

Auto-mapping rule map is inflexible and cumbersome for complex rules, allow lua script instead #946

Closed
ghost opened this issue May 15, 2015 · 9 comments

Comments

@ghost
Copy link

ghost commented May 15, 2015

I've just read through the auto-mapping introduction and while it seems useful for basic replacements, it seems way too cumbersome to maintain and use for advanced replacements like detecting all sort of wall tiles, then checking downwards to the distance of the next floor tile, and doing some shadow thing or something.

On the other hand, this would seem much more easily doable with a Lua script to me.

Therefore, is there any possibility you could add an alternate way of providing auto mapping via a Lua script? The Lua script should have a callback issued that is triggered always when the user places a tile, and should then get access to the changed tile coordinates as well as all tilelayer contents + tile layer names + filename of the tileset used on them (this allows to apply special rules according to the tileset image name being "watertiles01.png" or something, or a tile layer being named "ceiling").

@RPGHacker
Copy link
Contributor

Python could be an option, too, since that is already included as a plugin for Tiled.

@Ablu
Copy link
Contributor

Ablu commented May 15, 2015 via email

@ghost
Copy link
Author

ghost commented May 15, 2015

I think Lua or Javascript are both equally good choices, Python seems a bit too over the top. I am thinking of a one 200 lines file which I can hack together to implement all my rules, not a huge framework that can also cook my coffee ;-)

@bjorn
Copy link
Member

bjorn commented May 15, 2015

Well, a Python plugin was indeed already written, but I didn't write it and I don't like the generated API code so it's unlikely to be integrated further into Tiled, at least by me.

For me the choice is between Lua and JavaScript. I used to lean more towards Lua because it's a simpler language and it's used a lot in game development. But now I lean more towards JavaScript. This is mainly because having JavaScript API available should eventually also help with moving towards a Qt Quick based version of Tiled (I've made a little progress with this on the wip/qtquick branch).

In any case, adding scripting support is something I already wanted to do for a long time but didn't get around to yet, as with many things. Supporting me on Patreon helps me get around to things like this since I could spend more time on Tiled.

@bjorn
Copy link
Member

bjorn commented May 15, 2015

I've opened issue #949 about scripting in general, which also covers this use-case as part of "Hooking up to events to perform certain actions automatically". Closing this issue.

@bjorn bjorn closed this as completed May 15, 2015
@ghost
Copy link
Author

ghost commented May 16, 2015

Well I was more thinking of simply allowing a lua script to be specified in the rulefile, which in the easiest case just gets the arrays of the tile data and returns them back as a result.

Of course a general scripting API might cover this as well, but possibly more complicated for the user (if they need to learn/search the scripting API first) and possibly more complicated for you I suppose?

Therefore I suggest it might be worth looking into this as a separate thing.

@bjorn
Copy link
Member

bjorn commented May 17, 2015

Well I was more thinking of simply allowing a lua script to be specified in the rulefile, which in the easiest case just gets the arrays of the tile data and returns them back as a result.

Hmm, I'm not sure how this would work. You mean somehow passing the entire map as arrays into Lua and then getting some list of layers back? On the way in I guess it could use the Lua export plugin, but the way out would be rather harder. I personally think this is not less complicated than adding an API that the script could use to obtain information and to make changes to the map.

@ghost
Copy link
Author

ghost commented Oct 27, 2017

Hmm, I'm not sure how this would work. You mean somehow passing the entire map as arrays into Lua and then getting some list of layers back?

Yes exactly. Basically you'd need to write two C functions which interface with lua, one that serializes the map data of all layers and passes it to lua as a table, and one that takes a lua table and deserializes it back to the map data. It's the most easy way to do something resembling a script API.

Later on when you want to expand on it, you could add all sorts of callbacks to respond to UI things and add UI buttons etc. for a proper script API, but for a start this would be the easiest way to be able to script anything that helps with map creation (e.g. by auto tiling) without making a full-blown script API for more advanced plugins. The callback could simply run after each map change in the most simple invocation.

Edit: the same but instead with JavaScript would also be fine of course. I suggested lua since I found it particularly easy to interface with from C/C++ but it doesn't really matter what language it is

@bjorn
Copy link
Member

bjorn commented Oct 28, 2017

A map is a complex beast and serializing it into a Lua table and then deserializing it and somehow synchronizing the changes is not going to be trivial. I still think it would be easier to provide the scripting functions needed to request data from the map and change things.

Of course, I had expected to get around to this much sooner, but other new features have taken priority for getting out 1.0, as well as requests from patrons, and then the projects done as part of GSoC 2017. So scripting won't make it for 1.1, but I certainly hope to get to it in the near future.

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

No branches or pull requests

3 participants