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: Changing layer.height/width causes incorrect redraw #3481

Closed
eishiya opened this issue Sep 25, 2022 · 1 comment
Closed

Scripting: Changing layer.height/width causes incorrect redraw #3481

eishiya opened this issue Sep 25, 2022 · 1 comment
Labels
bug Broken behavior.

Comments

@eishiya
Copy link
Contributor

eishiya commented Sep 25, 2022

When resizing a layer via layer.width and layer.height, even if those added rows/columns are within the map bounds, Tiled will not draw them correctly.

Here's a small script that demonstrates the issue:

var changeLayerSize = tiled.registerAction("LayerSizeTest", function(action) {
	let map = tiled.activeAsset;
	if(!map || !map.isTileMap || map.infinite)
		return;

	map.macro("Layer Size Test", function() {
		//Resize the map:
		map.height = map.height + 3;
		map.width = map.width + 3;
		
		let layer = map.layerAt(0);
		let tile = layer.tileAt(0,0);
		
		//Resize the layer:
		layer.height = layer.height + 3;
		layer.width = layer.width + 3;
		
		let layerEdit = layer.edit();
		//Fill new columns with tiles:
		for(let y = 0; y < layer.height; ++y) {
			layerEdit.setTile(layer.width-1, y, tile);
			layerEdit.setTile(layer.width-2, y, tile);
			layerEdit.setTile(layer.width-3, y, tile);
		}
		//Fill new rows with tiles:
		for(x = 0; x < layer.width; x++) {
			layerEdit.setTile(x, layer.height-1, tile);
			layerEdit.setTile(x, layer.height-2, tile);
			layerEdit.setTile(x, layer.height-3, tile);
		}
		layerEdit.apply();
	});
});
changeLayerSize.text = "Layer Size Test";

tiled.extendMenu("Edit", [
	{ action: "LayerSizeTest", before: "Preferences" },
	{separator: true}
]);

This script extends the current map by 3 in width and height, extends its 0th layer by the same, and fills the new rows/columns with the tile that's in the top left corner.
This is what I expect to see after running it:
image
But this is what I actually get:
image
The "blank" tiles are populated - I can see the tile ID in the status bar, I can copy+paste them. If I save the map and reopen it, I get the expected result above. But for some reason, only the row/col immediately next to the old edge of the layer gets drawn while the others are not, and even those are drawn rather tentatively, they're not redrawn when the region next to them is drawn.

I imagine this has something to do with the fact that layer.width/height don't affect layer contents, but layer.resize(). which does affect contents, has its own problems (#3480), and I expect these "manual" size changes to still work fine as long as the resulting map size, layer size, and tile contents are all sensible, which I believe they are in this case.

@eishiya eishiya added the bug Broken behavior. label Sep 25, 2022
@bjorn bjorn closed this as completed in 44e16a3 Sep 27, 2022
@bjorn
Copy link
Member

bjorn commented Sep 27, 2022

I had missed updating the bounding rect of the graphics item representing the tile layer, in case of changing these properties. :-(

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

No branches or pull requests

2 participants