From 53235bbbf327e3e392a105b756b34ca546e4d984 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sun, 16 Jun 2019 10:00:50 +0200 Subject: [PATCH] script: add get(id) function --- CHANGELOG.md | 1 + src/client/app/widgets/inputs/script.js | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b01500a4..129ccdbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - improved canvas rendering speed on chrome v69 and above - widgets - modal: `scroll` option + - script: `get(id)` function added in `script`execution context ## 0.46.1 diff --git a/src/client/app/widgets/inputs/script.js b/src/client/app/widgets/inputs/script.js index 1d360dac..a7817bef 100644 --- a/src/client/app/widgets/inputs/script.js +++ b/src/client/app/widgets/inputs/script.js @@ -28,6 +28,7 @@ class Script extends Widget { '- `value`: the value received by the widget', '- `send(target, address, arg1, arg2, ...)`: function for sending osc messages (ignores the script\'s targets and the server\'s defaults unless `target` is `false`; ignores the script\'s `preArgs`)', '- `set(id, value)`: function for setting a widget\'s value', + '- `get(id)`: function for getting a widget\'s value', '', '* Note: `value` or `linkId` properties can be used to receive other widgets\' values. The `value` property must actually change to trigger the execution, where linked widgets via `linkId` can submit the same value over and over and trigger the execution', ]} @@ -59,6 +60,24 @@ class Script extends Widget { } + static scriptGet(id) { + + var widgets = widgetManager.getWidgetById(id) + + for (var i = widgets.length - 1; i >= 0; i--) { + + if (widget.getValue) { + + var v = widgets[i].getValue() + if (v !== undefined) return v + + } + + } + + } + + scriptSend(target, address, ...args) { var overrides = { @@ -73,13 +92,13 @@ class Script extends Widget { } - setValue(v, options={} ) { var context = { value: v, send: options.send ? this.scriptSend.bind(this) : ()=>{}, set: (id, value)=>{Script.scriptSet(id, value, options)}, + get: (id)=>{return Script.scriptGet(id)}, log: console.log } @@ -102,7 +121,8 @@ Script.parsersContexts.condition = { Script.parsersContexts.script = { value: '', send: ()=>{}, - set: ()=>{} + set: ()=>{}, + get: ()=>{} } Script.dynamicProps = Script.prototype.constructor.dynamicProps.concat(