Created
January 9, 2015 20:44
-
-
Save shdwjk/0a14b06ef4da1cb5e33f to your computer and use it in GitHub Desktop.
Roll20 API: Random Depth -- Randomly adjusts the depth of selected tokens.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GIST: https://gist.github.com/shdwjk/0a14b06ef4da1cb5e33f | |
var RandomDepth = RandomDepth || (function() { | |
'use strict'; | |
var version = 0.2, | |
randomToFrontList = function (l) { | |
if( l.length ) { | |
var i = randomInteger(l.length)-1; | |
toFront(l[i]); | |
if( l.length > 1) { | |
setTimeout(_.partial(randomToFrontList,_.without(l,l[i])),5); | |
} | |
} | |
}, | |
handleMessages = function(msg) | |
{ | |
if('api' !== msg.type ) { | |
return; | |
} | |
var args = msg.content.split(/\s+/), | |
objs; | |
switch(args.shift()) | |
{ | |
case '!random-depth': | |
objs = _.chain(msg.selected) | |
.map(function(o){ | |
return getObj(o._type,o._id); | |
}) | |
.reject(_.isUndefined) | |
.value(); | |
randomToFrontList(objs); | |
break; | |
} | |
}, | |
registerEventHandlers = function(){ | |
on('chat:message',handleMessages); | |
}; | |
return { | |
RegisterEventHandlers: registerEventHandlers | |
}; | |
}()); | |
on('ready',function(){ | |
'use strict'; | |
RandomDepth.RegisterEventHandlers(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment