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

Can Paths, Text, and Graphics Be Arranged Using the API? Or Is That a User Interface Issue?

1611389467

Edited 1611389539
Hi folks, this is a last desperate attempt to salvage something from the 8 months of work I put into developing a wargames campaign manager before I throw up my hands and give up.&nbsp; Roll20 introduced their new page copy in November or December that gets Paths, Text, and Graphics out of order on the newly copied map.&nbsp; I had been using True Page Copy up until then to duplicate the players' and GM maps each turn, something that is a vital part of the campaign.&nbsp; See: <a href="https://app.roll20.net/forum/post/9570552/major-issue-with-new-true-page-copy/?pageforid=9570552#post-9570552" rel="nofollow">https://app.roll20.net/forum/post/9570552/major-issue-with-new-true-page-copy/?pageforid=9570552#post-9570552</a> So, even a copy and paste of the object layer gets the order of objects wrong.&nbsp; I thought I might try to write an API fired on a text chat command that would take groups of similar objects and use the "To Back" and "To Front" commands to somehow reset the order of objects properly.&nbsp; But are these commands, circled below, available to the API or are they purely user interface items? Thanks in advance, -- Tim
1611389699

Edited 1611389900
Victor B.
Pro
Sheet Author
API Scripter
You can, but it will come down to naming convention for your objects.&nbsp; You'll need to know what you are looking for and then set the layer of the objects appropriately.&nbsp; This is right in the realm of TheAaron whom I sure will respond usually with code to make it work.&nbsp; Front and back only work on the layer you are at.&nbsp; If I'm reading your post right, you're getting stuff on the completely wrong layers (GM/Token/Map/Dynamic).&nbsp; If its a simple issue of to front or back on the same layer, that should make it easier.&nbsp;&nbsp;
1611392494
GiGs
Pro
Sheet Author
API Scripter
They are available to the API, but as Victor says, finding a way to set the order entirely programatically might be tricky. Does True Page Copy not work any more?
1611412808
The Aaron
Roll20 Production Team
API Scripter
Just to add to the discussion (and provide the obligatory code), To Front and To Back are provided to the API via a couple of free functions, toFront() and toBack() respectively.&nbsp; However, they both have horrible race conditions meaning if you call them too rapidly, the ordering gets overwritten by successive calls before the prior calls finish.&nbsp; You can fix that by creating a function that manages the list of things to reorder.&nbsp; The timing for each of the operations varies wildly—toBack() needs ~50ms to finish moving an object, toFront() needs ~1000ms.&nbsp; Here's an example function, toFrontFixed(), which will space out calls to toFront() to give each one a chance to finish: const toFrontFixed = (()=&gt;{ let queue=[]; let last=0; const DELAY = 1000; const burndownQueue = ()=&gt;{ let o = queue.shift(); toFront(o); last = Date.now(); if(queue.length){ setTimeout(burndownQueue,DELAY); } }; return (obj=&gt;{ if(queue.length){ queue.push(obj); } else { let t = Date.now(); if(last+DELAY &gt; t){ queue.push(obj); setTimeout(burndownQueue,(last+DELAY-t)); } else { toFront(obj); last = t; } } }); })(); That covered, the next major problem is how to order things.&nbsp; If there are some simple rules, like (Graphics at back, drawings in the middle, text on top), that could be pretty easy to manage.&nbsp; (For example, by simply finding all the lines and pushing them to back, then finding all the graphics and pushing them to back).&nbsp; If the rules are more complicated, so too will the script be. If your use case is always "When I copy a page, I want the ordering to match the ordering on the source page", then there are two things that can be done: &nbsp;&nbsp;&nbsp;&nbsp;1) That sounds like a legit bug that the Dev team needs to fix.&nbsp; I'll see if I can reproduce it and file a ticket for it. &nbsp; &nbsp; 2) A script could be written that would figure out a mapping between the source page's objects and the copy page's objects, then find the order they should be in and make changes to that ordering until they match.&nbsp; That's probably a little complicated, but should be doable.
1611413042
The Aaron
Roll20 Production Team
API Scripter
OK, I've reproduced this and I think it's definitely a bug.&nbsp; I'm going to file a ticket with the devs.
1611415357
The Aaron
Roll20 Production Team
API Scripter
I've explored page duplication thoroughly with the API.&nbsp; There are definitely several issues there.&nbsp; I've passed my findings off to the devs.
1611427704

Edited 1611428403
The Aaron said: OK, I've reproduced this and I think it's definitely a bug.&nbsp; I'm going to file a ticket with the devs. Thanks, Aaron.&nbsp; I have already and one of them came on the link I provided, but nothing has happened so far.&nbsp; I don't know if you saw it, but I provided a step by step procedure to duplicate the issue.&nbsp; While I was waiting, I played with the jukebox over the Christmas holidays and was perturbed to find that unless the GM is logged in playing tracks on the on("change:token:lastmove", function(obj, prev)&nbsp; event is yet another dogs breakfast of mis-function. :(&nbsp;&nbsp; &gt;sigh&lt; I'm going to go ahead and figure out what images are used in my map and then run the ordering successively, like !order1 then !order2, etc to avoid calling them too rapidly - I'm so glad you mentioned that.&nbsp; My campaign was ready to go and I just don't want to throw all I've done away to reinvent it at Foundry. -- Tim
Victor B. said: You can, but it will come down to naming convention for your objects.&nbsp; You'll need to know what you are looking for and then set the layer of the objects appropriately.&nbsp; This is right in the realm of TheAaron whom I sure will respond usually with code to make it work.&nbsp; Front and back only work on the layer you are at.&nbsp; If I'm reading your post right, you're getting stuff on the completely wrong layers (GM/Token/Map/Dynamic).&nbsp; If its a simple issue of to front or back on the same layer, that should make it easier.&nbsp;&nbsp; Thanks Victor, I was going to just use imgsrc.&nbsp; I'd forgotten about being able to name them. :)&nbsp; That will make things easier, I think.
GiGs said: They are available to the API, but as Victor says, finding a way to set the order entirely programatically might be tricky. Does True Page Copy not work any more? Unfortunately not.&nbsp; I've sent a message to PaprikaCC wondering if there is a way to fire it from an API, bit I haven't heard back, yet.&nbsp; Given the way copy and paste is also not preserving order, I suspect the developers have done something that would also sabotage True Page Copy.
1611429086
The Aaron
Roll20 Production Team
API Scripter
It kind of depends.&nbsp; The order is only messed up if you've ever changed it from the created order by pushing something back or forward.&nbsp; If PaprikaCC is walking the zorder field when creating things on the new page, it should work correctly. (checked, it does walk the zorder) If you change line 135 to this: if (msg.type !== 'api' || !playerIsGM(msg.playerid) || 'api'!==msg.playerid) return; You should be able to call it from the API.
The Aaron said: It kind of depends.&nbsp; The order is only messed up if you've ever changed it from the created order by pushing something back or forward.&nbsp; If PaprikaCC is walking the zorder field when creating things on the new page, it should work correctly. (checked, it does walk the zorder) If you change line 135 to this: if (msg.type !== 'api' || !playerIsGM(msg.playerid) || 'api'!==msg.playerid) return; You should be able to call it from the API. Thanks Aaron, does Bodin have this available in github or elsewhere?&nbsp; On the scripts page, I see only this:
Source can be found here&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/TruePageCopy/1.0" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/TruePageCopy/1.0</a> Just had a look at it TruePageCopy is good readable code, i like it.
Martijn S. said: Source can be found here&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/TruePageCopy/1.0" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/TruePageCopy/1.0</a> Just had a look at it TruePageCopy is good readable code, i like it. Many, many thanks, Martijn. :)
1611446813
The Aaron
Roll20 Production Team
API Scripter
You can also just use import from the script library to get the editable source in your game.
1611456815

Edited 1611458217
The Aaron said: You can also just use import from the script library to get the editable source in your game. Ah, OK, that worked. Now the problem is that true page ccopy doesn't work.&nbsp; Trying to follow: const content = 'If you wish to use True Page Copy, you can either use the Duplicate Page ' + 'Button or type "!pagecopy" or "!pagecopy source" when you are looking at ' + 'the page you want to copy from. Next, move to the map that you want to copy' + 'to and enter "!pagecopy" again. A button prompt will appear asking if you ' + 'want to copy the pages.'; Whether I use your mod or not, the above simply does not work.&nbsp; No button appears.&nbsp; Everything is running correctly when I save a script or restart the sandbox.&nbsp; EDIT: When I copy the campaign, it has no APIs.&nbsp; When I import True Page Copy, save/run it, and run the above instructions, it still doesn't work, with or without the change to line 135. Any ideas?&nbsp; Thanks in advance to anyone.
1611465475
The Aaron
Roll20 Production Team
API Scripter
Hmm. I'll have to give this a whirl in the morning.&nbsp;
1611555312

Edited 1611607141
Hmmm, well it works on the test campign I set up which I mentioned in the link above: Now I need to figure out why it is not working with my campaign.&nbsp; :( What I will do is copy my campaign, then add PaprikaCC's TRue Page Copy first.&nbsp; Then gradually add the scripts I'm using, one by one