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: Assigned map.selectedLayers displays incorrectly #3451

Open
eishiya opened this issue Aug 14, 2022 · 0 comments · May be fixed by #3512
Open

Scripting: Assigned map.selectedLayers displays incorrectly #3451

eishiya opened this issue Aug 14, 2022 · 0 comments · May be fixed by #3512
Labels
bug Broken behavior.

Comments

@eishiya
Copy link
Contributor

eishiya commented Aug 14, 2022

When assigning to TileMap.selectedLayers, if the assigned array has its layers in any order other than ascending by layer ID and doesn't contain every layer in the map, the layers will be selected, but the Layers panel will only highlight the bottom-most layer. I confirmed that the layers were selected via Highlight Current Layer, and via tiled.activeAsset.selectedLayers.

Here for example, I selected all "Invalid" layers via script, in order from bottom to top (the same order they appear in map.layers). The layers are sorted by their ID (which I've added to their layer name, for convenience), so everything is highlighted correctly:
image
But here, I've switched layers 2 and 3, so they're no longer in ascending order, and thus only the bottom-most selected layer is highlighted (but all three layers are actually selected):
image

Sorting the layers prior to assigning to map.selectedLayers works to correctly highlight all layers regardless of order:

invalidLayers.sort(function(a,b) {return a.id - b.id;});
map.selectedLayers = invalidLayers;

Selecting every layer in the map also highlights the layers correctly, regardless of their order in the array.

@eishiya eishiya added the bug Broken behavior. label Aug 14, 2022
lhiginbotham added a commit to lhiginbotham/tiled that referenced this issue Oct 24, 2022
	- fixes mapeditor#3451 where layer selection highlighting was bugging out if the newly set selection was not ordered by layer ID
	- this seems to be an event interplay issue with the following sequence:
		- script sets the layer selection to some array
		- first step in handling that is to set the currently selected layers to be the full array, triggering LayerView::selectedLayersChanged to select the whole range
		- second step is to make sure that the mCurrentLayer variable is pointing to an object within that array selection, which in this bad cause it is not, so we end up calling setSelectedLayers with one item, triggering LayerView::selectedLayersChanged again with a single item and effectively clearing out the selection we had just highlighted
	- first this by doing the second step before the first step
lhiginbotham added a commit to lhiginbotham/tiled that referenced this issue Oct 24, 2022
	- fixes mapeditor#3451 where layer selection highlighting was bugging out if the newly set selection was not ordered by layer ID
	- this seems to be an event interplay issue with the following sequence:
		- script sets the layer selection to some array
		- first step in handling that is to set the currently selected layers to be the full array, triggering LayerView::selectedLayersChanged to select the whole range
		- second step is to make sure that the mCurrentLayer variable is pointing to an object within that array selection, which in this bad case it is not, so we end up calling setSelectedLayers with one item, triggering LayerView::selectedLayersChanged again with a single item and effectively clearing out the selection we had just highlighted
	- first this by doing the second step before the first step
lhiginbotham added a commit to lhiginbotham/tiled that referenced this issue Oct 24, 2022
	- fixes mapeditor#3451 where layer selection highlighting was bugging out if the newly set selection was not ordered by layer ID
	- this seems to be an event interplay issue with the following sequence:
		- script sets the layer selection to some array
		- first step in handling that is to set the currently selected layers to be the full array, triggering LayerView::selectedLayersChanged to select the whole range
		- second step is to make sure that the mCurrentLayer variable is pointing to an object within that array selection, which in this bad case it is not, so we end up calling setSelectedLayers with one item, triggering LayerView::selectedLayersChanged again with a single item and effectively clearing out the selection we had just highlighted
	- fix this by doing the second step before the first step
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.

1 participant