Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Difference between revisions of "Script:Dynamic Lighting Animation"

From Roll20 Wiki

Jump to: navigation, search
(tagged as "discontinued API")
 
(15 intermediate revisions by one user not shown)
Line 1: Line 1:
The following script creates the API commands <code>!snapshot</code>, <code>!reset</code>, <code>!run</code>, and<code>!stop</code>.
+
{{script overview
 +
|name=Dynamic Lighting Animation
 +
|author={{user profile|235259|Brian}}
 +
|version=2.3
 +
|dependencies={{api repository link|splitArgs}}, {{api repository link|IsGM}}
 +
|lastmodified=2016-03-09
 +
|conflicts={{api repository link|Store Commands}}}}
  
==== Syntax ====
+
'''Dynamic Lighting Animation''' creates the API commands <code>!snapshot</code>, <code>!reset</code>, <code>!run</code>, and<code>!stop</code>. These are used to setup and then animate a sequence of "frames" changing the walls on the dynamic lighting layer. This effect could be useful for such things as a shifting magical labyrinth in real-time.
  
<blockquote style="border:1px #0088ee solid;background:#eee;padding:0.5em">!snapshot ''frames''<br>
+
=== Syntax ===
!reset<br>
+
{{syntaxbox top|formal=true|Dynamic Lighting Animation}}
!run<br>
+
{{API command|snapshot}} {{API parameter|name=frames}}<br>
!stop</blockquote>
+
{{API command|reset}}<br>
 +
{{API command|run}}<br>
 +
{{API command|stop}}
 +
{{Formal API command|
 +
{{token|S}} {{rarr}} {{API command|snapshot}} {{token|frames|-}}
 +
{{token|S}} {{rarr}} {{API command|reset}}<br>
 +
{{token|S}} {{rarr}} {{API command|run}}<br>
 +
{{token|S}} {{rarr}} {{API command|stop}}<br>
 +
{{token|frames}} {{rarr}} {{integer}}
 +
}}
 +
{{syntaxbox end}}
  
{| class="wikitable"
+
{{param description top}}
|-
+
{{param description|name=frames|value=The number of frames to hold the snapshot when running the animation. One frame is equal to 1/20th of a second, so a value of 20 will hold the snapshot for 1 second.}}
! Parameter
+
{{param description bottom}}
! Values
+
|-
+
| frames
+
| The number of frames to display the snapshot. The animation runs at 20fps, so using a value of 20 equates to a 1s snapshot.
+
|}
+
  
==== Installation ====
+
=== Using the commands ===
 
+
You need to enter the user ID of each GM in the game into the <code>gmIDs</code> variable (line 5). You can find someone's user ID from their wiki user page (there is a link to your personal user page in the sidebar of this wiki) or the URL of their profile page on the rest of the site.
+
 
+
If you do not accurately enter the GM's user IDs, the script will ignore your commands.
+
 
+
==== Using the commands ====
+
  
 
Only the GMs can use these API commands.
 
Only the GMs can use these API commands.
Line 34: Line 39:
  
 
You cannot record additional snapshots while the animation is running. If you need to change the animation or you're ready to record a different one, you need to use <code>!reset</code> to clear the old animation.
 
You cannot record additional snapshots while the animation is running. If you need to change the animation or you're ready to record a different one, you need to use <code>!reset</code> to clear the old animation.
 
==== Code ====
 
 
<pre data-language="javascript">
 
var animation = animation || {};
 
 
// Set to a list of the user IDs for each GM -- only the GM should be able to stop/start the animation!
 
// You can find your user ID by checking your userpage on the wiki, or the URL of your profile.
 
animation.gmIDs = [235259];
 
 
animation.running = false;
 
 
on('chat:message', function(msg) {
 
    if(msg.type != 'api') return;
 
   
 
    // Only use commands coming from a GM
 
    var isGM = false;
 
    var player = getObj('player', msg.playerid);
 
    _.each(animation.gmIDs, function(n) {
 
        if(player.get('d20userid') == n)
 
            isGM = true;
 
    });
 
    if(!isGM) return;
 
   
 
    var parts = msg.content.split(' ');
 
    var command = parts.shift().substring(1);
 
   
 
    switch(command)
 
    {
 
        case 'snapshot':
 
            if(animation.running)
 
            {
 
                sendChat("","/w gm You cannot add a frame while the animation is running.");
 
                break;
 
            }
 
           
 
            var pageid = Campaign().get('playerpageid');
 
            var dlPaths = findObjs({_type: 'path', _pageid: pageid, layer: 'walls'});
 
            var frames = parseInt(parts[0], 10);
 
            var pathdata = [];
 
           
 
            _.each(dlPaths, function(path) {
 
                var obj = {
 
                    id: path.id,
 
                    top: path.get('top'),
 
                    left: path.get('left'),
 
                    rotation: path.get('rotation'),
 
                    width: path.get('width'),
 
                    height: path.get('height'),
 
                    scaleX: path.get('scaleX'),
 
                    scaleY: path.get('scaleY')
 
                };
 
                pathdata.push(obj);
 
            });
 
            state.animation.frames.push({ data: pathdata, frames: frames });
 
            break;
 
        case 'reset':
 
            state.animation.curr_frame = 0;
 
            state.animation.frames = [];
 
            break;
 
        case 'run':
 
            animation.running = true;
 
            break;
 
        case 'stop':
 
            animation.running = false;
 
            break;
 
        default:
 
            break;
 
    }
 
});
 
 
on('ready', function() {
 
    if(!state.animation) state.animation = {};
 
    if(!state.animation.frames) state.animation.frames = [];
 
    if(!state.animation.curr_frame) state.animation.curr_frame = 0;
 
   
 
    var frame = state.animation.curr_frame;
 
    var frameCount = 0;
 
    setInterval(function() {
 
        if(!animation.running) return;
 
        if(!state.animation.frames[frame]) return;
 
       
 
        frameCount++;
 
        if(state.animation.frames[frame].frames <= frameCount)
 
        {
 
            animation.setupFrame(state.animation.frames[frame].data);
 
            frameCount -= state.animation.frames[frame].frames;
 
            frame++;
 
            if(frame == state.animation.frames.length) frame = 0;
 
            state.animation.curr_frame = frame;
 
        }
 
    }, 50);
 
});
 
 
/**
 
* Set the paths on the DL layer to the settings for the current animation frame.
 
*/
 
animation.setupFrame = function(pathdata) {
 
    _.each(pathdata, function(obj) {
 
        var path = getObj('path', obj.id);log(obj);
 
        path.set({
 
            top: obj.top,
 
            left: obj.left,
 
            rotation: obj.rotation,
 
            width: obj.width,
 
            height: obj.height,
 
            scaleX: obj.scaleX,
 
            scaleY: obj.scaleY
 
        });
 
    });
 
};
 
</pre>
 
  
 
==== Notes ====
 
==== Notes ====
Line 151: Line 44:
 
This script does '''not''' create or delete paths. If you want a frame with one or more paths missing, you can simply move them off the map.
 
This script does '''not''' create or delete paths. If you want a frame with one or more paths missing, you can simply move them off the map.
  
[[Category:User API Scripts|Dynamic Lighting Animation]]
+
=== Changelog ===
[[Category:API Commands|Dynamic Lighting Animation]]
+
{{changelog version|2.3|2016-03-09|* Update for one-click install}}
 +
{{changelog version|2.2|2015-01-24|* [bugfix] No-arg crash}}
 +
{{changelog version|2.1|2015-01-22|* Fixed transcription error}}
 +
{{changelog version|2.0|2015-01-08|* Release}}
 +
[[Category:Discontinued API Scripts]]

Latest revision as of 12:43, 17 June 2020

API ScriptAuthor: Brian
Version: 2.3
Last Modified: 2016-03-09
Code: Dynamic Lighting Animation
Dependencies: splitArgs, IsGM
Conflicts: Store Commands

Dynamic Lighting Animation creates the API commands !snapshot, !reset, !run, and!stop. These are used to setup and then animate a sequence of "frames" changing the walls on the dynamic lighting layer. This effect could be useful for such things as a shifting magical labyrinth in real-time.

Contents

[edit] Syntax

!snapshot <frames>
!reset
!run
!stop
Formally:

S

→ !snapshot frames


S

→ !reset

S

→ !run

S

→ !stop

frames

integer
Parameter Values
frames The number of frames to hold the snapshot when running the animation. One frame is equal to 1/20th of a second, so a value of 20 will hold the snapshot for 1 second.

[edit] Using the commands

Only the GMs can use these API commands.

In order to "record" the animation, move the player bookmark to the page with the DL layer you want to animate. Set up the paths on the DL layer as you want, and then use the !snapshot command.

The animation record will persist between game sessions, although the script is not set up to record different animations for different pages.

Once you're ready to show off your fantastical magical labyrinth to your players, use the !run command. Stop the animation with !stop.

You cannot record additional snapshots while the animation is running. If you need to change the animation or you're ready to record a different one, you need to use !reset to clear the old animation.

[edit] Notes

This script does not create or delete paths. If you want a frame with one or more paths missing, you can simply move them off the map.

[edit] Changelog

v2.3 (2016-03-09)

  • Update for one-click install


v2.2 (2015-01-24)

  • [bugfix] No-arg crash


v2.1 (2015-01-22)

  • Fixed transcription error


v2.0 (2015-01-08)

  • Release