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

Automap rule file should ignore object layers. #3262

Closed
kenakofer opened this issue Feb 3, 2022 · 6 comments
Closed

Automap rule file should ignore object layers. #3262

kenakofer opened this issue Feb 3, 2022 · 6 comments
Assignees
Labels
feature It's a feature, not a bug.

Comments

@kenakofer
Copy link

I want to add comments to my automapping rule file using text in an object layer, but currently can't figure out any way to do so.

When I add an object layer in the rule file, running the rule file will complain that the name of the object layer is not one of the allowed input*, output*, or region* possibilities.

(If I change its name to something like "region", it will complain that input* output*, and region* must be tile layers, but that's what I expected.)

I think it would be a reasonable default behavior for Tiled to ignore non-tile layers without errors during automapping.

I'd also be happy for any advice on a workaround for me to add comments to my rule files!!

Thanks a bunch! 😃

@eishiya
Copy link
Contributor

eishiya commented Feb 4, 2022

I think this would be better solved by making it possible to mark layers as comments (e.g. comment_LayerName) rather than by ignoring entire layer types. Also, Object Layers are valid output layers xP And it's possible one day they may become valid input layers.

It might be nice if any invalidly named layers were just ignored instead of raising errors. But if that's likely to confuse people, then an explicit comment marker would be good.

I use region_somethingInvalid as successful comment layers, seems to work for object layers too. So, for now, perhaps you can use regions_comment? Pretty sure this is an oversight, and a proper way to add comment layers would still be nice.

@bjorn
Copy link
Member

bjorn commented Feb 4, 2022

What if we just added layer name prefix "//" for commenting out a layer? Would also be nice for temporarily disabling a layer.

@bjorn bjorn added the feature It's a feature, not a bug. label Feb 4, 2022
@bjorn bjorn closed this as completed in 0582cf6 Feb 4, 2022
@bjorn bjorn self-assigned this Feb 4, 2022
@bjorn bjorn added this to Tiled 1.8 Feb 4, 2022
@bjorn bjorn moved this to Done in Tiled 1.8 Feb 4, 2022
@eishiya
Copy link
Contributor

eishiya commented Feb 4, 2022

// is fantastic, thank you! Naturally, here's a script to toggle // on selected layer(s), which you can hotkey:

/* 	Toggle // by eishiya, last updated 4 Feb 2022

	Adds an action to the Layers menu that adds or removes // to/from
	selected Layers' names, useful for disabling layers in Automapping.
	
	Group Layer names are left untouched, since Automapping ignores them.
*/

var toggleCommentLayer = tiled.registerAction("ToggleCommentLayer", function(action) {
	// Should the state of each layer be toggled individually,
	// or based on the state of the bottom-most layer?
	let toggleIndividually = false;
	
	
	let map = tiled.activeAsset;
	if(!map || !map.isTileMap) {
		return;
	}

	let lastSeenCommented = null;

	map.macro("Toggle //", function() {
		let selectedLayers = map.selectedLayers;
		for(let li = 0; li < selectedLayers.length; ++li) {
			let curLayer = selectedLayers[li];
			if(curLayer.isGroupLayer) //ignore group layers
				continue;
			if(curLayer.name.indexOf("//") == 0) { //commented
				if(lastSeenCommented === null) lastSeenCommented = true;
				if(toggleIndividually || lastSeenCommented === true)
					curLayer.name = curLayer.name.substring(2).trim();
			} else { //uncommented
				if(lastSeenCommented === null) lastSeenCommented = false;
				if(toggleIndividually || lastSeenCommented === false)
					curLayer.name = "//" + curLayer.name;
			}
		}
	});
});
toggleCommentLayer.text = "Toggle //";

tiled.extendMenu("Layer", [
    { action: "ToggleCommentLayer", before: "LayerProperties" },
	{separator: true}
]);

You can customize the toggling behaviour by changing whether toggleIndividually is true or false. By default, it's false, which means all layers will be toggled to the same state, which I usually find more helpful. If you want individual toggling, set it to true. Note that the script iterates from the bottom up, so when this is false, it'll be the bottom layer that determines which way the others are toggled.

@bjorn
Copy link
Member

bjorn commented Feb 4, 2022

@eishiya Amazing! I guess we'll see that in https://github.com/eishiya/tiled-scripts soon. :-)

@eishiya
Copy link
Contributor

eishiya commented Feb 4, 2022

I wasn't planning to put it there, otherwise I'd have just posted a link xP But I guess I should add this to my Automapping Helper script.

@kenakofer
Copy link
Author

Wow, what a fine solution, and so prompt too! Y'all are incredible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature It's a feature, not a bug.
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants