From 3b2008275dc5314f6f6069b312148a79f561d9f3 Mon Sep 17 00:00:00 2001
From: tobias <thinkdifferent055@gmail.com>
Date: Fri, 29 Sep 2023 16:06:15 +0200
Subject: [PATCH] #187 - Use pad colors for feedback

---
 feedbacks.js              | 62 +++++++++++++++++++++++----------------
 receive/project_update.js |  1 +
 2 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/feedbacks.js b/feedbacks.js
index 7fb6e32..531f879 100644
--- a/feedbacks.js
+++ b/feedbacks.js
@@ -1,33 +1,45 @@
-const { combineRgb } = require('@companion-module/base')
+const {combineRgb} = require('@companion-module/base')
 
 module.exports = async function (self) {
-	self.setFeedbackDefinitions({
-		PadStatus: {
-			name: 'Pad Status',
-			type: 'boolean',
-			label: 'Pad Status',
-			defaultStyle: {
-				bgcolor: combineRgb(255, 0, 0),
-				color: combineRgb(0, 0, 0),
-			},
-			options: [
-				{
-					id: 'name',
-					type: 'textinput',
-					label: 'Pad Name',
-					default: '',
-				},
-			],
-			callback: (feedback, context) => {
+    self.setFeedbackDefinitions({
+        PadStatus: {
+            name: 'Pad Status',
+            type: 'advanced',
+            label: 'Pad Status',
+            options: [
+                {
+                    id: 'name',
+                    type: 'textinput',
+                    label: 'Pad Name',
+                    default: '',
+                },
+            ],
+            callback: (feedback, context) => {
                 self.log('debug', `Update feedback for pad name ${feedback.options.name}`);
-				const pad = self.currentProject.findPadByName(feedback.options.name);
+                const pad = self.currentProject.findPadByName(feedback.options.name);
                 if (pad != null) {
                     self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`);
-                    return pad.status === 'PLAY';
+                    if (pad.status === 'PLAY') {
+                        return {
+                            bgcolor: hexStringToNumber(pad.design.play.hi),
+                            color: hexStringToNumber(pad.design.play.font)
+                        };
+                    } else {
+                        return {
+                            bgcolor: hexStringToNumber(pad.design.normal.hi),
+                            color: hexStringToNumber(pad.design.normal.font)
+                        };
+                    }
                 } else {
-                    return false;
+                    return {
+                        bgcolor: combineRgb(0, 0, 0)
+                    };
                 }
-			},
-		},
-	})
+            },
+        },
+    })
+}
+
+function hexStringToNumber(string) {
+    return parseInt(string.replace(/^#/, ''), 16)
 }
diff --git a/receive/project_update.js b/receive/project_update.js
index 80a9ebe..3520055 100644
--- a/receive/project_update.js
+++ b/receive/project_update.js
@@ -5,5 +5,6 @@ module.exports = class ProjectUpdate extends MessageExecutable {
 
     handleMessage(plugin, message) {
         plugin.currentProject = new Project(message)
+        plugin.checkFeedbacks();
     }
 }
\ No newline at end of file
-- 
GitLab