-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfeedbacks.js
82 lines (69 loc) · 2.48 KB
/
feedbacks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module.exports = {
createFeedbackFromAction: (instance, action) => {
const { combineRgb } = require('@companion-module/base')
const paramFuncs = require('./paramFuncs.js')
const rcpNames = require('./rcpNames.json')
let newFeedback = JSON.parse(JSON.stringify(action)) // Clone the Action to a matching feedback
if (instance.colorCommands.includes(action.name)) {
newFeedback.type = 'advanced' // Old feedback style
newFeedback.options.pop()
} else {
newFeedback.type = 'boolean' // New feedback style
if (newFeedback.options.length > 0) {
let lastOptions = newFeedback.options[newFeedback.options.length - 1]
if (lastOptions.label == 'State') {
lastOptions.choices.pop() // Get rid of the Toggle setting for Feedbacks
lastOptions.default = 1 // Don't select Toggle if there's no Toggle!
}
if (lastOptions.label == 'Relative') {
newFeedback.options.pop() // Get rid of Relative checkbox for feedback
}
}
newFeedback.options.push({
type: 'checkbox',
label: 'Auto-Create Variable',
id: 'createVariable',
default: false,
})
}
newFeedback.defaultStyle = {
color: combineRgb(0, 0, 0),
bgcolor: combineRgb(255, 0, 0),
}
let valOptionIdx = newFeedback.options.findIndex((opt) => opt.id == 'Val')
if (valOptionIdx > -1) {
newFeedback.options[valOptionIdx].isVisible = (options) => !options.createVariable
}
newFeedback.callback = async (feedback, context) => {
const varFuncs = require('./variables.js')
let rcpCmd = paramFuncs.findRcpCmd(feedback.feedbackId)
if (rcpCmd === undefined) return
let options = await paramFuncs.parseOptions(context, feedback.options)
if (options == undefined) return
let fb = options
fb.Address = rcpCmd.Address
fb.Val = await paramFuncs.parseVal(context, fb)
let data = instance.getFromDataStore(fb)
if (data == undefined) return
fb.X = feedback.options.X
fb.Y = feedback.options.Y
varFuncs.fbCreatesVar(instance, fb, data) // Are we creating and/or updating a variable?
// if (options && data == options.Val) {
if (fb.Val == data) {
return true
}
let rcpName = rcpCmd.Address.slice(rcpCmd.Address.indexOf('/') + 1) // String after "MIXER:Current/"
if (instance.colorCommands.includes(rcpName)) {
let retOptions = {}
let c = rcpNames.chColorRGB[data]
if (c != undefined) {
retOptions.color = c.color
retOptions.bgcolor = c.bgcolor
}
return retOptions
}
return false
}
return newFeedback
},
}