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

[Scriptlet] LDLOpenPolygon - Fixes the new LDL bug causing phantom DL lines for closed polygons

1651028641

Edited 1651028935
David M.
Pro
API Scripter
Hey there, fellow LDL holdouts! Some of you may have noticed that some of your maps with dynamic lighting are now producing "phantom" LoS blocking lines stretching to the upper left of your maps. This is related to a recent update that has broken LDL when "closed" polygons (startPt = endPt) are used. Since LDL is no longer supported and a fix is surely never coming, this little scriptlet converts your "closed" polygon into an "open" one which will not produce the phantom lines. For you folks knowledgeable with SVG paths, the script merely removes the last array element containing ["Z"] which denotes it as a closed polygon. To use, select the offending polygon path and run the following macro: !openpolygon Example gif (click to play). The rectangle on the DL layer is producing the phantom line prior to running the script but is functioning as expected afterward.   Here's the code: const LDLOpenPolygon = (() => { async function handleInput(msg) { if (msg.type=="api" && msg.content.toLowerCase().indexOf("!openpolygon")==0) { try { let selected = msg.selected.filter(e => e._type==='path'); if (selected) { let pathObj = getObj('path', selected[0]._id); let pathArr = JSON.parse(pathObj.get("path")); let closedPoly = pathArr.find(e => e[0] === 'Z') ? true : false; if (closedPoly) { let openPath = pathArr.filter(e => e[0] !== 'Z'); let pathObjCopy = JSON.parse(JSON.stringify(pathObj)); pathObjCopy._path = JSON.stringify(openPath); let newPathObj = await createObj('path',pathObjCopy); if (newPathObj) { pathObj.remove(); } else { sendChat('',`/w gm Unexpected error. The selected path was unaffected.`); } } } } catch(err) { sendChat('',`/w gm `+ 'Error: ' + err.message); } }; }; const registerEventHandlers = () => { on('chat:message', handleInput); }; on('ready', () => { registerEventHandlers(); }); })(); If you are feeling frisky you could modify this to affect all paths on a given page or across your campaign, but there's no way I'm going to be held responsible for that if anything goes wrong! ;)  
1651028885
David M.
Pro
API Scripter
Note: I'm working on a simple (DL agnostic) path editing script currently. This will likely get rolled up into that when I'm done, but wanted to share this part now in case anyone is pulling their hair out redrawing a ton of DL paths.
1651033567
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I'm very interested in the DL agnostic path editing script! :D Have you posted anything about it?
1651061267

Edited 1651061313
David M.
Pro
API Scripter
Cool, you were actually the one that gave me the idea from a previous thread where you were lamenting the existence of an edit function. :) Thought it would be an interesting project. Haven't posted anything about it yet. Here's a preview. Simple polygon vertex manipulation. A command spawns control pts (tokens) at each existing vertex and the script then listens for movement of these tokens, drawing a new path and deleting the old one (the path JSON is unfortunately read-only after creation). I have a split function that seems to work, too, allowing splitting at vertices only. I want to add a way to add/delete pts and do some cleanup before releasing. I was going to try my hand at a bezier tool, though after realizing that dynamic lighting doesn't respect non-oval bezier curves I think I'll hold off on that. Click for gif  
1651069284
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
As a long-time adherent of Adobe Illustrator (since 1988), I love the idea of this script. Shame about the lack of support for Bezier curves.