From a1602a0e5cf042d0a97303013a01981936e0fa1d Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sun, 3 May 2015 14:47:33 -0500 Subject: [PATCH 1/2] Squashed 'GroupInitiative/' changes from 5a86dc9..f6d655c f6d655c prod-GroupInitiative: Updated prod version of GroupInitiative at version 0.8.1. git-subtree-dir: GroupInitiative git-subtree-split: f6d655cee2cfe5bbb7b9e1c7ad709486e795da68 --- GroupInitiative.js | 99 +++++++++++++++++++++++++++++----------------- package.json | 27 ++++++------- 2 files changed, 75 insertions(+), 51 deletions(-) diff --git a/GroupInitiative.js b/GroupInitiative.js index d66ac0c2d4..1127040589 100644 --- a/GroupInitiative.js +++ b/GroupInitiative.js @@ -5,7 +5,8 @@ var GroupInitiative = GroupInitiative || (function() { 'use strict'; - var version = 0.6, + var version = '0.8.1', + lastUpdate = 1430682355, schemaVersion = 0.6, bonusCache = {}, statAdjustments = { @@ -68,9 +69,9 @@ var GroupInitiative = GroupInitiative || (function() { .map(function(d){ return randomInteger(20)+d; },{}) - .reduce(function(r,memo){ + .reduce(function(memo,r){ return memo+r; - },0) + },[0]) .map(function(v){ return Math.floor(v/l.length); }) @@ -98,24 +99,28 @@ var GroupInitiative = GroupInitiative || (function() { }, checkInstall = function() { + log('-=> GroupInitiative v'+version+' <=- ['+(new Date(lastUpdate*1000))+']'); + if( ! _.has(state,'GroupInitiative') || state.GroupInitiative.version !== schemaVersion) { - if( state && state.GroupInitiative && state.GroupInitiative.version && 0.5 === state.GroupInitiative.version ) { - log('GroupInitiative: Updating state schema to version '+schemaVersion); - state.GroupInitiative.version = schemaVersion; - state.GroupInitiative.replaceRoll = false; - } else { - state.GroupInitiative = { - version: schemaVersion, - bonusStatGroups: [ - [ - { - attribute: 'dexterity' - } - ] - ], - rollType: 'Individual-Roll', - replaceRoll: false - }; + log(' > Updating Schema to v'+schemaVersion+' <'); + switch(state.GroupInitiative && state.GroupInitiative.version) { + case 0.5: + state.GroupInitiative.version = schemaVersion; + state.GroupInitiative.replaceRoll = false; + break; + default: + state.GroupInitiative = { + version: schemaVersion, + bonusStatGroups: [ + [ + { + attribute: 'dexterity' + } + ] + ], + rollType: 'Individual-Roll', + replaceRoll: false + }; } } }, @@ -341,27 +346,40 @@ var GroupInitiative = GroupInitiative || (function() { return bonus; }, - HandleInput = function(msg) { - var args, + HandleInput = function(msg_orig) { + var msg = _.clone(msg_orig), + args, cmds, workgroup, workvar, turnorder, rolls, error=false, - initFunc; + initFunc, + cont=false, + manualBonus=0; - if (msg.type !== "api" || !isGM(msg.playerid) ) { + if (msg.type !== "api" || !playerIsGM(msg.playerid) ) { return; } + if(_.has(msg,'inlinerolls')){ + msg.content = _.chain(msg.inlinerolls) + .reduce(function(m,v,k){ + m['$[['+k+']]']=v.results.total || 0; + return m; + },{}) + .reduce(function(m,v,k){ + return m.replace(k,v); + },msg.content) + .value(); + } + args = msg.content.split(/\s+--/); switch(args.shift()) { case '!group-init': if(args.length > 0) { cmds=args.shift().split(/\s+/); - toString(args); - toString(cmds); switch(cmds[0]) { case 'help': @@ -511,11 +529,23 @@ var GroupInitiative = GroupInitiative || (function() { state.GroupInitiative.replaceRoll = !state.GroupInitiative.replaceRoll; sendChat('GroupInitiative', '/w gm ' +'
' - +'Replace Initiative on Roll is now: '+ (state.GroupInitiative.replaceRoll ? 'ON' : 'OFF') +'' + +'Replace Initiative on Roll is now: '+ (state.GroupInitiative.replaceRoll ? 'ON' : 'OFF') +'' +'
' ); break; + case 'bonus': + if(cmds[1].match(/^[\-\+]?\d+$/)){ + manualBonus=parseInt(cmds[1],10); + cont=true; + } else { + sendChat('GroupInitiative', '/w gm ' + +'
' + +'Not a valid bonus: '+cmds[1]+'' + +'
' + ); + } + break; default: sendChat('GroupInitiative', '/w gm ' @@ -526,6 +556,10 @@ var GroupInitiative = GroupInitiative || (function() { break; } } else { + cont=true; + } + + if(cont) { if(_.has(msg,'selected')) { bonusCache = {}; turnorder = Campaign().get('turnorder'); @@ -556,10 +590,10 @@ var GroupInitiative = GroupInitiative || (function() { }; }) .map(function(s){ - s.bonus=s.character ? findInitiativeBonus(s.character.id) || 0 : 0; + s.bonus=(s.character ? findInitiativeBonus(s.character.id) || 0 : 0)+manualBonus; return s; }) - .map(initFunc,{}) + .map(initFunc) .map(function(s){ return { id: s.token.id, @@ -595,13 +629,6 @@ var GroupInitiative = GroupInitiative || (function() { on("ready",function(){ 'use strict'; - if("undefined" !== typeof isGM && _.isFunction(isGM)) { GroupInitiative.CheckInstall(); GroupInitiative.RegisterEventHandlers(); - } else { - log('--------------------------------------------------------------'); - log('GroupInitiative requires the isGM module to work.'); - log('isGM GIST: https://gist.github.com/shdwjk/8d5bb062abab18463625'); - log('--------------------------------------------------------------'); - } }); diff --git a/package.json b/package.json index 59ef624866..5840778c16 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,14 @@ { - "name": "GroupInitiative", - "version": "0.6", - "description": "Adds the selected tokens to the turn order after rolling their initiative + configurable data.", - "authors": "The Aaron", - "roll20userid": "104025", - "dependencies": { - "isGMModule": "0.x" - }, - "modifies": { - "state.GroupInitiative": "read,write", - "campaign.turnorder": "read,write", - "graphic.represents": "read" - }, - "conflicts": [ - ] + "name": "GroupInitiative", + "version": "0.8.1", + "description": "Adds the selected tokens to the turn order after rolling their initiative + configurable data.", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": [], + "modifies": { + "state.GroupInitiative": "read,write", + "campaign.turnorder": "read,write", + "graphic.represents": "read" + }, + "conflicts": [] } From 27d99f5743fa9cc619fac899953b371d2763611d Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sun, 3 May 2015 18:36:37 -0500 Subject: [PATCH 2/2] Squashed 'GroupInitiative/' changes from f6d655c..e25afc2 e25afc2 prod-GroupInitiative: Updated prod version of GroupInitiative at version 0.8.2. git-subtree-dir: GroupInitiative git-subtree-split: e25afc23ca293ef039fdb674b2fdfe96fcc2d633 --- GroupInitiative.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GroupInitiative.js b/GroupInitiative.js index 1127040589..4b49c969cc 100644 --- a/GroupInitiative.js +++ b/GroupInitiative.js @@ -5,8 +5,8 @@ var GroupInitiative = GroupInitiative || (function() { 'use strict'; - var version = '0.8.1', - lastUpdate = 1430682355, + var version = '0.8.2', + lastUpdate = 1430695680, schemaVersion = 0.6, bonusCache = {}, statAdjustments = { @@ -536,7 +536,7 @@ var GroupInitiative = GroupInitiative || (function() { case 'bonus': if(cmds[1].match(/^[\-\+]?\d+$/)){ - manualBonus=parseInt(cmds[1],10); + manualBonus=parseFloat(cmds[1]); cont=true; } else { sendChat('GroupInitiative', '/w gm ' diff --git a/package.json b/package.json index 5840778c16..5b8732762e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "GroupInitiative", - "version": "0.8.1", + "version": "0.8.2", "description": "Adds the selected tokens to the turn order after rolling their initiative + configurable data.", "authors": "The Aaron", "roll20userid": "104025",