diff --git a/src/api.js b/src/api.js index 1cfdf13d..eff7e224 100644 --- a/src/api.js +++ b/src/api.js @@ -149,8 +149,11 @@ module.exports = class DanceAPI { changePropEachBy: (group, property, val) => { return nativeAPI.changePropEachBy(group, property, val); }, - ai: value => { - nativeAPI.ai(value); + ai: params => { + nativeAPI.ai(params); + }, + aiText: value => { + nativeAPI.aiText(value); }, }; } diff --git a/src/p5.dance.js b/src/p5.dance.js index 55fb13e1..059c2312 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -1119,7 +1119,25 @@ module.exports = class DanceParty { } // Called when executing the AI block. - async ai(value) { + ai(params) { + console.log('handle AI:', params); + + if (params) { + if (params.backgroundEffect && params.backgroundColor) { + this.setBackgroundEffect( + params.backgroundEffect, + params.backgroundColor + ); + } + + if (params.foregroundEffect) { + this.setForegroundEffect(params.foregroundEffect); + } + } + } + + // Called when executing the free-text AI block. + async aiText(value) { console.log('AI:', value); // Call the main repo's doAI function which will transform this @@ -1129,10 +1147,7 @@ module.exports = class DanceParty { const params = JSON.parse(response); console.log('handle AI:', params); - this.setBackgroundEffect( - params.backgroundEffect, - params.backgroundColor - ); + this.setBackgroundEffect(params.backgroundEffect, params.backgroundColor); this.setForegroundEffect(params.foregroundEffect);