Created
November 4, 2017 13:45
-
-
Save Bastlifa/8adfd09b7665ea77070bce260e80f3bc to your computer and use it in GitHub Desktop.
Change ten foot squares maps in roll20 to 5 foot squares maps (path functions provided by Aaron)
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
on("ready", function() { | |
var graphics; | |
var paths; | |
const scalePathString = function(pathstring,scale){ | |
return JSON.stringify(_.map(JSON.parse(pathstring),(n)=> _.map(n,(i)=> _.isNumber(i) ? scale*i : i ))); | |
}; | |
const simpleObject = function(o){ | |
return JSON.parse(JSON.stringify(o)); | |
}; | |
const scaleDrawing = function(scale){ | |
return function(drawing){ | |
let newpath=_.omit(simpleObject(drawing),['_id','_type']); | |
if(_.contains(['','[]'],newpath._path)){ | |
return; | |
} | |
newpath.path=scalePathString(newpath._path,scale); | |
delete newpath._path; | |
newpath.top*=scale; | |
newpath.left*=scale; | |
newpath.width*=scale; | |
newpath.height*=scale; | |
let newPathObj = createObj('path',newpath); | |
drawing.remove(); | |
}; | |
}; | |
on("chat:message", function (msg) { | |
if (msg.type === "api" && msg.content === "!10To5" && playerIsGM(msg.playerid)) | |
{ | |
var page = getObj('page', getObj('player',msg.playerid).get('lastpage')); | |
page.set('width', page.get('width')*2); | |
page.set('height', page.get('height')*2); | |
page.set("scale_number", 5); | |
page.set("snapping_increment", 1); | |
graphics = findObjs({_type: 'graphic', _pageid: getObj('player',msg.playerid).get('lastpage')}); | |
paths = findObjs({_type: 'path', _pageid: getObj('player',msg.playerid).get('lastpage')}); | |
if (graphics) | |
{ | |
for(var i=0; i<graphics.length; i++) | |
{ | |
graphics[i].set('top', graphics[i].get('top')*2); | |
graphics[i].set('left', graphics[i].get('left')*2); | |
graphics[i].set('width', graphics[i].get('width')*2); | |
graphics[i].set('height', graphics[i].get('height')*2); | |
} | |
} | |
if (paths) | |
{ | |
_.each(paths,scaleDrawing(2)); | |
} | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment