yasd/apps/server/lib/DeckButton.js

59 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2022-04-29 11:21:51 -04:00
'use strict'
module.exports = class deckButton {
constructor(iconPath, label, color, pressAction, releaseAction=null, toggleable=false, toggleIcon=null){
this.iconPath = iconPath;
this.label = label;
this.color = color;
this.pressAction = pressAction;
this.releaseAction = releaseAction;
this.toggleable = toggleable;
this.toggleIcon = toggleIcon;
}
press(){
if(!this.pressAction){
return;
}
let action = this.pressAction.split(':');
try {
const o = pluginloader.plugins[action[0]];
const f = o[action[1]]
const a = f(action[2])
} catch (error) {
console.log("Press Referenced plugin not found.")
}
}
release(){
if(!this.releaseAction){
return;
}
let action = this.releaseAction.split(':');
try {
const o = pluginloader.plugins[action[0]];
const f = o[action[1]]
const a = f(action[2])
} catch (error) {
console.log("Release Referenced plugin not found.")
}
}
toJSON() {
return {
"iconPath": this.iconPath,
"label": this.label,
"color": this.color,
"pressAction": this.pressAction,
"releaseAction": this.releaseAction,
"toggleable": this.toggleable,
"toggleIcon": this.toggleIcon
};
}
static from(json) {
return Object.assign(new deckButton(), json)
}
}