Skip to content

Instantly share code, notes, and snippets.

@shdwjk
Last active August 29, 2015 14:11
Show Gist options
  • Save shdwjk/d67c07ba49e1a57a1c0f to your computer and use it in GitHub Desktop.
Save shdwjk/d67c07ba49e1a57a1c0f to your computer and use it in GitHub Desktop.
Roll20 API: A command wrapped version of the Darkness Closing In API sample script.
// GIST: https://gist.github.com/shdwjk/d67c07ba49e1a57a1c0f
var DarknessClosingIn = DarknessClosingIn || (function() {
'use strict';
var version = 0.1,
schemaVersion = 0.1,
checkInstall = function() {
if( ! _.has(state,'DarknessClosingIn') || state.DarknessClosingIn.version !== schemaVersion) {
log('DarknessClosingIn: Resetting state');
state.DarknessClosingIn = {
version: schemaVersion,
gettingDarker: false
};
}
},
handleInput = function(msg) {
var args;
if (msg.type !== "api" || ! isGM(msg.playerid) ) {
return;
}
args = msg.content.split(/\s+/);
switch(args[0]) {
case '!dci':
state.DarknessClosingIn.gettingDarker = ! state.DarknessClosingIn.gettingDarker;
sendChat('','/w gm ' + (
state.DarknessClosingIn.gettingDarker
? 'Darkness is now closing in.'
: 'Darkness is no longer closing in.'
)
);
break;
}
},
gettingDarker = function(obj, prev) {
if( state.DarknessClosingIn.gettingDarker
&& (
obj.get("left") !== prev.left
|| obj.get("top") !== prev.top
)
&& obj.get('light_radius')
) {
obj.set({
light_radius: Math.floor(obj.get('light_radius') * 0.90)
});
}
},
registerEventHandlers = function() {
on('chat:message', handleInput);
on("change:token", gettingDarker);
};
return {
CheckInstall: checkInstall,
RegisterEventHandlers: registerEventHandlers
};
}());
on('ready',function() {
'use strict';
if("undefined" !== typeof isGM && _.isFunction(isGM)) {
DarknessClosingIn.CheckInstall();
DarknessClosingIn.RegisterEventHandlers();
} else {
log('--------------------------------------------------------------');
log('DarknessClosingIn requires the isGM module to work.');
log('isGM GIST: https://gist.github.com/shdwjk/8d5bb062abab18463625');
log('--------------------------------------------------------------');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment