From de18f8ae68649ee60a922002ddd5688d6f655ebe Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Thu, 26 Mar 2015 15:46:07 -0500 Subject: [PATCH 1/3] Squashed 'Bump/' content from commit fbfa611 git-subtree-dir: Bump git-subtree-split: fbfa6119d1d1c91da8d1bd22214a8af21f1b6b2e --- Bump.js | 433 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 ++ 2 files changed, 450 insertions(+) create mode 100644 Bump.js create mode 100644 package.json diff --git a/Bump.js b/Bump.js new file mode 100644 index 0000000000..8d8c432f30 --- /dev/null +++ b/Bump.js @@ -0,0 +1,433 @@ +// Github: https://github.com/shdwjk/Roll20API/blob/master/Bump/Bump.js +// By: The Aaron, Arcane Scriptomancer +// Contact: https://app.roll20.net/users/104025/the-aaron + +// Insipired by Stephen S. in: https://app.roll20.net/forum/post/1758461/thinking-about-bump-in-script-dot-dot-dot-for-gms/#post-1761852 + +var Bump = Bump || (function() { + 'use strict'; + + var version = 0.1, + schemaVersion = 0.1, + clearURL = 'https://s3.amazonaws.com/files.d20.io/images/4277467/iQYjFOsYC5JsuOPUCI9RGA/thumb.png?1401938659', + + regex = { + colors: /^(transparent|(?:#?[0-9a-fA-F]{6}))$/ + }, + + mirroredProps = [ + 'name', 'left', 'top', 'width', 'height', 'rotation', + 'flipv', 'fliph', 'bar1_value', 'bar1_max', + 'bar2_value', 'bar2_max', 'bar3_value', 'bar3_max', + 'tint_color', 'statusmarkers', 'lastmove', + 'represents','bar1_link','bar2_link','bar3_link' + ], + + checkInstall = function() { + log('-=> Bump v'+version+' <=-'); + + if( ! _.has(state,'Bump') || state.Bump.version !== schemaVersion) { + log(' > Updating Schema to v'+schemaVersion+' <'); + state.Bump = { + version: schemaVersion, + config: { + layerColors: { + 'gmlayer' : '#008000', + 'objects' : '#800080' + }, + autoPush: false + }, + mirrored: {} + }; + } + }, + + ch = function (c) { + var entities = { + '<' : 'lt', + '>' : 'gt', + "'" : '#39', + '@' : '#64', + '{' : '#123', + '|' : '#124', + '}' : '#125', + '[' : '#91', + ']' : '#93', + '"' : 'quot', + '-' : 'mdash', + ' ' : 'nbsp' + }; + + if(_.has(entities,c) ){ + return ('&'+entities[c]+';'); + } + return ''; + }, + + + getMirroredPair = function(id) { + var mirrored; + _.find(state.Bump.mirrored,function(slaveid,masterid){ + if(id === masterid || id === slaveid) { + mirrored = { + master: getObj('graphic',masterid), + slave: getObj('graphic',slaveid) + }; + return true; + } + return false; + }); + return mirrored; + }, + + getMirrored = function(id) { + var mirrored; + _.find(state.Bump.mirrored,function(slaveid,masterid){ + if(id === masterid){ + mirrored = getObj('graphic',slaveid); + return true; + } + if(id === slaveid) { + mirrored = getObj('graphic',masterid); + return true; + } + return false; + }); + return mirrored; + }, + + + createMirrored = function(id, push, who) { + // get root obj + var master = getObj('graphic',id), + slave = getMirrored(id), + baseObj, + layer; + + if(!slave && master) { + layer=((state.Bump.config.autoPush || push || 'gmlayer' === master.get('layer')) ? 'objects' : 'gmlayer'); + if(state.Bump.config.autoPush || push) { + master.set({layer: 'gmlayer'}); + } + baseObj = { + imgsrc: clearURL, + layer: layer, + pageid: master.get('pageid'), + aura1_color: state.Bump.config.layerColors[layer], + aura1_square: true, + aura1_radius: 0.000001 + }; + _.each(mirroredProps,function(p){ + baseObj[p]=master.get(p); + }); + slave = createObj('graphic',baseObj); + state.Bump.mirrored[master.id]=slave.id; + } else { + if(slave) { + sendChat('','/w '+who+' ' + +'
' + +'Error: Slave Token already exists.' + +'
' + ); + } else { + sendChat('','/w '+who+' ' + +'
' + +'Error: Couldn'+ch("'")+'t find a token for id: '+id + +'
' + ); + } + } + }, + + setMasterLayer = function (obj,layer){ + obj.set({ + layer: layer + }); + }, + + setSlaveLayer = function (obj,layer){ + obj.set({ + layer: layer, + aura1_color: state.Bump.config.layerColors[layer] + }); + }, + + bumpToken = function(id) { + var pair=getMirroredPair(id); + if(pair) { + switch(pair.master.get('layer')){ + case 'gmlayer': + setMasterLayer(pair.master,'objects'); + setSlaveLayer(pair.slave,'gmlayer'); + break; + + default: + setMasterLayer(pair.master,'gmlayer'); + setSlaveLayer(pair.slave,'objects'); + break; + } + } + }, + + removeMirrored = function(id) { + var pair=getMirroredPair(id); + if(pair) { + if(id === pair.master.id ) { + pair.slave.remove(); + } + delete state.Bump.mirrored[pair.master.id]; + } + }, + + + handleRemoveToken = function(obj) { + // special handling for deleting slaves? + removeMirrored(obj.id); + }, + + handleTokenChange = function(obj,prev) { + var pair = getMirroredPair(obj.id); + if(pair) { + (pair.master.id === obj.id ? pair.slave : pair.master).set(_.reduce(mirroredProps,function(m,p){ + m[p]=obj.get(p); + return m; + },{})); + if(obj.get('layer') !== prev.layer) { + if(pair.master.id === obj.id) { + setSlaveLayer(pair.slave,prev.layer); + } else { + setMasterLayer(pair.master,prev.layer); + setSlaveLayer(pair.slave,obj.get('layer')); + } + } + } + }, + + getConfigOption_GMLayerColor = function() { + var text = ('transparent' === state.Bump.config.layerColors.gmlayer ? 'transparent' : ' '); + return '
' + +'GM Layer (Visible) Color:' + +'
' + +text + +'
' + +'' + +'Set Color' + +'' + +'
'; + }, + getConfigOption_ObjectsLayerColor = function() { + var text = ('transparent' === state.Bump.config.layerColors.objects ? 'transparent' : ' '); + return '
' + +'Objects Layer (Invisible) Color: ' + +'
' + +text + +'
' + +'' + +'Set Color' + +'' + +'
'; + }, + getConfigOption_AutoPush = function() { + var text = (state.Bump.config.autoPush ? 'On' : 'Off' ); + return '
' + +'Auto Push is currently ' + +text + +' ' + +'' + +'Toggle' + +'' + +'
'; + + }, + + getAllConfigOptions = function() { + return getConfigOption_GMLayerColor() + getConfigOption_ObjectsLayerColor() + getConfigOption_AutoPush(); + }, + + showHelp = function(who) { + + sendChat('','/w '+who+' ' ++'
' + +'
' + +'Bump v'+version + +'
' + +'
' + +'

Bump provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa.

' + +'
' + +'Commands' + +'
' + +'!bump-slave [--push|--help]' + +'
' + +'

Adds an invisible slave token on the other layer.

' + +'
    ' + +'
  • ' + +'--push '+ch('-')+' If the selected token is on the Objects Layer, it will be pushed to the GM Layer.' + +'
  • ' + +'
  • ' + +'--help '+ch('-')+' Shows the Help screen' + +'
  • ' + +'
' + +'
' + +'
' + +'
' + +'!bump [--help]' + +'
' + +'

Swaps the selected Tokens for their counterparts on the other layer.

' + +'
    ' + +'
  • ' + +'--help '+ch('-')+' Shows the Help screen' + +'
  • ' + +'
' + +'
' + +'
' + +'
' + +'!bump-config ['+ch('<')+'Options'+ch('>')+'|--help]' + +'
' + +'

Swaps the selected Tokens for their counterparts on the other layer.

' + +'
    ' + +'
  • ' + +'--help '+ch('-')+' Shows the Help screen' + +'
  • ' + +'
  • ' + +''+ch('<')+'Options'+ch('>')+' '+ch('-')+' Any combination of the below:' + +'
      ' + +'
    • --gm-layer-color|'+ch('<')+'html color|transparent'+ch('>')+' '+ch('-')+' Set the aura color for the slave token when it is on the GM Layer (i.e.: the '+ch('"')+'Visible'+ch('"')+' color.)
    • ' + +'
    • --objects-layer-color|'+ch('<')+'html color|transparent'+ch('>')+' '+ch('-')+' Set the aura color for the slave token when it is on the Objects Layer (i.e.: the '+ch('"')+'Invisible'+ch('"')+' color.)
    • ' + +'
    • --toggle-autopush '+ch('-')+' Sets whether !bump-slave always forces the master token to the GM Layer.
    • ' + +'
    ' + +'
  • ' + +'
' + +'
' + +'
' + +getAllConfigOptions() ++'
' + ); + }, + + handleInput = function(msg) { + var args, who; + + if (msg.type !== "api" || !playerIsGM(msg.playerid)) { + return; + } + who=getObj('player',msg.playerid).get('_displayname').split(' ')[0]; + + args = msg.content.split(/\s+/); + switch(args.shift()) { + case '!bump': + if(!msg.selected || _.contains(args,'--help')) { + showHelp(who); + return; + } + _.each(msg.selected,function(s){ + bumpToken(s._id); + }); + break; + + case '!bump-slave': + if(!msg.selected || _.contains(args,'--help')) { + showHelp(who); + return; + } + _.each(msg.selected,function(s){ + createMirrored(s._id,_.contains(args,'--push'), who); + }); + break; + + case '!bump-config': + if(_.contains(args,'--help')) { + showHelp(who); + return; + } + if(!args.length) { + sendChat('','/w '+who+' ' ++'
' + +'
' + +'Bump v'+version + +'
' + +getAllConfigOptions() ++'
' + ); + return; + } + _.each(args,function(a){ + var opt=a.split(/\|/), + msg=''; + switch(opt.shift()) { + case '--gm-layer-color': + if(opt[0].match(regex.colors)) { + state.Bump.config.layerColors.gmlayer=opt[0]; + } else { + msg='
Error: Not a valid color: '+opt[0]+'
'; + } + sendChat('','/w '+who+' ' + +'
' + +msg + +getConfigOption_GMLayerColor() + +'
' + ); + break; + + case '--objects-layer-color': + if(opt[0].match(regex.colors)) { + state.Bump.config.layerColors.objects=opt[0]; + } else { + msg='
Error: Not a valid color: '+opt[0]+'
'; + } + sendChat('','/w '+who+' ' + +'
' + +msg + +getConfigOption_ObjectsLayerColor() + +'
' + ); + break; + + case '--toggle-auto-push': + state.Bump.config.autoPush=!state.Bump.config.autoPush; + sendChat('','/w '+who+' ' + +'
' + +getConfigOption_AutoPush() + +'
' + ); + break; + default: + sendChat('','/w '+who+' ' + +'
Unsupported Option:
'+a+'' + ); + } + + }); + + break; + } + }, + + registerEventHandlers = function() { + on('chat:message', handleInput); + on('change:graphic', handleTokenChange); + on('destroy:graphic', handleRemoveToken); + }; + + return { + CheckInstall: checkInstall, + RegisterEventHandlers: registerEventHandlers + }; + +}()); + +on('ready',function() { + 'use strict'; + + Bump.CheckInstall(); + Bump.RegisterEventHandlers(); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000000..300239e4d6 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "Bump", + "version": "0.1", + "description": "Bump provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa.", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": { + }, + "modifies": { + "state.Bump": "read,write", + "graphics": "create,remove", + "graphics.*": "read,write", + "player.displayname": "read" + }, + "conflicts": [ + ] +} From 05bb051ac2ca3c278d17b44eddf7dc43b033094c Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Thu, 26 Mar 2015 16:05:51 -0500 Subject: [PATCH 2/3] Squashed 'Bump/' changes from fbfa611..a2f2cad a2f2cad prod-Bump: Updated prod version of Bump at version 0.2. git-subtree-dir: Bump git-subtree-split: a2f2cadd50dee0f493b01876dba207f4c4771252 --- Bump.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Bump.js b/Bump.js index 8d8c432f30..669c0d03bb 100644 --- a/Bump.js +++ b/Bump.js @@ -7,7 +7,7 @@ var Bump = Bump || (function() { 'use strict'; - var version = 0.1, + var version = 0.2, schemaVersion = 0.1, clearURL = 'https://s3.amazonaws.com/files.d20.io/images/4277467/iQYjFOsYC5JsuOPUCI9RGA/thumb.png?1401938659', @@ -19,7 +19,7 @@ var Bump = Bump || (function() { 'name', 'left', 'top', 'width', 'height', 'rotation', 'flipv', 'fliph', 'bar1_value', 'bar1_max', 'bar2_value', 'bar2_max', 'bar3_value', 'bar3_max', - 'tint_color', 'statusmarkers', 'lastmove', + 'tint_color', 'lastmove', 'represents','bar1_link','bar2_link','bar3_link' ], diff --git a/package.json b/package.json index 300239e4d6..be3cb029d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Bump", - "version": "0.1", + "version": "0.2", "description": "Bump provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa.", "authors": "The Aaron", "roll20userid": "104025", From 64b586f2aa79283f48ba4b16ae79b6bb9905815b Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sun, 29 Mar 2015 18:13:16 -0500 Subject: [PATCH 3/3] Squashed 'Bump/' changes from a2f2cad..a2d1044 a2d1044 prod-Bump: Updated prod version of Bump at version 0.2.1. git-subtree-dir: Bump git-subtree-split: a2d104497fb5749b83717c120676f22bd519e9f0 --- Bump.js | 73 +++++++++++++++++++++++++++++++++++++++------------- package.json | 28 ++++++++++---------- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/Bump.js b/Bump.js index 669c0d03bb..e424b36004 100644 --- a/Bump.js +++ b/Bump.js @@ -7,8 +7,9 @@ var Bump = Bump || (function() { 'use strict'; - var version = 0.2, - schemaVersion = 0.1, + var version = '0.2.1', + lastUpdate = 1427670567, + schemaVersion = 0.2, clearURL = 'https://s3.amazonaws.com/files.d20.io/images/4277467/iQYjFOsYC5JsuOPUCI9RGA/thumb.png?1401938659', regex = { @@ -24,21 +25,31 @@ var Bump = Bump || (function() { ], checkInstall = function() { - log('-=> Bump v'+version+' <=-'); + log('-=> Bump v'+version+' <=- ['+(new Date(lastUpdate*1000))+']'); if( ! _.has(state,'Bump') || state.Bump.version !== schemaVersion) { log(' > Updating Schema to v'+schemaVersion+' <'); - state.Bump = { - version: schemaVersion, - config: { - layerColors: { - 'gmlayer' : '#008000', - 'objects' : '#800080' - }, - autoPush: false - }, - mirrored: {} - }; + switch(state.Bump && state.Bump.version) { + case 0.1: + state.Bump.config.autoSlave = false; + state.Bump.version = schemaVersion; + break; + + default: + state.Bump = { + version: schemaVersion, + config: { + layerColors: { + 'gmlayer' : '#008000', + 'objects' : '#800080' + }, + autoPush: false, + autoSlave: false + }, + mirrored: {} + }; + break; + } } }, @@ -152,7 +163,7 @@ var Bump = Bump || (function() { }); }, - bumpToken = function(id) { + bumpToken = function(id,who) { var pair=getMirroredPair(id); if(pair) { switch(pair.master.get('layer')){ @@ -166,6 +177,8 @@ var Bump = Bump || (function() { setSlaveLayer(pair.slave,'objects'); break; } + } else if(state.Bump.config.autoSlave) { + createMirrored(id, false, who); } }, @@ -250,8 +263,21 @@ var Bump = Bump || (function() { }, + getConfigOption_AutoSlave = function() { + var text = (state.Bump.config.autoSlave ? 'On' : 'Off' ); + return '
' + +'Auto Slave is currently ' + +text + +' ' + +'' + +'Toggle' + +'' + +'
'; + + }, + getAllConfigOptions = function() { - return getConfigOption_GMLayerColor() + getConfigOption_ObjectsLayerColor() + getConfigOption_AutoPush(); + return getConfigOption_GMLayerColor() + getConfigOption_ObjectsLayerColor() + getConfigOption_AutoPush() + getConfigOption_AutoSlave(); }, showHelp = function(who) { @@ -303,7 +329,8 @@ var Bump = Bump || (function() { +'
    ' +'
  • --gm-layer-color|'+ch('<')+'html color|transparent'+ch('>')+' '+ch('-')+' Set the aura color for the slave token when it is on the GM Layer (i.e.: the '+ch('"')+'Visible'+ch('"')+' color.)
  • ' +'
  • --objects-layer-color|'+ch('<')+'html color|transparent'+ch('>')+' '+ch('-')+' Set the aura color for the slave token when it is on the Objects Layer (i.e.: the '+ch('"')+'Invisible'+ch('"')+' color.)
  • ' - +'
  • --toggle-autopush '+ch('-')+' Sets whether !bump-slave always forces the master token to the GM Layer.
  • ' + +'
  • --toggle-auto-push '+ch('-')+' Sets whether !bump-slave always forces the master token to the GM Layer.
  • ' + +'
  • --toggle-auto-slave '+ch('-')+' Sets whether !bump automatically creates a slave for tokens without them.
  • ' +'
' +' ' +'' @@ -330,7 +357,7 @@ var Bump = Bump || (function() { return; } _.each(msg.selected,function(s){ - bumpToken(s._id); + bumpToken(s._id,who); }); break; @@ -400,6 +427,16 @@ var Bump = Bump || (function() { +'' ); break; + + case '--toggle-auto-slave': + state.Bump.config.autoSlave=!state.Bump.config.autoSlave; + sendChat('','/w '+who+' ' + +'
' + +getConfigOption_AutoSlave() + +'
' + ); + break; + default: sendChat('','/w '+who+' ' +'
Unsupported Option:
'+a+'' diff --git a/package.json b/package.json index be3cb029d6..5b6819996f 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,15 @@ { - "name": "Bump", - "version": "0.2", - "description": "Bump provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa.", - "authors": "The Aaron", - "roll20userid": "104025", - "dependencies": { - }, - "modifies": { - "state.Bump": "read,write", - "graphics": "create,remove", - "graphics.*": "read,write", - "player.displayname": "read" - }, - "conflicts": [ - ] + "name": "Bump", + "version": "0.2.1", + "description": "Bump provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa.", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": [], + "modifies": { + "state.Bump": "read,write", + "graphics": "create,remove", + "graphics.*": "read,write", + "player.displayname": "read" + }, + "conflicts": [] }