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

Transition - An API Script for Shape, Text, Jukebox, Daylight & Macro Transitions

1714662338

Edited 1714662354
Coryphon
Pro
Sheet Author
Compendium Curator
Transition An API Script for Shape, Text, Jukebox, Daylight &amp; Macro Transitions Script and these instructions available &nbsp; here . As I wanted to create a dramatic opening page for my new Lord of the Rings 5e Roleplaying game &nbsp;( from Free League Publishing ) , &nbsp; I started writing a script to automate transparency fading. &nbsp; ‘Transition’ &nbsp; is the result, &nbsp; and the original scope has expanded considerably ! Here is a video showing my opening sequence just to give a sense of what the script can do :&nbsp; link The above video sequence was generated from : !transition sequence fade-jb:LoTR5e_OpeningMix:0:12 3000 #RingText -NqOagh2CoNd-UK2vApe 1000 #O-Ring -Nq81VUKHMbNM-iKaOJc 1000 #Logo -Nq4HzffCq5YTIANqhEs|-Nq4ILn0YaV8Z4GA6R6J 1000 #Background -NqTIBvszqB9c9qGYGWg 4000 #Text -Nqhf1HIqHcxsO3TJ8uP -NqmWbCG5TNtRx-u0huJ 3000 -NqmWbgjwBBFiAa7ljhd 3000 -NqmWcAUZz1oGnI6T77X 3000 -NqmWcgiXMaapJPiNAHE 3000 fade-dl:0.3:0.01:80 3000 fade-jb:LoTR5e_OpeningMix:12:0 ?{Reset||reset} So the whole sequence is a single macro call. &nbsp; The script uses setInterval and Promises to handle simultaneous and sequential transition effects, &nbsp; by which I mean a workflow sequence that can support, &nbsp; for example : Fade in the music AS WE Fade in Shape A &nbsp; &amp; &nbsp; Shape B simultaneously THEN Wait 3 seconds THEN Fade in Shape C and fade out Text AA simultaneously THEN Wait 5 seconds THEN Fade out Daylight &nbsp; &amp; &nbsp; fade out Music simultaneously ( In the examples below &nbsp; &lt;arg &gt;&nbsp; are mandatory, &nbsp;[arg]&nbsp; are optional ) Notes, Hints &amp; Tips NOTE 1 :&nbsp; The transparency aspect of the script ignores any colour values explicitly set to &nbsp; ‘transparent’. &nbsp; It works by using the HTML colour trick of appending opacity to a colour code e.g. &nbsp; #ff0000 becomes &nbsp; #ff0000ff. &nbsp; Therefore, &nbsp; you can explicitly set e.g. &nbsp; stroke or fill colour to &nbsp; ‘transparent’ &nbsp; if you want it to be ignored. HINT :&nbsp; I found that transitioning a shape with both &nbsp; fill &nbsp; and &nbsp; stroke &nbsp; was not quite as nice as using fill alone, &nbsp; as the stroke &nbsp;( border )&nbsp; could be seen during the transition. &nbsp; So generally I left stroke explicitly transparent. &nbsp; This may be a browser-specific thing. NOTE 2 :&nbsp; Transition uses a number of defaults for its operations. &nbsp; As follows : Shapes and Text: Increment 4, interval 80ms (range 0 to 255, 00 to FF) Jukebox: Increment 2, interval 800ms (volume range 0 to 100) Daylight: Increment 0.025, interval 50ms (range 0.0 to 1.0)) NOTE 3 :&nbsp; The script automatically &nbsp; ‘absolutes’ &nbsp; increment &nbsp;( and delay )&nbsp; values and sets the sign according to the operation. WARNING :&nbsp; Beware of setting milliseconds too small, &nbsp; I found that around 50ms or less the transitions could get a bit laggy. &nbsp; Again maybe browser/computer dependent. &nbsp; I do use 10ms increments in reset operations for speed &nbsp;( see below ) . TIP :&nbsp; If you are fading &nbsp; in , &nbsp; then you need to start from transparent for your selected objects. &nbsp; As you cannot use &nbsp; ‘transparent’ &nbsp;( as the script would never know what your target colour would be )&nbsp; you should EITHER set your colours manually appended with &nbsp; ’00’ &nbsp; to force transparency OR select the items and add &nbsp;' reset '&nbsp; as the last argument to Transition &nbsp;( see below ) . &nbsp; I went through MANY iterations of my opening sequence to get the timings etc. &nbsp; correct, &nbsp; so for Transition sequences and Jukebox Fade you can append with &nbsp; ‘reset’ &nbsp; to get back to your starting state. When building your sequence command it is easiest to do it in a macro and add :&nbsp; ?{Reset||reset} &nbsp; at the end to allow easy run and reset cycles. &nbsp; Caveats to resetting are : Resetting daylight fades will set back to 100% brightness Resetting jukebox fades sets track start volume to end volume. Track will play if start volume &gt; 0. (Unfortunately you cannot reset a track to its starting play point as that is not exposed by the API) Macros executed or wrapped by Transition obviously cannot be reset NOTE 4 :&nbsp; Jukebox Fade, &nbsp; Daylight Fade, &nbsp; Executed Macros and Wrapped Macros are ASYNCHRONOUS, &nbsp; they will run while other sequences are running. &nbsp; For me this made sense with the use cases I had in mind, &nbsp; and it is much easier to just multiply the increments by the ms delays and add an equivalent pause after an operation to force synchronicity, &nbsp; rather than pollute the &nbsp; ‘keyword space’ &nbsp; with synchronous versions, &nbsp; e.g. : transition sequence fade-jb : LoTR5e_OpeningMix : 0 : 12 &nbsp; -NqOagh2CoNd-UK2vApe &nbsp;( Asynchronous ) transition sequence fade-jb : LoTR5e_OpeningMix : 0 : 12 4800 &nbsp; -NqOagh2CoNd-UK2vApe &nbsp;( ’Synchronous’ ) ( The default of jukebox fade increment 2 and delay 800ms for 0 to 12 gives 6 x 800 &nbsp; = &nbsp; 4800ms ) Simple Commands Transition has a number of &nbsp; ‘convenience’ &nbsp; actions for &nbsp; ‘quick and dirty’ &nbsp; effects. !transition selected &lt;in|out&gt; [reset] As implied, &nbsp; select a group of objects and run the script. &nbsp; The objects &nbsp;( text and shape )&nbsp; will fade out to transparent or in to completely opaque. !transition fade-daylight &lt;value 0.0 to 1.0&gt; [increment, default:0.04] [milliseconds, default: 80] Change daylight brightness. &nbsp; The first value can also take a number of &nbsp;( case-insensitive )&nbsp; presets : day &nbsp;( 1.0 ) overcast &nbsp;( 0.8 ) dusk &nbsp;( 0.4 ) moonlight &nbsp;( 0.2 ) night &nbsp;( 0.0 ) This can then be macro-ed up as : ! transition fade-daylight &nbsp; ?{Light Level|Day|Overcast|Dusk|Moonlight|Night} ( I stole this code from another script somewhere, &nbsp; or maybe off the forum, &nbsp; but I can ' t remember where &nbsp; ;- ) !transition fade-jukebox&nbsp;[increment, default: 2] [milliseconds, default: 800] [reset] Fade a jukebox track from one volume to another. &nbsp; These can be &nbsp; ‘stacked’ &nbsp; in a macro to do a cross-fade. &nbsp; e.g. : ! transition fade-jukebox Birdsong 20 0 1 1000 ! transition fade-jukebox WargRiders 0 20 1 1000 WARNING 1: Transition does not at this time support Jukebox tracks with spaces in their names, currently you have to remove spaces or replace them with dashes or underscores! WARNING 2: Setting a delay of less than 500ms seems to stop the track playing immediately, the volume fades, then the track starts !transition wrap-macro&nbsp;&lt;from|to&gt; [from|to] [from|to]… This command allows you to pass repeated incremental values to a macro. &nbsp; An example would be : ! transition wrap-macro LightMacro 1 500 1|5 Where LightMacro is : ! token-mod &nbsp; --on has_bright_light_vision emits_bright_light emits_low_light &nbsp; --set bright_light_distance#arg1 low_light_distance#arg1 dim_light_opacity#20 The example would run LightMacro 5 times, &nbsp; incrementing the value of &nbsp; arg1 &nbsp; by 1 every 500ms from 1 to 5. Up to 9 arguments can be specified &nbsp;( arg1 - arg9 ) , &nbsp; each with their own &nbsp; to|from &nbsp; values. &nbsp; Arguments can be re-used as shown in the example above, &nbsp; but note that a single increment and ms delay is applied to &nbsp; all &nbsp; args &nbsp;( at this time !) . &nbsp; Again, &nbsp; you could stack different commands within one macro. Also note that you do not have to use ANY arg values in your wrapped macro if you just want to fire it a number of times. &nbsp; For example, &nbsp; a target macro of : ! token-mod &nbsp; --move 1u &nbsp; --ids &nbsp; -NweH1zHSjf9UBIQZEqO will cause the token to move 1 unit per iteration. WARNING :&nbsp; I added this functionality because I wanted to move page elements and there was no point reinventing the wheel as TokenMod is the go-to for this type of thing. &nbsp; However , &nbsp; do note that you must use &nbsp; --ids &nbsp; because this is an api calling an api so no selected items get passed through in the message, &nbsp; and &nbsp; this further means you must set the TokenMod config item to allow players to use &nbsp; --ids &nbsp; as the api does not pass the &nbsp; ‘ is player a GM ’ &nbsp; test within Token Mod. &nbsp;( Yeah, &nbsp; that didn’t take me half a day to find &nbsp; ;- )) Utility Commands A selection of convenience functions which helped me setup pages for transitions. !transition layout-text &lt;spacing (pixels)&gt; Convenience function to vertically space out a group of selected text objects and justify them using &nbsp; left , &nbsp; right or &nbsp; center | centre . &nbsp; The function finds the highest text item and spaces down from there. !transition markup-selection Function that adds a text box with the items ID to the top left of each selected object. &nbsp; Can be useful when planning sequences to keep track of ids and the location of transparent items. !transition debug-on / debug-off Off by default, &nbsp; a debug flag is held in the state object. &nbsp; When on, &nbsp; timestamped detailed stack-indented logging is enabled. &nbsp; Can be useful in complex sequences where multiple intervals are running. !transition kill Should any intervals get out of control, &nbsp; e.g. &nbsp; get into an infinite loop &nbsp;( which should not be possible !)&nbsp; then this command will kill any running intervals. &nbsp; Using the debug-on command is the best way to diagnose. Sequence So, &nbsp; going back to our introduction for creating our opening screen to wow and delight our players, &nbsp; here is the command line again : ! transition sequence fade-jb : LoTR5e_OpeningMix : 0 : 12 3000 &nbsp; #RingText &nbsp; -NqOagh2CoNd-UK2vApe 1000 &nbsp; #O-Ring &nbsp; -Nq81VUKHMbNM-iKaOJc 1000 &nbsp; #Logo &nbsp; -Nq4HzffCq5YTIANqhEs|-Nq4ILn0YaV8Z4GA6R6J 1000 &nbsp; #Background &nbsp; -NqTIBvszqB9c9qGYGWg 4000 &nbsp; #Text &nbsp; -Nqhf1HIqHcxsO3TJ8uP &nbsp; -NqmWbCG5TNtRx-u0huJ 3000 &nbsp; -NqmWbgjwBBFiAa7ljhd 3000 &nbsp; -NqmWcAUZz1oGnI6T77X 3000 &nbsp; -NqmWcgiXMaapJPiNAHE 3000 fade-dl : 0.3 : 0.01 : 80 3000 fade-jb : LoTR5e_OpeningMix : 12 : 0 &nbsp; ?{Reset||reset} So we can chain together series of operations using a number of elements, &nbsp; the var=n notation below signifies default values if omitted. &nbsp; Each command below opaerates as per the standalone commands detailed above. fade-jb :&nbsp; Fade Jukebox with colon-delimited arguments of &nbsp; fade-jb:Track:StartVolume:EndVolume:[Increment=2]:[Delay=800] fade-dl :&nbsp; Fade daylight with colon-delimited arguments of &nbsp; fade-dl:TargetBrightness:[Increment=0.04]:[Delay=80] exec-macro :&nbsp; Execute a macro asynchronously. &nbsp; Takes no arguments, &nbsp; just fires it off :&nbsp; exec-macro:MyMacro wrap-macro :&nbsp; Execute a macro with colon-delimited arguments of &nbsp; wrap-macro:MacroName:Increment:Delay:arg1-from|arg1-to:arg2-from|arg2-to:argn-from|argn-to #Comment :&nbsp; As it can get a bit confusing with long sequences of IDs, &nbsp; any term starting with &nbsp; # &nbsp; is ignored as a comment &nbsp;( no spaces !) Number :&nbsp; Any number between sequence items is used as a delay in milliseconds -Naaaaaaa or -Naaaaaa|-Nbbbbbb :&nbsp; Shape or Text IDs for transparency transitions. &nbsp; Each ID tuple can take the form &nbsp; ID:[in|out]:[Increment=4]:[Delay=80] &nbsp; and multiple tuples can be pipe-delimited together for simultaneous transitions. Note that the fade in/out variable defaults as follows :&nbsp; Shapes will fade &nbsp; out &nbsp; to transparent, &nbsp; text will fade &nbsp; in &nbsp; from transparent. &nbsp; That is why in the example above only the IDs are shown with no colon-delimited extra information. So this &nbsp;( two shapes ):&nbsp; -Nq4HzffCq5YTIANqhEs|-Nq4ILn0YaV8Z4GA6R6J Actually resolves to this :&nbsp; -Nq4HzffCq5YTIANqhEs:out:4:80|-Nq4ILn0YaV8Z4GA6R6J:out:4:80 And this &nbsp;( a text object ):&nbsp; -Nqhf1HIqHcxsO3TJ8uP Actually resolves to this :&nbsp; -Nqhf1HIqHcxsO3TJ8uP:in:4:80 ( These defaults were just the most useful for me &nbsp; ;- ) Any problems or suggestions then please contact me on Roll20 at &nbsp; <a href="https://app.roll20.net/users/2447813/coryphon" rel="nofollow">https://app.roll20.net/users/2447813/coryphon</a> ~&nbsp; Coryphon &nbsp;~ PS Another quick example &nbsp; here .
1714665101
timmaugh
Pro
API Scripter
That's a pretty cool idea, Coryphon! Your comment above the code says you're not a js programmer, but the script is pretty impressive!
1714665584
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Seconded! That is pretty amazing!
1714665715
Coryphon
Pro
Sheet Author
Compendium Curator
Thank you very much!
1714764870
Coryphon
Pro
Sheet Author
Compendium Curator
Hiya, New version of script (0.2) available after feedback from Timmaugh, changes are: - Wrap macro args are now ++arg1++ etc., rather than just arg1 to avoid spurious replacements - Actual object ID detection now uses a lookup into a regex of all objects rather than 'startsWith("-N")' as this is not safe ~ Coryphon ~
this is cool but for smooth brains, also very confusing or maybe the lack of no sleep for 30 hrs and trying to understand this just hurts me. A YT video of the entire process would be nice.&nbsp;
1718181696
Coryphon
Pro
Sheet Author
Compendium Curator
Novercalis said: this is cool but for smooth brains, also very confusing or maybe the lack of no sleep for 30 hrs and trying to understand this just hurts me. A YT video of the entire process would be nice.&nbsp; Hi Novercalis, Sure, completely understandable, I will try and put something together that makes it a bit more coherent! ;-) Give me a few days and I'll sort something out, Thursday is my game night so hopefully after that... Do feel free to message me in the meantime with any specific questions, Regards, ~ Coryphon ~
bumping for a potential update on a YT video showing how to use this on a step by step way.
1721637916
Coryphon
Pro
Sheet Author
Compendium Curator
Novercalis said: bumping for a potential update on a YT video showing how to use this on a step by step way. Hi Novercalis, my apologies, is on my radar to do, ~ C ~
1722581844

Edited 1722581920
Coryphon
Pro
Sheet Author
Compendium Curator
Novercalis said: bumping for a potential update on a YT video showing how to use this on a step by step way. Hi Novercalis, My apologies for the long delay, please find a tutorial video&nbsp; here . Making videos is not my forte so I would love to say it is 20 minutes of video gold, buuuuut it probably isn't :-) I have also updated the Transition script with a couple of fixes which I found while making the video! The script can be found&nbsp; here , Best regards, ~ Coryphon ~