Skip to content

Instantly share code, notes, and snippets.

@SCPRedMage
Created January 19, 2017 00:13
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 SCPRedMage/4f848ecf11e8815e79a6c506aa93a664 to your computer and use it in GitHub Desktop.
Save SCPRedMage/4f848ecf11e8815e79a6c506aa93a664 to your computer and use it in GitHub Desktop.
Script to trigger sheet worker updates when linked bar is updated
var BarMonitor = BarMonitor || (function() {
'use strict';
var version = '0.1',
lastUpdate = 1484779400,
attrUpdate = function(obj,bar)
{
var link = obj.get(bar+"_link");
var value = obj.get(bar+"_value");
if(!_.isUndefined(link) && link !== "")
{
var linkAttr = getObj("attribute", link);
if (!_.isUndefined(linkAttr))
{
findObjs({ _characterid: linkAttr.get("_characterid"), _type: "attribute", name: "recalc1"})[0].setWithWorker({current: 1});
//linkAttr.setWithWorker( { current: value } );
}
}
},
barUpdate = function(obj,prev)
{
if (obj.get("bar1_value") != prev["bar1_value"] && obj.get("bar1_value") != -99 && prev["bar1_value"] != -99)
attrUpdate(obj,"bar1");
if (obj.get("bar2_value") != prev["bar2_value"] && obj.get("bar2_value") != -99 && prev["bar2_value"] != -99)
attrUpdate(obj,"bar2");
if (obj.get("bar3_value") != prev["bar3_value"] && obj.get("bar3_value") != -99 && prev["bar3_value"] != -99)
attrUpdate(obj,"bar3");
},
checkInstall = function() {
log('-=> Bar Monitor v'+version+' <=- ['+(new Date(lastUpdate*1000))+']');
},
RegisterEventHandlers = function() {
on('change:graphic:bar1_value', barUpdate);
on('change:graphic:bar2_value', barUpdate);
on('change:graphic:bar3_value', barUpdate);
};
return {
CheckInstall: checkInstall,
RegisterEventHandlers: RegisterEventHandlers
};
}());
on("ready",function(){
'use strict';
BarMonitor.CheckInstall();
BarMonitor.RegisterEventHandlers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment