Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Random Turnorder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Random Turnorder

Call `!shuffleturnorder` to shuffle the items in the turnorder window randomly. If any tokens _not_ in the turn order are selected at the time, they will be added prior to the shuffling.
85 changes: 85 additions & 0 deletions Random Turnorder/Random Turnorder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* The `!shuffleturnorder' command will add all selected tokens to the turnorder
* window (if not already present), and then shuffle all items in the turn order.
*/
var bshields = bshields || {};
bshields.shuffleturnorder = (function() {
'use strict';

var version = 1.0,
commands = {
shuffleturnorder: function(args, msg) {
var selected = msg.selected,
turnorder = [],
turnorderTokenids = [];

if (Campaign().get('turnorder')) {
turnorder = JSON.parse(Campaign().get('turnorder'));
turnorderTokenids = _.pluck(turnorder, 'id');
}

if (selected) {
_.each(selected, function(token) {
if (!_.contains(turnorderTokenids, token._id)) {
// Selected token is not in turn order
turnorder.push({
id: token._id,
pr: '0',
custom: ''
});
}
});
}

turnorder = _.shuffle(turnorder);
Campaign().set('turnorder', JSON.stringify(turnorder));
},
help: function(command, args, msg) {
if (_.isFunction(commands['help_' + command])) {
commands['help_' + command](args, msg);
}
}
};

function handleInput(msg) {
var isApi = msg.type === 'api',
args = msg.content.trim().splitArgs(),
command, arg0, isHelp;

if (!isGM(msg.playerid)) { return; }

if (isApi) {
command = args.shift().substring(1).toLowerCase();
arg0 = args.shift() || '';
isHelp = arg0.toLowerCase() === 'help' || arg0.toLowerCase() === 'h';

if (!isHelp) {
if (arg0) {
args.unshift(arg0);
}

if (_.isFunction(commands[command])) {
commands[command](args, msg);
}
} else if (_.isFunction(commands.help)) {
commands.help(command, args, msg);
}
} else if (_.isFunction(commands['msg_' + msg.type])) {
commands['msg_' + msg.type](args, msg);
}
}

function registerEventHandlers() {
on('chat:message', handleInput);
}

return {
registerEventHandlers: registerEventHandlers
};
}());

on('ready', function() {
'use strict';

bshields.shuffleturnorder.registerEventHandlers();
});
18 changes: 18 additions & 0 deletions Random Turnorder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Shuffle Turnorder",
"version": "1.0",
"description": "Shuffles items in the turnorder window, and adds any selected tokens if they are not already present.",
"authors": "Brian Shields",
"roll20userid": "235259",
"dependencies": {
"IsGMModule": "0.7",
"splitArgs": "1.0"
},
"modifies": {
"turnorder": "write",
"token": "read"
},
"conflicts": [
"none"
]
}