Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Is there any way to detect token "nudge" with snapping on?

1474844833
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
cuz I think there is.... 
1474846461
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
1474847744
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
1474848089
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
More subtle.... This gives dragification detection with grid snapping "on" and isdrawing false. So... a "buttonish" UI for a token. You corrupt the "left" value with obj.set("left", obj.get("left") + 0.1); Nudging invokes snapping... which removes that "+ 0.1" and triggers the on("change:graphic", events.change_graphic); event. Still playing with the idea... might be useful.
1474851135
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
<a href="https://gist.github.com/BaldarSilveraxe/03119eb156980d15202bca20621e2bd1" rel="nofollow">https://gist.github.com/BaldarSilveraxe/03119eb156980d15202bca20621e2bd1</a>
1474857042
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Huh, that could be rather useful.
1474887246
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
&nbsp; &nbsp; var nudge_action = function (obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var character = obj.get("represents"), player; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (_.isEmpty(character)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("API", "just the token"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // You have just the token. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Do something &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player = getObj("player", getObj("character", obj.get("represents")).get("controlledby").split(/\s/)[0]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (_.isEmpty(player)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("API", "Token and character"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // You have token and the character. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Do something. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("API", "Token, first player and character."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // You have the token, first player in the controlby and thecharacter. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Do something. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; },
1474887540
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I think so.... A "quick command list" spammed to the API when you have the player for example. Or create other dragification token under the player control on the fly.... or a second token with its on tokenactions.... or cheesy&nbsp;onamonapia that time out....&nbsp; It just a nearly "token-click" interface option.&nbsp;
1474888174

Edited 1474888231
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
If you were&nbsp;ambitious you could delete and recreate the token.... this would force "deselect" by the player... ... now you would have a way to cycle through a long list of token actions. ... you could even use the status colors or token status "numbers" to give a visual cue of what subset of token actions the player had active.&nbsp;
1474945032
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Rotation throws a wrinkle into it..... it creates off grid snap values. You have to pad the left side of the value with a 0. See below (I will update the gist posted above tomorrow. update_node = function (obj, pre) { var nudge = ((obj.get("left").toString() !== pre.left.toString()) || (obj.get("top").toString() !== pre.top.toString())) && ((Math.abs(obj.get("left") - pre.left) &lt; 40) && (Math.abs(obj.get("top") - pre.top) &lt; 40)), spun = (obj.get("rotation").toString() !== pre.rotation.toString()) && (Math.abs(obj.get("rotation") - pre.rotation) &lt; 22), cleanleft = Number(obj.get("left")) || ~~obj.get("left"), cleantop = Number(obj.get("top")) || ~~obj.get("top"), cleanrotation = Number(obj.get("rotation")) || ~~obj.get("rotation"); obj.set({ left: "0" + cleanleft, top: "0" + cleantop, rotation: "0" + cleanrotation }); },
1474945766
vÍnce
Pro
Sheet Author
What is this nonsesne?
1474947990
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
You get to approve the sausage.... not the&nbsp;sausage making.
1474948173
vÍnce
Pro
Sheet Author
lol
Stephen S. said: You get to approve the sausage.... not the&nbsp;sausage making. loooooooooooool This is easily... the &nbsp;best line I have read on Roll20. :P
1474973846
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Freaky..... seems to break DLing. obj.set({ left: "0" + cleanleft, top: "0" + cleantop, rotation: "0" + cleanrotation });
1474975785
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Updated &nbsp;the gist. Seems to work.... <a href="https://gist.github.com/BaldarSilveraxe/03119eb156" rel="nofollow">https://gist.github.com/BaldarSilveraxe/03119eb156</a>... I guess the API clean up for the left/top token placement on the canvas and the left/top for DL are somewhat different. I think the most practical application for this would be some sort of GM interface. A quick drag of a token spams abbreviated character data in the chat for example.