Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Copy polygon/line to dynamic lighting layer or vice verser?

What i've started doing for quick and easy caves/dungeons/rooms is draw out the walls using grey extra large polygon/line then make a copy and move it to the DL layer, change it's colour to my preferred DL colour and it's thickness to regular. This means that my players see a nice even grey boundary to the walls without me having to fuss with it too much. Can anyone suggest a way I can automate this with the help of an already existing API? Basically what i'd like is to be able to draw the wall on the background or DL layer then select it and activate a macro that copies it to the other layer and makes the changes to it's colour and thickness. I know token mod can manage the changes and the layer switch but where i get stuck is the copying and the placement on the new layer to line up perfectly with the other layer. Any suggestions or thoughts would be much appreciated, I have no experience in making my own APIs unfortunately.
1591364058

Edited 1591366316
The Aaron
Roll20 Production Team
API Scripter
TokenMod only works on Graphic objects, not drawings.  There isn't a script that does what you want that I'm aware of... ... so I wrote one! Select one or more drawings and run one of: !to-map !to-dl To copy to the respective layers with adjustments.  You can edit color and stroke width in the script.j  14 is the largest size selectable through the UI for line width, but as you can see below, you can make that larger. Script: on('ready',()=>{ const DLProps = { stroke: "#ff00ff", stroke_width: 5, layer: "walls" }; const MapProps = { stroke: "#999999", stroke_width: 25, layer: "map" }; const SimpleObj = (o) => JSON.parse(JSON.stringify(o)); const DupPathWithOpts = (p,o)=>{ let base = SimpleObj(p); base.path = base._path; base.pageid = base._pageid; delete base._id; delete base._type; delete base._pageid; delete base._path; let np = createObj('path',Object.assign({},base,o)); toFront(np); }; on('chat:message',msg=>{ if('api'===msg.type && /^!to-(dl|map)(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let args = msg.content.split(/\s+/); let paths = (msg.selected || []) .map(o=>getObj('path',o._id)) .filter(g=>undefined !== g) ; let opts; switch(args[0].toLowerCase()){ case '!to-dl': opts = DLProps; break; case '!to-map': opts = MapProps; break; } paths.forEach(p=>DupPathWithOpts(p,opts)); } }); }); Edit: Added GM only
1591364258
The Aaron
Roll20 Production Team
API Scripter
One caveat, this will happily copy any path to the DL layer, even freehand and circle paths.  Just be sure to DL responsibly! =D
Literally beat me by a minute... Although, to be fair, my path copy code is mangled from code that The Aaron gave me a couple of years ago (also, no need to select for this one, just works on the page you're on). Warning, didn't test much! on ( "ready" ,  function () {      // change constants to desired lighting and map color/width           const   dllPathColor  =  "#ffff00"      const   mapPathColor  =  "#666666"      const   dllPathWidth  =  5      const   mapPathWidth  =  10      const   simpleObject  =  function ( o ){          return   JSON . parse ( JSON . stringify ( o ))     }      const    pathCopier  =  function ( drawing ,  layer ){              let   newpath = _ . omit ( simpleObject ( drawing ),[ '_id' , '_type' ])              if ( _ . contains ([ '' , '[]' ], newpath . _path )){                  return             }              newpath . path  =  JSON . stringify ( newpath . _path )              newpath . stroke  =  layer  ===  "lighting"  ?  dllPathColor  :  mapPathColor              newpath . layer  =  layer  ===  "lighting"  ?  "walls"  :  "map"              newpath . stroke_width  =  layer  ===  "lighting"  ?  dllPathWidth  :  mapPathWidth              let   newPathObj  =  createObj ( 'path' , newpath )     }      on ( "chat:message" ,  function  ( msg ) {          if  ( msg . type  ===  "api"  &&  msg . content  ===  "!ToLightingPathCopy"  &&  playerIsGM ( msg . playerid ))         {              var   page  =  getObj ( 'page' ,  getObj ( 'player' , msg . playerid ). get ( 'lastpage' ))              paths  =  findObjs ({ _type :   'path' ,  _pageid :   getObj ( 'player' , msg . playerid ). get ( 'lastpage' ),  layer :   'map' })              if  ( paths )             {                  for ( var   i = 0 ;  i < paths . length ;  i ++)                 {                      pathCopier ( paths [ i ],  'lighting' )                 }             }         }          if  ( msg . type  ===  "api"  &&  msg . content  ===  "!ToMapPathCopy"  &&  playerIsGM ( msg . playerid ))         {              var   page  =  getObj ( 'page' ,  getObj ( 'player' , msg . playerid ). get ( 'lastpage' ))              paths  =  findObjs ({ _type :   'path' ,  _pageid :   getObj ( 'player' , msg . playerid ). get ( 'lastpage' ),  layer :   'walls' })              if  ( paths )             {                  for ( var   i = 0 ;  i < paths . length ;  i ++)                 {                      pathCopier ( paths [ i ],  'map' )                 }             }         }     }); });
1591364659
The Aaron
Roll20 Production Team
API Scripter
Bast L.  said: Literally beat me by a minute... Although, to be fair, my path copy code is mangled from code that The Aaron gave me a couple of years ago (also, no need to select for this one, just works on the page you're on).  Warning, didn't test much! Woot!  Fun to see how different and similar code that approaches the same problem is. =D 
The Aaron said: Bast L.  said: Literally beat me by a minute... Although, to be fair, my path copy code is mangled from code that The Aaron gave me a couple of years ago (also, no need to select for this one, just works on the page you're on).  Warning, didn't test much! Woot!  Fun to see how different and similar code that approaches the same problem is. =D  I should've split the args, just lazy :) alt+shift+down toFront as well, is good (I was thrown for a while, because the lines were disappearing on a page with a map, they were just hidden behind it). Selection is probably safer than just grabbing any path, but I've had weird issues with drag-selecting paths before, not quite sure what the issues were though.
1591366267
The Aaron
Roll20 Production Team
API Scripter
Yeah, I wrote the script in about 5 minutes (I have lots of micro parts I can pull in to build little snippets quickly), but then spent quite a while figuring out why copying to the map didn't do anything. =D  I should probably make the script only work for GMs... I'd thought about trying to sync all the paths on the walls layer and the map layer, but that seemed like it could create some problems. =D
This is a very cool idea. I might have to give this approach a try. I've recently been exploring ways to do more with drawn objects using the API.
you guys are total legends