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

Scripting : Make MapEditor|TilesetEditor.currentWangSet and MapEditor|TilesetEditor.currentWangColorIndex writeable #4105

Merged
merged 7 commits into from
Nov 29, 2024

Conversation

dogboydog
Copy link
Contributor

@dogboydog dogboydog commented Nov 21, 2024

Fix #4101

currentWangSet setter: seems to be working:

tiled.mapEditor.currentWangSet = tiled.activeAsset.tilesets[0].wangSets[0] 

Currently crashing, I'm doing something wrong setting the currentWangColorIndex Edit: working :

tiled.mapEditor.currentWangColorIndex  = 2 

I didn't see an existing public method to change the selection so I tried to make one based on reading the rest of the code in wangdock.cpp . Maybe I missed something existing or just have a logic error in my setter. Visually at least, it seems to change the color selection though.

Causes crash:
image

TODO (@dogboydog )

  • Update NEWS
  • Update scripting doc

@bjorn
Copy link
Member

bjorn commented Nov 22, 2024

The error message is from QSortFilterProxyModel, and it says the QModelIndex you're using is from the wrong model. That's because mWangColorModel->colorIndex returns an index in the source model, which still needs to be mapped to the model used by the view (the mWangColorFilterModel).

I don't recall now what this sort-filter-model is used for (I couldn't immediately find a reason for it to exist in the current code). The easiest thing to do for now is to call mWangColorFilterModel->mapFromSource(index), as done in a slightly mode convoluted way in WangDock::editWangColorName.

Hmm, in fact, you could likely adjust WangDock::onColorCaptured, which is basically doing what you're after with WangDock::setCurrentWangColor.

Just note that there's an assert in WangColorModel::colorIndex, which should not be possible to trigger from script. Potentially we could just turn the assert into a regular condition and return QModelIndex() in that case.

@dogboydog
Copy link
Contributor Author

dogboydog commented Nov 22, 2024

Thanks, I think I implemented what you suggested. It's working without errors now.
I updated the scripting docs and NEWS.md

tiled_wangset._color.mp4

.gitignore Show resolved Hide resolved
src/tiled/mapeditor.cpp Outdated Show resolved Hide resolved
@bjorn
Copy link
Member

bjorn commented Nov 29, 2024

There's one remaining issue with this change, which is that the docs for the TilesetEditor are adjusted, but the change affects the MapEditor.

Rather than just fixing the docs change, it would probably be worth looking into making the properties also writable for the TilesetEditor. :-)

@dogboydog
Copy link
Contributor Author

Oh whoops. Sorry about that, I'll take a look.

@dogboydog
Copy link
Contributor Author

Added and seems to work for me locally in the Tileset editor as well.

@dogboydog dogboydog changed the title Scripting : Make MapEditor.currentWangSet and MapEditor.currentWangColorIndex writeable Scripting : Make MapEditor|TilesetEditor.currentWangSet and MapEditor|TilesetEditor.currentWangColorIndex writeable Nov 29, 2024
I guess this is enough.
@bjorn bjorn merged commit 6a994d1 into mapeditor:master Nov 29, 2024
13 of 14 checks passed
@dogboydog dogboydog deleted the 4101-wangset-scripting branch November 29, 2024 21:16
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

Successfully merging this pull request may close these issues.

Scripting : Make MapEditor.currentWangSet and MapEditor.currentWangColorIndex writeable
2 participants