From dfb571ea0d9baa6ef33a696ada26c6d67ebe0e9b Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 14 Feb 2015 09:45:58 -0600 Subject: [PATCH 1/2] Squashed 'Tile/' content from commit c3fad1f git-subtree-dir: Tile git-subtree-split: c3fad1f932b9135ed82665ac4cac5b7d057a5e4b --- Tile.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 22 +++++++++++ 2 files changed, 129 insertions(+) create mode 100644 Tile.js create mode 100644 package.json diff --git a/Tile.js b/Tile.js new file mode 100644 index 0000000000..5634c417a2 --- /dev/null +++ b/Tile.js @@ -0,0 +1,107 @@ +// Github: https://github.com/shdwjk/Roll20API/blob/master/Tile/Tile.js +// By: The Aaron, Arcane Scriptomancer +// Contact: https://app.roll20.net/users/104025/the-aaron + +var Tile = Tile || (function() { + 'use strict'; + + var version = 0.1, + tileNextMove = false, + + getCleanImgsrc = function (imgsrc) { + var parts = imgsrc.match(/(.*\/images\/.*)(thumb|max)(.*)$/); + if(parts) { + return parts[1]+'thumb'+parts[3]; + } + return; + }, + + handleInput = function(msg) { + var args; + + if (msg.type !== "api" || !isGM(msg.playerid)) { + return; + } + + args = msg.content.split(/\s+/); + switch(args[0]) { + case '!tile-next-move': + tileNextMove=true; + sendChat('Tile', '/w gm Tiling next move on the map layer.'); + break; + } + }, + + handleMove = function(obj, prev) { + var img, + ax,ay, + sx,sy, + cx,cy, + ix,iy, + t + ; + + if( tileNextMove + && 'map' === obj.get('layer') + && ( obj.get('left') !== prev.left || obj.get('top') !== prev.top) + ) { + img = getCleanImgsrc(obj.get('imgsrc')); + if(img) { + ax = prev.left; + ay = prev.top; + sx = obj.get('width') * (prev.left < obj.get('left') ? 1 : -1 ); + sy = obj.get('height') * (prev.top < obj.get('top') ? 1 : -1 ); + cx = Math.round(Math.abs((obj.get('left')-prev.left)/sx)); + cy = Math.round(Math.abs((obj.get('top')-prev.top)/sx)); + t = { + imgsrc: img, + pageid: obj.get('pageid'), + layer: 'map', + width: prev.width, + height: prev.height + }; + for(ix=0;ix<=cx;++ix) { + for(iy=0;iy<=cy;++iy) { + t.left = (ax + (sx * ix) ); + t.top = (ay + (sy * iy) ); + if(ix === cx && iy === cy ) { + obj.set({ + left: t.left, + top: t.top + }); + } else { + createObj('graphic',t); + } + } + } + + } else { + sendChat('Tile','/w gm Can only tile with images in a User Library.'); + } + tileNextMove = false; + } + }, + + registerEventHandlers = function() { + on('change:graphic', handleMove); + on('chat:message', handleInput); + }; + + return { + RegisterEventHandlers: registerEventHandlers + }; + +}()); + +on('ready',function() { + 'use strict'; + + if("undefined" !== typeof isGM && _.isFunction(isGM)) { + Tile.RegisterEventHandlers(); + } else { + log('--------------------------------------------------------------'); + log('Tile requires the isGM module to work.'); + log('isGM GIST: https://gist.github.com/shdwjk/8d5bb062abab18463625'); + log('--------------------------------------------------------------'); + } +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000000..426d490143 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "Tile", + "version": "0.1", + "description": "Create tiled arrays of grpahics on the map layer.", + "authors": "The Aaron", + "roll20userid": "104025", + "dependencies": { + "isGMModule": "0.x" + }, + "modifies": { + "graphic": "create", + "graphic.height": "read", + "graphic.imgsrc": "read", + "graphic.layer": "read", + "graphic.left": "read,write", + "graphic.pageid": "read", + "graphic.top": "read,write", + "graphic.width": "read" + }, + "conflicts": [ + ] +} From 680a505cbcd59d7c7027d998ab385d7d6e449866 Mon Sep 17 00:00:00 2001 From: "Aaron C. Meadows" Date: Sat, 14 Feb 2015 10:09:41 -0600 Subject: [PATCH 2/2] Squashed 'Tile/' changes from c3fad1f..3405871 3405871 prod-Tile: Updated prod version of Tile at version 0.2. git-subtree-dir: Tile git-subtree-split: 3405871fe97580ac96a39a40cee2d7db74a7b73a --- Tile.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tile.js b/Tile.js index 5634c417a2..dadf4ec5d7 100644 --- a/Tile.js +++ b/Tile.js @@ -5,7 +5,7 @@ var Tile = Tile || (function() { 'use strict'; - var version = 0.1, + var version = 0.2, tileNextMove = false, getCleanImgsrc = function (imgsrc) { @@ -52,7 +52,7 @@ var Tile = Tile || (function() { sx = obj.get('width') * (prev.left < obj.get('left') ? 1 : -1 ); sy = obj.get('height') * (prev.top < obj.get('top') ? 1 : -1 ); cx = Math.round(Math.abs((obj.get('left')-prev.left)/sx)); - cy = Math.round(Math.abs((obj.get('top')-prev.top)/sx)); + cy = Math.round(Math.abs((obj.get('top')-prev.top)/sy)); t = { imgsrc: img, pageid: obj.get('pageid'), diff --git a/package.json b/package.json index 426d490143..4018f77640 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Tile", - "version": "0.1", + "version": "0.2", "description": "Create tiled arrays of grpahics on the map layer.", "authors": "The Aaron", "roll20userid": "104025",