
I'm running a game that uses a ton of scripts to turn the Roll20 sandbox into an infographic, and that has required me to cobble together all sorts of functions related to Text objects. As this is the first time I've ever released a script "publicly", I figured I'd start small with the first, and simplest feature: Automatically (or manually; the script is very configurable!) add black shadows to text objects.
GitHub Link: https://github.com/Eunomiac/EunosRoll20Scripts
- Fully Plug-And-Play — Simply add "ETC.js" (available at the GitHub link above) to a new API script in your game, then restart the sandbox. Instructions are provided on script startup: You can add/remove shadows from selected text objects with a command, or toggle on automatic shadowing, which will add a text shadow to any new text object created by any player.
- Completely Hands-Off — Text shadows are created on the map layer (by default), then z-ordered behind their master text objects (in case you want the master objects on the map layer, too). Shadows will move when their master object moves; they will update their content, size, font, etc. in line with their master object; and they will remove themselves if their master object is removed. Ideally, you should never have to think about the text shadow objects themselves.
- Tuned for All Fonts & Sizes — The shadows are positioned depending on the font family and size, for a pleasing look whether you're shadowing a huge heading or a paragraph of body text.
- Configurable — Configuration options are clearly marked and commented in the script: tune offsets for specific font and size combinations, and change the color of the shadow objects or the layer on which they're created.
Future Plans
Below are features I already have coded in my game, but will take a little bit of work to extract out of the tangled web of my own script dependencies. I plan to add them to this package when I get the chance:
- Text Justification — By compiling a list of the pixel widths of every character, in every font, at every size, I have functions that left/center/right-justify a text object: You provide the text, desired justification, and a maximum width in pixels, then the script adds the necessary line breaks and white space (for padding). Vertical justification, too, so you can set maximum dimensions and define how text will align on both axes. Overflow can be truncated, truncated with ellipses, or allowed to overflow on a given axis. (The results turned out to be surprisingly precise: I've even used it to make tables, with carefully lined-up columns, using text objects.)
- Attribute Linking — A simple way to link a text object in the sandbox to an attribute on a character, either to display the attribute's current value, or provide a bar showing current value out of max value, or repeat a symbol a number of times equal to the attribute value. The text object will automatically update whenever the linked attribute is changed. Alternatively, text objects can be linked to API commands for direct control via chat, macro or other scripts.
- Permissions — A minor feature, but this will let the GM give permission to players to edit text objects in the sandbox, including a "free love" setting that opens all text objects up to editing by anyone. (I don't think there's a way to do this outside of a script, so here it is! ... Or, rather, soon will be!)
- A Ton of Convenience Functions — All sorts of utility functions for manipulating text in your own scripts: convert numbers to roman numerals, ordinals or words; align and position text objects relative to each other or the sandbox; toggle text objects on and off; grab character names from just about any reference (e.g. playerID, tokenID), then automatically and conditionally abbreviate them for length; add timers and countdowns that continuously update... basically, a grab bag of all the functions I've found helpful after running this game for over two years!
And Lastly
I'm a completely self-taught coder who is starved for feedback on just about anything: If you have any insights into my coding practices or bad habits or anything else, I really would love to hear them! And, of course, if you have any issues at all with this script (or suggestions on how to improve it), please let me know, with sincere thanks in advance.