The
problem:
Right
now, if I want to have a soldier token that might be armed with any
arbitrary weapon, I have to create and import a graphic for the same
soldier, wielding every conceivable weapon. Then say I want a
dragonborn, but with the same weapons. Then an elf. Then a half elf.
The tokens add up, and the work I do to create them could be
automated.
A
solution:
Say
that instead, I had a base graphic for my soldier:
And
then I have a graphic for the bow he wields:
Then
I had the ability to iterate over the pixels and copy them from the
bow graphic and set them onto an instance of the base graphic with
the result:
And
then I had my sword graphic:
Which
I could merge with another instance of the same base:
That
would cut down on a lot of both graphic design work and image storage
on Roll20, because to arm my elves, I just need an elf base and I can
reuse the same weapon images. Same with my dragonborn, and any other
new race or PC or whatever I want to bring in later.
Implementation:
The
pixels only need to be copied from images. The interface could be
something like this:
object.getPixel
Parameters:
x The
horizontal coordinate of the pixel on the image
y The
vertical coordinate of the pixel on the image
Returns:
A
JSON object containing rgba information about the pixel. Example: {"r": 0, "g": 255, "b": 100, "a": 255}
If
called from a non image object, or the x and y coordinates are beyond
the bounds of the image, it returns the undefined type.
object.SetPixel
Parameters:
target The
target image on which to apply
color The JSON object containing the same rgba
information about the pixel that is returned from o.getPixel.
x
The horizontal
coordinate to set the pixel at.
y
The vertical coordinate to set
the pixel at.
Returns:
void
Alternative:
These
two methods would inevitably open up some really creative scripting
beyond what my intention is here. While I’m not familiar with the
Roll20 backend and the stress this would possibly open up to servers
and clients, another, more limited option that would achieve a
similar goal would be to have a method that merged two images into a
single instance on the tabletop.
object.MergeImage
Parameters:
target The
target image that effectively gets copied and pasted on top of the
instance of object o. X and Y coordinates of the target are mapped to
the exact X and Y of the base object. If target has larger dimensions
than the base, then anything beyond is cut off.
Returns:
void Another Alternative Skip the API altogether. Provide the ability to select two tokens and merge them from selecting the "merge" option from the right click context menu. Or even just "group" them. Once grouped, they are selected and moved as if they were a single token, and could be ungrouped as well. Conclusion I prefer my original API idea for getting and setting pixels, but all of these solutions would help get me to my goal. Complications that would need to be defined are things like: What happens if I set the new merged token to a sheet? The ideal would be that the sheet store the modified token and not just the base, but there may be things I don't know about how that works, as well as other complications that I haven't thought of.