From 76dc8d00d111b74516d141c6f8c43b016bd71010 Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Sat, 14 Oct 2023 22:11:22 +0200 Subject: [PATCH] Format code --- README.md | 4 +- actions.js | 184 ++++++------- feedbacks.js | 172 ++++++------ main.js | 459 ++++++++++++++++---------------- presets.js | 261 +++++++++--------- project.js | 246 ++++++++--------- receive/current_page_request.js | 15 +- receive/current_page_update.js | 15 +- receive/message_executable.js | 18 +- receive/pad_name_update.js | 21 +- receive/pad_status_update.js | 13 +- receive/project_update.js | 21 +- 12 files changed, 715 insertions(+), 714 deletions(-) diff --git a/README.md b/README.md index a3dcecf..d6667c4 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,5 @@ See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE) # Install -* Inside `PlayWallCompanion` run `npm install` to install all dependencies (on Windows: `npm.cmd install) -* Set parent directory (the parent directory contains the `PlayWallCompanion`) as the `Developer module path` +- Inside `PlayWallCompanion` run `npm install` to install all dependencies (on Windows: `npm.cmd install) +- Set parent directory (the parent directory contains the `PlayWallCompanion`) as the `Developer module path` diff --git a/actions.js b/actions.js index acccc8c..8867080 100644 --- a/actions.js +++ b/actions.js @@ -1,94 +1,94 @@ module.exports = function (self) { - self.setActionDefinitions({ - pad_playback_action: { - name: 'Pad Playback', - options: [ - { - id: 'type', - type: "dropdown", - choices: [ - { id: 'NAME', label: 'Name' }, - { id: 'NUMBER', label: 'Number' } - ], - label: 'Type', - default: 'NUMBER' - }, - { - id: 'name', - type: 'textinput', - label: 'Pad Name', - default: '', - required: true, - isVisible: (options) => options.type === 'NAME' - }, - { - id: 'index', - type: 'number', - label: 'Pad Number', - default: '', - required: true, - isVisible: (options) => options.type === 'NUMBER' - }, - ], - callback: async (event) => { - if (event.options.type === 'NAME') { - const pad = self.currentProject.findPadByName(event.options.name); - if (!pad) { - self.log('warning', 'Cannot find a pad with name ' + event.options.name); - return; - } - self.sendToWebSocket('cart-action', { - 'padId': pad.id - }); - } else if (event.options.index) { - self.sendToWebSocket('cart-action', { - 'padIndex': event.options.index - 1 - }); - } - }, - }, - page_set_action: { - name: 'Page Set', - options: [ - { - id: 'page', - type: 'number', - label: 'Page Number', - default: '', - }, - ], - callback: async (event) => { - self.sendToWebSocket('page-action', { - 'page': event.options.page - 1 - }); - }, - }, - pad_navigate_action: { - name: 'Page Navigate', - options: [ - { - id: 'type', - type: 'dropdown', - choices: [ - { id: 'PREVIOUS', label: 'Previous' }, - { id: 'NEXT', label: 'Next' } - ], - label: 'Action', - default: '', - }, - ], - callback: async (event) => { - self.sendToWebSocket('navigate-action', { - 'action': event.options.type - }); - }, - }, - stop_action: { - name: 'Stop All', - options: [], - callback: async (event) => { - self.sendToWebSocket('stop-action', {}); - }, - } - }) + self.setActionDefinitions({ + pad_playback_action: { + name: 'Pad Playback', + options: [ + { + id: 'type', + type: 'dropdown', + choices: [ + { id: 'NAME', label: 'Name' }, + { id: 'NUMBER', label: 'Number' }, + ], + label: 'Type', + default: 'NUMBER', + }, + { + id: 'name', + type: 'textinput', + label: 'Pad Name', + default: '', + required: true, + isVisible: (options) => options.type === 'NAME', + }, + { + id: 'index', + type: 'number', + label: 'Pad Number', + default: '', + required: true, + isVisible: (options) => options.type === 'NUMBER', + }, + ], + callback: async (event) => { + if (event.options.type === 'NAME') { + const pad = self.currentProject.findPadByName(event.options.name) + if (!pad) { + self.log('warning', 'Cannot find a pad with name ' + event.options.name) + return + } + self.sendToWebSocket('cart-action', { + padId: pad.id, + }) + } else if (event.options.index) { + self.sendToWebSocket('cart-action', { + padIndex: event.options.index - 1, + }) + } + }, + }, + page_set_action: { + name: 'Page Set', + options: [ + { + id: 'page', + type: 'number', + label: 'Page Number', + default: '', + }, + ], + callback: async (event) => { + self.sendToWebSocket('page-action', { + page: event.options.page - 1, + }) + }, + }, + pad_navigate_action: { + name: 'Page Navigate', + options: [ + { + id: 'type', + type: 'dropdown', + choices: [ + { id: 'PREVIOUS', label: 'Previous' }, + { id: 'NEXT', label: 'Next' }, + ], + label: 'Action', + default: '', + }, + ], + callback: async (event) => { + self.sendToWebSocket('navigate-action', { + action: event.options.type, + }) + }, + }, + stop_action: { + name: 'Stop All', + options: [], + callback: async (event) => { + self.sendToWebSocket('stop-action', {}) + }, + }, + }) } diff --git a/feedbacks.js b/feedbacks.js index be4f8ee..582cb4a 100644 --- a/feedbacks.js +++ b/feedbacks.js @@ -1,92 +1,92 @@ -const {combineRgb} = require('@companion-module/base') +const { combineRgb } = require('@companion-module/base') module.exports = async function (self) { - self.setFeedbackDefinitions({ - pad_status: { - name: 'Pad Status', - type: 'advanced', - options: [ - { - id: 'type', - type: "dropdown", - choices: [ - { id: 'NAME', label: 'Name' }, - { id: 'NUMBER', label: 'Number' } - ], - label: 'Type', - default: 'NUMBER' - }, - { - id: 'name', - type: 'textinput', - label: 'Pad Name', - default: '', - required: true, - isVisible: (options) => options.type === 'NAME' - }, - { - id: 'index', - type: 'number', - label: 'Pad Number', - default: '', - required: true, - isVisible: (options) => options.type === 'NUMBER' - }, - ], - callback: (feedback, context) => { - let pad; - if (feedback.options.type === 'NAME') { - self.log('debug', `Update feedback for pad name ${feedback.options.name}`); - pad = self.currentProject.findPadByName(feedback.options.name); - } else { - self.log('debug', `Update feedback for pad index ${feedback.options.index - 1}`); - pad = self.currentProject.findPadByIndexInCurrentPage(feedback.options.index - 1); - } - if (pad != null) { - self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`); - if (pad.status === 'PLAY') { - let design = pad.design.play ?? self.currentProject.getDesign().play; - return { - bgcolor: hexStringToNumber(design.low), - color: hexStringToNumber(design.font) - }; - } else { - let design = pad.design.normal ?? self.currentProject.getDesign().normal; - return { - bgcolor: hexStringToNumber(design.low), - color: hexStringToNumber(design.font) - }; - } - } else { - return { - bgcolor: combineRgb(0, 0, 0) - }; - } - }, - }, - page_active: { - name: 'Page Active', - type: 'boolean', - defaultStyle: { - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(255, 0, 0) - }, - options: [ - { - id: 'index', - type: 'number', - label: 'Page Number', - default: '', - required: true - }, - ], - callback: (feedback, context) => { - return self.currentProject.getCurrentPage() === feedback.options.index - 1; - }, - } - }) + self.setFeedbackDefinitions({ + pad_status: { + name: 'Pad Status', + type: 'advanced', + options: [ + { + id: 'type', + type: 'dropdown', + choices: [ + { id: 'NAME', label: 'Name' }, + { id: 'NUMBER', label: 'Number' }, + ], + label: 'Type', + default: 'NUMBER', + }, + { + id: 'name', + type: 'textinput', + label: 'Pad Name', + default: '', + required: true, + isVisible: (options) => options.type === 'NAME', + }, + { + id: 'index', + type: 'number', + label: 'Pad Number', + default: '', + required: true, + isVisible: (options) => options.type === 'NUMBER', + }, + ], + callback: (feedback, context) => { + let pad + if (feedback.options.type === 'NAME') { + self.log('debug', `Update feedback for pad name ${feedback.options.name}`) + pad = self.currentProject.findPadByName(feedback.options.name) + } else { + self.log('debug', `Update feedback for pad index ${feedback.options.index - 1}`) + pad = self.currentProject.findPadByIndexInCurrentPage(feedback.options.index - 1) + } + if (pad != null) { + self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`) + if (pad.status === 'PLAY') { + let design = pad.design.play ?? self.currentProject.getDesign().play + return { + bgcolor: hexStringToNumber(design.low), + color: hexStringToNumber(design.font), + } + } else { + let design = pad.design.normal ?? self.currentProject.getDesign().normal + return { + bgcolor: hexStringToNumber(design.low), + color: hexStringToNumber(design.font), + } + } + } else { + return { + bgcolor: combineRgb(0, 0, 0), + } + } + }, + }, + page_active: { + name: 'Page Active', + type: 'boolean', + defaultStyle: { + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(255, 0, 0), + }, + options: [ + { + id: 'index', + type: 'number', + label: 'Page Number', + default: '', + required: true, + }, + ], + callback: (feedback, context) => { + return self.currentProject.getCurrentPage() === feedback.options.index - 1 + }, + }, + }) } function hexStringToNumber(string) { - return parseInt(string.replace(/^#/, ''), 16) + return parseInt(string.replace(/^#/, ''), 16) } diff --git a/main.js b/main.js index e1132e9..942beb9 100644 --- a/main.js +++ b/main.js @@ -1,235 +1,242 @@ -const {InstanceBase, Regex, runEntrypoint, InstanceStatus, combineRgb} = require('@companion-module/base') +const { InstanceBase, Regex, runEntrypoint, InstanceStatus, combineRgb } = require('@companion-module/base') const UpgradeScripts = require('./upgrades') const UpdateActions = require('./actions') const UpdateFeedbacks = require('./feedbacks') const WebSocket = require('ws') -const ProjectUpdate = require("./receive/project_update"); -const Project = require("./project"); -const PadNameUpdate = require("./receive/pad_name_update"); -const PadStatusUpdate = require("./receive/pad_status_update"); -const CurrentPageUpdate = require("./receive/current_page_update"); -const CurrentPageRequest = require("./receive/current_page_request"); -const uuid = require('uuid'); -const presets = require('./presets'); +const ProjectUpdate = require('./receive/project_update') +const Project = require('./project') +const PadNameUpdate = require('./receive/pad_name_update') +const PadStatusUpdate = require('./receive/pad_status_update') +const CurrentPageUpdate = require('./receive/current_page_update') +const CurrentPageRequest = require('./receive/current_page_request') +const uuid = require('uuid') +const presets = require('./presets') class ModuleInstance extends InstanceBase { - isInitialized = false - // language=RegExp - wsRegex = '^wss?:\\/\\/([\\da-z.-]+)(:\\d{1,5})?(?:\\/(.*))?$' - - messageHandlers = { - 'project-current': new ProjectUpdate(), - 'pad-name-changed': new PadNameUpdate(), - 'pad-status-changed': new PadStatusUpdate(), - 'current-page-changed': new CurrentPageUpdate(), - 'current-page-request': new CurrentPageRequest() - }; - - currentProject = new Project({}); - - constructor(internal) { - super(internal) - } - - async init(config) { - this.config = config - - this.initWebSocket() - this.isInitialized = true - - this.updateActions() - await this.updateFeedbacks() - - this.setPresetDefinitions(presets()); - } - - // When module gets deleted - async destroy() { - this.isInitialized = false - if (this.reconnect_timer) { - clearTimeout(this.reconnect_timer) - this.reconnect_timer = null - } - if (this.ping_timer) { - clearTimeout(this.ping_timer) - this.ping_timer = null - } - if (this.ws) { - this.ws.close(1000) - delete this.ws - } - } - - async configUpdated(config) { - this.config = config - this.initWebSocket() - } - - // Return config fields for web config - getConfigFields() { - return [ - { - type: 'textinput', - id: 'host', - label: 'PlayWall IP', - default: '127.0.0.1', - width: 8, - regex: Regex.IP, - }, - { - type: 'textinput', - id: 'port', - label: 'PlayWall Port', - default: '9876', - width: 4, - regex: Regex.PORT, - }, - { - type: 'checkbox', - id: 'debug_messages', - label: 'Debug messages', - tooltip: 'Log incomming and outcomming messages', - width: 6, - }, - { - type: 'checkbox', - id: 'reconnect', - label: 'Reconnect', - tooltip: 'Reconnect on WebSocket error (after 5 secs)', - width: 6, - default: true, - }, - ] - } - - updateActions() { - UpdateActions(this) - } - - async updateFeedbacks() { - await UpdateFeedbacks(this) - } - - // Websocket handling - - maybeReconnect() { - if (this.isInitialized && this.config.reconnect) { - if (this.reconnect_timer) { - clearTimeout(this.reconnect_timer) - } - this.reconnect_timer = setTimeout(() => { - this.initWebSocket() - }, 1000) - } - } - - startPingTrigger() { - if (this.isInitialized) { - if (this.ping_timer) { - clearTimeout(this.ping_timer) - } - this.log('debug', "Start Ping Timer"); - this.ping_timer = setInterval(() => { - this.sendToWebSocket('ping', {}); - }, 60 * 1000) - } - } - - initWebSocket() { - if (this.reconnect_timer) { - clearTimeout(this.reconnect_timer) - this.reconnect_timer = null - } - if (this.ping_timer) { - clearTimeout(this.ping_timer) - this.ping_timer = null - } - - if (this.config.host == null || this.config.port == null) { - this.log('debug', `PlayWall host '${this.config.host}' or port '${this.config.port}' is invalid`); - this.updateStatus(InstanceStatus.BadConfig, `PlayWall host '${this.config.host}' or port '${this.config.port}' is invalid`) - return - } - const url = `ws://${this.config.host}:${this.config.port}/api` - if (!url || url.match(new RegExp(this.wsRegex)) === null) { - this.updateStatus(InstanceStatus.BadConfig, `WS URL is not defined or invalid`) - return - } - - this.updateStatus(InstanceStatus.Connecting) - - if (this.ws) { - this.ws.close(1000) - delete this.ws - } - - this.ws = new WebSocket(url) - - this.ws.on('open', () => { - this.updateStatus(InstanceStatus.Ok) - this.log('debug', `Connection opened`) - this.startPingTrigger(); - - this.sendToWebSocket('project-current', {}); - }) - this.ws.on('close', (code) => { - this.log('debug', `Connection closed with code ${code}`) - this.updateStatus(InstanceStatus.Disconnected, `Connection closed with code ${code}`) - this.maybeReconnect(); - }) - - this.ws.on('message', this.messageReceivedFromWebSocket.bind(this)) - - this.ws.on('error', (data) => { - this.log('error', `WebSocket error: ${data}`) - }) - } - - sendToWebSocket(type, payload) { - this.ws.send(JSON.stringify({ - 'type': type, - 'messageId': uuid.v4(), - 'payload': payload - })); - } - - messageReceivedFromWebSocket(data) { - if (this.config.debug_messages) { - this.log('debug', `Message received: ${data}`) - } - - const message = JSON.parse(data) - if (message.type != null) { - if (this.messageHandlers[message.type] != null) { - this.messageHandlers[message.type].handleMessage(this, message) - } else { - this.log('debug', `Cannot handle incoming message of type ${message.type}`) - } - } else if (message.updateType != null) { - if (this.messageHandlers[message.updateType] != null) { - this.messageHandlers[message.updateType].handleMessage(this, message) - } else { - this.log('debug', `Cannot handle incoming message of updateType ${message.updateType}`) - } - } else { - this.log('debug', `Cannot handle incoming message ${data}`) - } - } - - updateVariables() { - this.setVariableDefinitions([...Array(this.currentProject.getPadCount()).keys()].map(index => { - return {variableId: `pad-${index}`, name: `Pad Index ${index + 1}`} - })) - } - - updateVariablesForCurrentPage() { - let pads = this.currentProject.getAllPadsOfCurrentPage(); - for (let i in pads) { - let pad = pads[i]; - this.log('debug', `Update variable 'pad-${pad.position}'`); - this.setVariableValues({[`pad-${pad.position}`]: pad.name}); - } - } + isInitialized = false + // language=RegExp + wsRegex = '^wss?:\\/\\/([\\da-z.-]+)(:\\d{1,5})?(?:\\/(.*))?$' + + messageHandlers = { + 'project-current': new ProjectUpdate(), + 'pad-name-changed': new PadNameUpdate(), + 'pad-status-changed': new PadStatusUpdate(), + 'current-page-changed': new CurrentPageUpdate(), + 'current-page-request': new CurrentPageRequest(), + } + + currentProject = new Project({}) + + constructor(internal) { + super(internal) + } + + async init(config) { + this.config = config + + this.initWebSocket() + this.isInitialized = true + + this.updateActions() + await this.updateFeedbacks() + + this.setPresetDefinitions(presets()) + } + + // When module gets deleted + async destroy() { + this.isInitialized = false + if (this.reconnect_timer) { + clearTimeout(this.reconnect_timer) + this.reconnect_timer = null + } + if (this.ping_timer) { + clearTimeout(this.ping_timer) + this.ping_timer = null + } + if (this.ws) { + this.ws.close(1000) + delete this.ws + } + } + + async configUpdated(config) { + this.config = config + this.initWebSocket() + } + + // Return config fields for web config + getConfigFields() { + return [ + { + type: 'textinput', + id: 'host', + label: 'PlayWall IP', + default: '127.0.0.1', + width: 8, + regex: Regex.IP, + }, + { + type: 'textinput', + id: 'port', + label: 'PlayWall Port', + default: '9876', + width: 4, + regex: Regex.PORT, + }, + { + type: 'checkbox', + id: 'debug_messages', + label: 'Debug messages', + tooltip: 'Log incomming and outcomming messages', + width: 6, + }, + { + type: 'checkbox', + id: 'reconnect', + label: 'Reconnect', + tooltip: 'Reconnect on WebSocket error (after 5 secs)', + width: 6, + default: true, + }, + ] + } + + updateActions() { + UpdateActions(this) + } + + async updateFeedbacks() { + await UpdateFeedbacks(this) + } + + // Websocket handling + + maybeReconnect() { + if (this.isInitialized && this.config.reconnect) { + if (this.reconnect_timer) { + clearTimeout(this.reconnect_timer) + } + this.reconnect_timer = setTimeout(() => { + this.initWebSocket() + }, 1000) + } + } + + startPingTrigger() { + if (this.isInitialized) { + if (this.ping_timer) { + clearTimeout(this.ping_timer) + } + this.log('debug', 'Start Ping Timer') + this.ping_timer = setInterval(() => { + this.sendToWebSocket('ping', {}) + }, 60 * 1000) + } + } + + initWebSocket() { + if (this.reconnect_timer) { + clearTimeout(this.reconnect_timer) + this.reconnect_timer = null + } + if (this.ping_timer) { + clearTimeout(this.ping_timer) + this.ping_timer = null + } + + if (this.config.host == null || this.config.port == null) { + this.log('debug', `PlayWall host '${this.config.host}' or port '${this.config.port}' is invalid`) + this.updateStatus( + InstanceStatus.BadConfig, + `PlayWall host '${this.config.host}' or port '${this.config.port}' is invalid` + ) + return + } + const url = `ws://${this.config.host}:${this.config.port}/api` + if (!url || url.match(new RegExp(this.wsRegex)) === null) { + this.updateStatus(InstanceStatus.BadConfig, `WS URL is not defined or invalid`) + return + } + + this.updateStatus(InstanceStatus.Connecting) + + if (this.ws) { + this.ws.close(1000) + delete this.ws + } + + this.ws = new WebSocket(url) + + this.ws.on('open', () => { + this.updateStatus(InstanceStatus.Ok) + this.log('debug', `Connection opened`) + this.startPingTrigger() + + this.sendToWebSocket('project-current', {}) + }) + this.ws.on('close', (code) => { + this.log('debug', `Connection closed with code ${code}`) + this.updateStatus(InstanceStatus.Disconnected, `Connection closed with code ${code}`) + this.maybeReconnect() + }) + + this.ws.on('message', this.messageReceivedFromWebSocket.bind(this)) + + this.ws.on('error', (data) => { + this.log('error', `WebSocket error: ${data}`) + }) + } + + sendToWebSocket(type, payload) { + this.ws.send( + JSON.stringify({ + type: type, + messageId: uuid.v4(), + payload: payload, + }) + ) + } + + messageReceivedFromWebSocket(data) { + if (this.config.debug_messages) { + this.log('debug', `Message received: ${data}`) + } + + const message = JSON.parse(data) + if (message.type != null) { + if (this.messageHandlers[message.type] != null) { + this.messageHandlers[message.type].handleMessage(this, message) + } else { + this.log('debug', `Cannot handle incoming message of type ${message.type}`) + } + } else if (message.updateType != null) { + if (this.messageHandlers[message.updateType] != null) { + this.messageHandlers[message.updateType].handleMessage(this, message) + } else { + this.log('debug', `Cannot handle incoming message of updateType ${message.updateType}`) + } + } else { + this.log('debug', `Cannot handle incoming message ${data}`) + } + } + + updateVariables() { + this.setVariableDefinitions( + [...Array(this.currentProject.getPadCount()).keys()].map((index) => { + return { variableId: `pad-${index}`, name: `Pad Index ${index + 1}` } + }) + ) + } + + updateVariablesForCurrentPage() { + let pads = this.currentProject.getAllPadsOfCurrentPage() + for (let i in pads) { + let pad = pads[i] + this.log('debug', `Update variable 'pad-${pad.position}'`) + this.setVariableValues({ [`pad-${pad.position}`]: pad.name }) + } + } } runEntrypoint(ModuleInstance, UpgradeScripts) diff --git a/presets.js b/presets.js index 7298ea0..81b7711 100644 --- a/presets.js +++ b/presets.js @@ -1,136 +1,135 @@ -const {combineRgb} = require("@companion-module/base"); +const { combineRgb } = require('@companion-module/base') module.exports = function () { - let presets = {}; + let presets = {} - // Pad Playback - for (let i = 0; i < 100; i++) { - presets[`pad-playback-${i}`] = { - category: 'Pad Playback', - name: `pad-playback-${i}`, - type: 'button', - previewStyle: { - text: `Pad ${i + 1}`, - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), - }, - style: { - text: `$(PlayWall:pad-${i})`, - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), - }, - steps: [ - { - down: [ - { - actionId: 'pad_playback_action', - options: { - 'type': 'NUMBER', - 'index': i + 1 - } - } - ] - } - ], - feedbacks: [ - { - feedbackId: 'pad_status', - options: { - 'type': 'NUMBER', - 'index': i + 1 - } - } - ] - }; - } + // Pad Playback + for (let i = 0; i < 100; i++) { + presets[`pad-playback-${i}`] = { + category: 'Pad Playback', + name: `pad-playback-${i}`, + type: 'button', + previewStyle: { + text: `Pad ${i + 1}`, + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + style: { + text: `$(PlayWall:pad-${i})`, + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + steps: [ + { + down: [ + { + actionId: 'pad_playback_action', + options: { + type: 'NUMBER', + index: i + 1, + }, + }, + ], + }, + ], + feedbacks: [ + { + feedbackId: 'pad_status', + options: { + type: 'NUMBER', + index: i + 1, + }, + }, + ], + } + } - // Pages - for (let i = 0; i < 20; i++) { - presets[`page-set-${i}`] = { - category: 'Pad Set', - name: `page-set-${i}`, - type: 'button', - style: { - text: `Seite ${i + 1}`, - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), - }, - steps: [ - { - down: [ - { - actionId: 'page_set_action', - options: { - 'page': i + 1 - } - } - ] - } - ], - feedbacks: [ - { - feedbackId: 'page_active', - options: { - 'index': i + 1 - }, - style: { - bgcolor: combineRgb(255, 0, 0), - color: combineRgb(255, 255, 255), - } - } - ] - }; - } + // Pages + for (let i = 0; i < 20; i++) { + presets[`page-set-${i}`] = { + category: 'Pad Set', + name: `page-set-${i}`, + type: 'button', + style: { + text: `Seite ${i + 1}`, + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + steps: [ + { + down: [ + { + actionId: 'page_set_action', + options: { + page: i + 1, + }, + }, + ], + }, + ], + feedbacks: [ + { + feedbackId: 'page_active', + options: { + index: i + 1, + }, + style: { + bgcolor: combineRgb(255, 0, 0), + color: combineRgb(255, 255, 255), + }, + }, + ], + } + } - presets['pad-navigate-previous'] = { - category: 'Page Navigate', - name: 'pad-navigate-previous', - type: 'button', - style: { - text: 'Zurück', - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), - }, - steps: [ - { - down: [ - { - actionId: 'pad_navigate_action', - options: { - 'type': 'PREVIOUS' - } - } - ] - } - ] - }; - presets['pad-navigate-next'] = { - category: 'Page Navigate', - name: 'pad-navigate-next', - type: 'button', - style: { - text: 'Vor', - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), - }, - steps: [ - { - down: [ - { - actionId: 'pad_navigate_action', - options: { - 'type': 'NEXT' - } - } - ] - } - ] - } + presets['pad-navigate-previous'] = { + category: 'Page Navigate', + name: 'pad-navigate-previous', + type: 'button', + style: { + text: 'Zurück', + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + steps: [ + { + down: [ + { + actionId: 'pad_navigate_action', + options: { + type: 'PREVIOUS', + }, + }, + ], + }, + ], + } + presets['pad-navigate-next'] = { + category: 'Page Navigate', + name: 'pad-navigate-next', + type: 'button', + style: { + text: 'Vor', + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + steps: [ + { + down: [ + { + actionId: 'pad_navigate_action', + options: { + type: 'NEXT', + }, + }, + ], + }, + ], + } - - return presets; -}; \ No newline at end of file + return presets +} diff --git a/project.js b/project.js index bb3e2d7..bf2b74d 100644 --- a/project.js +++ b/project.js @@ -1,145 +1,145 @@ module.exports = class Project { - constructor(data) { - this.padCache = {} - this.currentPage = 0; + constructor(data) { + this.padCache = {} + this.currentPage = 0 - // Prefill with current project - if (data) { - this.data = data; - console.log('Create pad cache') - for (const pageId in data.pages) { - const page = data.pages[pageId] - for (const padId in page.pads) { - const pad = page.pads[padId]; - if (pad.name !== "") { - this.padCache[pad.name] = pad; - console.log(`Add pad "${pad.name}" to cache`) - } - } - } - } - } + // Prefill with current project + if (data) { + this.data = data + console.log('Create pad cache') + for (const pageId in data.pages) { + const page = data.pages[pageId] + for (const padId in page.pads) { + const pad = page.pads[padId] + if (pad.name !== '') { + this.padCache[pad.name] = pad + console.log(`Add pad "${pad.name}" to cache`) + } + } + } + } + } - /* + /* Page */ - /** - * - * @returns {number} - */ - getCurrentPage() { - return this.currentPage; - } + /** + * + * @returns {number} + */ + getCurrentPage() { + return this.currentPage + } - /** - * - * @param {number} newPage - */ - updateCurrentPage(newPage) { - this.currentPage = newPage; - } + /** + * + * @param {number} newPage + */ + updateCurrentPage(newPage) { + this.currentPage = newPage + } - /* + /* Pads */ - /** - * - * @returns {number} - */ - getPadCount() { - return this.data.settings.columns * this.data.settings.rows; - } + /** + * + * @returns {number} + */ + getPadCount() { + return this.data.settings.columns * this.data.settings.rows + } - /** - * - * @returns {*[]} - */ - getAllPadsOfCurrentPage() { - let pads = []; + /** + * + * @returns {*[]} + */ + getAllPadsOfCurrentPage() { + let pads = [] - for (const pageId in this.data.pages) { - const page = this.data.pages[pageId] - if (page.position === this.currentPage) { - for (const padId in page.pads) { - const pad = page.pads[padId]; - pads.push(pad); - } - } - } - return pads; - } + for (const pageId in this.data.pages) { + const page = this.data.pages[pageId] + if (page.position === this.currentPage) { + for (const padId in page.pads) { + const pad = page.pads[padId] + pads.push(pad) + } + } + } + return pads + } - /** - * - * @param {string} oldName - * @param {string} newName - */ - updatePadName(oldName, newName) { - this.padCache[newName] = this.padCache[oldName]; - delete this.padCache[oldName]; - } + /** + * + * @param {string} oldName + * @param {string} newName + */ + updatePadName(oldName, newName) { + this.padCache[newName] = this.padCache[oldName] + delete this.padCache[oldName] + } - /** - * - * @param {string} padId - * @param {string} newStatus - */ - updatePadStatus(padId, newStatus) { - const pad = this.findPadById(padId); - if (pad != null) { - pad.status = newStatus; - } - } + /** + * + * @param {string} padId + * @param {string} newStatus + */ + updatePadStatus(padId, newStatus) { + const pad = this.findPadById(padId) + if (pad != null) { + pad.status = newStatus + } + } - /** - * - * @param {string} name - * @returns {*} - */ - findPadByName(name) { - return this.padCache[name]; - } + /** + * + * @param {string} name + * @returns {*} + */ + findPadByName(name) { + return this.padCache[name] + } - /** - * - * @param {number} index - */ - findPadByIndexInCurrentPage(index) { - for (const pageId in this.data.pages) { - const page = this.data.pages[pageId] - if (page.position === this.currentPage) { - for (const padId in page.pads) { - const pad = page.pads[padId]; - if (pad.position === index) { - return pad; - } - } - } - } - return null; - } + /** + * + * @param {number} index + */ + findPadByIndexInCurrentPage(index) { + for (const pageId in this.data.pages) { + const page = this.data.pages[pageId] + if (page.position === this.currentPage) { + for (const padId in page.pads) { + const pad = page.pads[padId] + if (pad.position === index) { + return pad + } + } + } + } + return null + } - /** - * - * @param {string} padId - */ - findPadById(padId) { - for (const id in this.padCache) { - const pad = this.padCache[id]; - if (pad.id === padId) { - return pad - } - } - return null - } + /** + * + * @param {string} padId + */ + findPadById(padId) { + for (const id in this.padCache) { + const pad = this.padCache[id] + if (pad.id === padId) { + return pad + } + } + return null + } - /* + /* Design */ - getDesign() { - return this.data.design; - } -} \ No newline at end of file + getDesign() { + return this.data.design + } +} diff --git a/receive/current_page_request.js b/receive/current_page_request.js index e8a3a58..9cbeb9f 100644 --- a/receive/current_page_request.js +++ b/receive/current_page_request.js @@ -1,11 +1,10 @@ -const MessageExecutable = require("./message_executable"); +const MessageExecutable = require('./message_executable') module.exports = class CurrentPageRequest extends MessageExecutable { + handleMessage(plugin, message) { + plugin.currentProject.updateCurrentPage(message.page) + plugin.checkFeedbacks() - handleMessage(plugin, message) { - plugin.currentProject.updateCurrentPage(message.page); - plugin.checkFeedbacks(); - - plugin.updateVariablesForCurrentPage(); - } -} \ No newline at end of file + plugin.updateVariablesForCurrentPage() + } +} diff --git a/receive/current_page_update.js b/receive/current_page_update.js index abcfe42..34d849b 100644 --- a/receive/current_page_update.js +++ b/receive/current_page_update.js @@ -1,11 +1,10 @@ -const MessageExecutable = require("./message_executable"); +const MessageExecutable = require('./message_executable') module.exports = class CurrentPageUpdate extends MessageExecutable { + handleMessage(plugin, message) { + plugin.currentProject.updateCurrentPage(message.newPage) + plugin.checkFeedbacks() - handleMessage(plugin, message) { - plugin.currentProject.updateCurrentPage(message.newPage); - plugin.checkFeedbacks(); - - plugin.updateVariablesForCurrentPage(); - } -} \ No newline at end of file + plugin.updateVariablesForCurrentPage() + } +} diff --git a/receive/message_executable.js b/receive/message_executable.js index 5d0039f..f3fef19 100644 --- a/receive/message_executable.js +++ b/receive/message_executable.js @@ -1,10 +1,10 @@ module.exports = class MessageExecutable { - /** - * - * @param {ModuleInstance} plugin - * @param {Object} message - */ - handleMessage(plugin, message) { - // Abstract method - } -} \ No newline at end of file + /** + * + * @param {ModuleInstance} plugin + * @param {Object} message + */ + handleMessage(plugin, message) { + // Abstract method + } +} diff --git a/receive/pad_name_update.js b/receive/pad_name_update.js index 91f5f0f..658f90f 100644 --- a/receive/pad_name_update.js +++ b/receive/pad_name_update.js @@ -1,14 +1,13 @@ -const MessageExecutable = require("./message_executable"); +const MessageExecutable = require('./message_executable') module.exports = class PadNameUpdate extends MessageExecutable { + handleMessage(plugin, message) { + plugin.currentProject.updatePadName(message.oldValue, message.newValue) - handleMessage(plugin, message) { - plugin.currentProject.updatePadName(message.oldValue, message.newValue); - - let pad = plugin.currentProject.findPadById(message.pad); - if (pad.page === plugin.currentProject.getCurrentPage()) { - plugin.log('debug', `Update variable 'pad-${pad.position}'`); - plugin.setVariableValues({[`pad-${pad.position}`]: message.newValue}); - } - } -} \ No newline at end of file + let pad = plugin.currentProject.findPadById(message.pad) + if (pad.page === plugin.currentProject.getCurrentPage()) { + plugin.log('debug', `Update variable 'pad-${pad.position}'`) + plugin.setVariableValues({ [`pad-${pad.position}`]: message.newValue }) + } + } +} diff --git a/receive/pad_status_update.js b/receive/pad_status_update.js index 6a5b03c..2f788a5 100644 --- a/receive/pad_status_update.js +++ b/receive/pad_status_update.js @@ -1,11 +1,10 @@ -const MessageExecutable = require("./message_executable"); +const MessageExecutable = require('./message_executable') module.exports = class PadStatusUpdate extends MessageExecutable { - - handleMessage(plugin, message) { - plugin.currentProject.updatePadStatus(message.pad, message.status); - plugin.checkFeedbacks(); - } + handleMessage(plugin, message) { + plugin.currentProject.updatePadStatus(message.pad, message.status) + plugin.checkFeedbacks() + } } -// {"pad":"8b7ef494-d735-45f9-ab84-c95e299298a6","status":"PLAY","updateType":"pad-status-changed"} \ No newline at end of file +// {"pad":"8b7ef494-d735-45f9-ab84-c95e299298a6","status":"PLAY","updateType":"pad-status-changed"} diff --git a/receive/project_update.js b/receive/project_update.js index 167f605..fc5ce53 100644 --- a/receive/project_update.js +++ b/receive/project_update.js @@ -1,15 +1,14 @@ -const MessageExecutable = require("./message_executable"); -const Project = require("../project"); +const MessageExecutable = require('./message_executable') +const Project = require('../project') module.exports = class ProjectUpdate extends MessageExecutable { + handleMessage(plugin, message) { + plugin.currentProject = new Project(message) + plugin.sendToWebSocket('current-page-request', {}) - handleMessage(plugin, message) { - plugin.currentProject = new Project(message) - plugin.sendToWebSocket('current-page-request', {}); + plugin.checkFeedbacks() - plugin.checkFeedbacks(); - - plugin.updateVariables() - plugin.updateVariablesForCurrentPage(); - } -} \ No newline at end of file + plugin.updateVariables() + plugin.updateVariablesForCurrentPage() + } +} -- GitLab