FEATURE: Token Snap to Grid behaviour

Developer discussion regarding MapTool 1.4

Moderators: dorpond, trevor, Azhrei

Forum rules
Posting now open to all registered forum users.
Post Reply
User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

FEATURE: Token Snap to Grid behaviour

Post by Jagged »

Token Snap to Grid behaviour
The ability to specify as a token attribute, whether to snap to grid based upon the layer, token centre or top and left. Ideally with appropriate script commands. Default behaviour would be (as now) "based upon the layer".

In my opinion this is a missing piece of token control and management. When I build a token in a graphic tool I often have to consider on which layer it will be used most, which is not always clear, and adjust the transparent border accordingly. Current behaviour can also get in the way of some map automation, when I want to move things between some layers (a less frequent issue).

d4rkAlf
Cave Troll
Posts: 35
Joined: Thu Apr 16, 2015 9:48 am

FEATURE: setSnapToGrid

Post by d4rkAlf »

This is what I have so far:

Code: Select all

/* Sets whether the token should snap to the grid or not*/
if (functionName.equals("setTokenSnapToGrid")) {
	checkNumberOfParameters(functionName, parameters, 1, 2);

	Object param = parameters.get(0);
	String snapToGridString;
	if (param instanceof String) {
		snapToGridString = (String) param;
	} else {
		//TODO: should use the correct I18N string
		throw new ParserException(I18N.getText("macro.function.general.xxx", functionName, 0, param.toString()));
	}

	boolean snapToGrid;
	if (snapToGridString.equalsIgnoreCase("true")) {
		snapToGrid = true;
	} else if (snapToGridString.equalsIgnoreCase("false")) {
		snapToGrid = false;
	} else {
		//TODO: should use the correct I18N string
		throw new ParserException(I18N.getText("macro.function.general.xxx", functionName, 0, param.toString()));
	}

	Token token = getTokenFromParam((MapToolVariableResolver) parser.getVariableResolver(), functionName, parameters, 1);
	token.setSnapToGrid(snapToGrid);
	return "";
}
I have a couple of questions though. A) How does/should the parser handle boolean parameters? Right now scripters have to use a string "true" or "false" in my code. B) What should those internationalization strings actually be?

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: FEATURE: setSnapToGrid

Post by Jagged »

Duplicate thread: http://forums.rptools.net/viewtopic.php?f=86&t=25828
Perhaps one of the nice Mods will merge this for us? :)

Regarding the Parse Handler, this will be difficult to test at the moment because it appears as though ParserExceptions are not being handled by the Line Parser at the moment. Made a short post about it here

d4rkAlf
Cave Troll
Posts: 35
Joined: Thu Apr 16, 2015 9:48 am

Re: FEATURE: setSnapToGrid

Post by d4rkAlf »

Jagged wrote:Duplicate thread: http://forums.rptools.net/viewtopic.php?f=86&t=25828
Perhaps one of the nice Mods will merge this for us? :)

Regarding the Parse Handler, this will be difficult to test at the moment because it appears as though ParserExceptions are not being handled by the Line Parser at the moment. Made a short post about it here
Uhm, that code had nothing to do with the OP. It's just a new macro for scripters to set whether a token should snap to grid or not. It doesn't change anything about the behaviour of the snap-to-grid functionality.

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: FEATURE: Token Snap to Grid behaviour

Post by Jagged »

My bad!

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: FEATURE: Token Snap to Grid behaviour

Post by JamzTheMan »

FYI, all other functions can typically use 0 and 1 as well as true and false. And true/false are keywords so shouldn't be translated, no more than function names.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: FEATURE: Token Snap to Grid behaviour

Post by RPTroll »

Was this ever submitted as a pull request? I see one for a snaptogrid function but this one is different.
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: FEATURE: Token Snap to Grid behaviour

Post by Jagged »

Due to a mistake on my part, two threads have been merged here. One about setting "snap to grid" and one about "snap to grid behaviour". Which one did you mean?

Apologies again to Darkalf :(

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: FEATURE: Token Snap to Grid behaviour

Post by RPTroll »

The snap to grid function
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

Post Reply

Return to “MapTool 1.4”