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?

January 23 (4 years ago)

Edited January 23 (4 years ago)

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.  Roll20 introduced their new page copy in November or December that gets Paths, Text, and Graphics out of order on the newly copied map.  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.  See:

https://app.roll20.net/forum/post/9570552/major-issue-with-new-true-page-copy/?pageforid=9570552#post-9570552

So, even a copy and paste of the object layer gets the order of objects wrong.  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. 

But are these commands, circled below, available to the API or are they purely user interface items?





Thanks in advance,
--
Tim

January 23 (4 years ago)

Edited January 23 (4 years ago)
Victor B.
Pro
Sheet Author
API Scripter

You can, but it will come down to naming convention for your objects.  You'll need to know what you are looking for and then set the layer of the objects appropriately.  This is right in the realm of TheAaron whom I sure will respond usually with code to make it work.  Front and back only work on the layer you are at.  If I'm reading your post right, you're getting stuff on the completely wrong layers (GM/Token/Map/Dynamic).  If its a simple issue of to front or back on the same layer, that should make it easier.  

January 23 (4 years ago)
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?

January 23 (4 years ago)
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.  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.  You can fix that by creating a function that manages the list of things to reorder.  The timing for each of the operations varies wildly—toBack() needs ~50ms to finish moving an object, toFront() needs ~1000ms.  Here's an example function, toFrontFixed(), which will space out calls to toFront() to give each one a chance to finish:

  const toFrontFixed = (()=>{
    let queue=[];
    let last=0;
    const DELAY = 1000;
    const burndownQueue = ()=>{
      let o = queue.shift();
      toFront(o);
      last = Date.now();
      if(queue.length){
        setTimeout(burndownQueue,DELAY);
      }
    };
    return (obj=>{
      if(queue.length){
        queue.push(obj);
      } else {
        let t = Date.now();
        if(last+DELAY > 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.  If there are some simple rules, like (Graphics at back, drawings in the middle, text on top), that could be pretty easy to manage.  (For example, by simply finding all the lines and pushing them to back, then finding all the graphics and pushing them to back).  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:
    1) That sounds like a legit bug that the Dev team needs to fix.  I'll see if I can reproduce it and file a ticket for it.
    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.  That's probably a little complicated, but should be doable.



January 23 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

OK, I've reproduced this and I think it's definitely a bug.  I'm going to file a ticket with the devs.

January 23 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

I've explored page duplication thoroughly with the API.  There are definitely several issues there.  I've passed my findings off to the devs.

January 23 (4 years ago)

Edited January 23 (4 years ago)


The Aaron said:

OK, I've reproduced this and I think it's definitely a bug.  I'm going to file a ticket with the devs.


Thanks, Aaron.  I have already and one of them came on the link I provided, but nothing has happened so far.  I don't know if you saw it, but I provided a step by step procedure to duplicate the issue.  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)  event is yet another dogs breakfast of mis-function. :(   >sigh<

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.  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

January 23 (4 years ago)


Victor B. said:

You can, but it will come down to naming convention for your objects.  You'll need to know what you are looking for and then set the layer of the objects appropriately.  This is right in the realm of TheAaron whom I sure will respond usually with code to make it work.  Front and back only work on the layer you are at.  If I'm reading your post right, you're getting stuff on the completely wrong layers (GM/Token/Map/Dynamic).  If its a simple issue of to front or back on the same layer, that should make it easier.  


Thanks Victor, I was going to just use imgsrc.  I'd forgotten about being able to name them. :)  That will make things easier, I think.

January 23 (4 years ago)


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.  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.  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.

January 23 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

It kind of depends.  The order is only messed up if you've ever changed it from the created order by pushing something back or forward.  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.


January 23 (4 years ago)


The Aaron said:

It kind of depends.  The order is only messed up if you've ever changed it from the created order by pushing something back or forward.  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?  On the scripts page, I see only this:



January 23 (4 years ago)

Source can be found here 

https://github.com/Roll20/roll20-api-scripts/tree/master/TruePageCopy/1.0

Just had a look at it TruePageCopy is good readable code, i like it.

January 24 (4 years ago)


Martijn S. said:

Source can be found here 

https://github.com/Roll20/roll20-api-scripts/tree/master/TruePageCopy/1.0

Just had a look at it TruePageCopy is good readable code, i like it.


Many, many thanks, Martijn. :)

January 24 (4 years ago)
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.

January 24 (4 years ago)

Edited January 24 (4 years ago)

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.  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.  No button appears.  Everything is running correctly when I save a script or restart the sandbox. 

EDIT: When I copy the campaign, it has no APIs.  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?  Thanks in advance to anyone.

January 24 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Hmm. I'll have to give this a whirl in the morning. 

January 25 (4 years ago)

Edited January 25 (4 years ago)

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.  :(


What I will do is copy my campaign, then add PaprikaCC's TRue Page Copy first.  Then gradually add the scripts I'm using, one by one