Skip to content

Instantly share code, notes, and snippets.

@BaldarSilveraxe
Last active September 27, 2016 11:38
Show Gist options
  • Save BaldarSilveraxe/03119eb156980d15202bca20621e2bd1 to your computer and use it in GitHub Desktop.
Save BaldarSilveraxe/03119eb156980d15202bca20621e2bd1 to your computer and use it in GitHub Desktop.
/*global _, on, getObj, sendChat */
/*jslint browser: true, multivar: true, bitwise: true, es6: true */
var nudge_test = nudge_test || (function () {
"use strict";
var nudge_action = function (obj, nudge, twist) {
var character = obj.get("represents"), player;
if (_.isEmpty(character)) {
sendChat("API", "just the token. Nudged: " + nudge + " , Twist: " + twist + ".");
// Do something
} else {
player = getObj("player", getObj("character", obj.get("represents")).get("controlledby").split(/\s/)[0]);
if (_.isEmpty(player)) {
sendChat("API", "Token and character. Nudged: " + nudge + " , Twist: " + twist + ".");
// Do something.
} else {
sendChat("API", "Token, first player and character. Nudged: " + nudge + " , Twist: " + twist + ".");
// Do something.
}
}
},
change_graphic = function (obj, pre) {
var nudge = ((obj.get("left") !== pre.left) || (obj.get("top") !== pre.top))
&& ((Math.abs(obj.get("left") - pre.left) < 36) && (Math.abs(obj.get("top") - pre.top) < 36)),
twist = (obj.get("rotation") !== pre.rotation) && (Math.abs(obj.get("rotation") - pre.rotation) < 23),
cleanleft = ~~(obj.get("left") - 0.5),
cleantop = ~~(obj.get("top") - 0.5),
cleanrotation = ~~(obj.get("rotation") + 0.1);
nudge_action(obj, nudge, twist);
obj.set({
left: cleanleft - 0.5,
top: cleantop - 0.5,
rotation: cleanrotation - 0.1
});
},
events = function () {
on("change:graphic", change_graphic);
};
return {
events: events
};
}());
on("ready", function () {
"use strict";
nudge_test.events();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment