Skip to content

Instantly share code, notes, and snippets.

@BaldarSilveraxe
Created August 16, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaldarSilveraxe/bd9d656adb38fca1f9c2 to your computer and use it in GitHub Desktop.
Save BaldarSilveraxe/bd9d656adb38fca1f9c2 to your computer and use it in GitHub Desktop.
Roll20 Chat API
/*global sendChat, createObj, getObj, toFront, state, _, log, on*/
/*jslint white: true */
var stopTalkingYouTwo = stopTalkingYouTwo || (function(){
'use strict';
var version = '0.1.0',
whisperUrl = 'https://s3.amazonaws.com/files.d20.io/images/11583165/eABhjOsunqhKHto2aRQ96A/thumb.png?1439727668',
whisperPing = function(currentPageGraphics) {
_.each(currentPageGraphics, function(obj) {whisperPingeer(obj); });
},
whisperPingeer = function(obj) {
var whisper = createObj('graphic',{
imgsrc: whisperUrl, layer: obj.get('layer'), pageid: obj.get('pageid'),
top: obj.get('top') - 35, left: obj.get('left') + 35, height: 35, width: 35 });
(function(){
var size = 70, delta = -10, threshold = 35, rate = 200,
interval = setInterval(function(){
whisper.set({
height: size,
width: size
});
size += delta;
if(size <= threshold) {
clearInterval(interval);
}
}, rate);
}());
setTimeout(function() {whisper.remove(); }, 1000);
},
handleInput = function(msg) {
var currentPageGraphics;
if (msg.type !== "api" ) {return; }
currentPageGraphics = findObjs({pageid: Campaign().get('playerpageid'), type: 'graphic', layer: 'objects' });
whisperPing(currentPageGraphics);
},
registerEventHandlers = function() {
on('chat:message', handleInput);
};
return {
RegisterEventHandlers: registerEventHandlers
};
}());
on('ready',function(){
'use strict';
stopTalkingYouTwo.RegisterEventHandlers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment