From e7ac086839acdc138f872848d20717ed645651c4 Mon Sep 17 00:00:00 2001 From: breville Date: Fri, 22 Sep 2023 05:05:04 +0000 Subject: [PATCH 1/4] hoc2023: AI modal --- src/api.js | 5 ++++- src/p5.dance.js | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/api.js b/src/api.js index 1cfdf13d..26a14866 100644 --- a/src/api.js +++ b/src/api.js @@ -150,7 +150,10 @@ module.exports = class DanceAPI { return nativeAPI.changePropEachBy(group, property, val); }, ai: value => { - nativeAPI.ai(value); + nativeAPI.handleAi(value); + }, + aiText: value => { + nativeAPI.aiText(value); }, }; } diff --git a/src/p5.dance.js b/src/p5.dance.js index 55fb13e1..3ffcfc02 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -1118,8 +1118,23 @@ module.exports = class DanceParty { }, this); } + handleAi(params) { + console.log('handle AI:', params); + + this.setBackgroundEffect( + params.backgroundEffect, + params.backgroundColor + ); + + this.setForegroundEffect(params.foregroundEffect); + + if (params.setDancer) { + //this.makeNewDanceSprite('MOOSE', 'harold', null); + } + } + // Called when executing the AI block. - async ai(value) { + async aiText(value) { console.log('AI:', value); // Call the main repo's doAI function which will transform this From 7a2d509cf4747817626e95b984a600171a96f935 Mon Sep 17 00:00:00 2001 From: breville Date: Tue, 26 Sep 2023 03:14:56 +0000 Subject: [PATCH 2/4] Tidy up --- src/api.js | 4 ++-- src/p5.dance.js | 20 +++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/api.js b/src/api.js index 26a14866..eff7e224 100644 --- a/src/api.js +++ b/src/api.js @@ -149,8 +149,8 @@ module.exports = class DanceAPI { changePropEachBy: (group, property, val) => { return nativeAPI.changePropEachBy(group, property, val); }, - ai: value => { - nativeAPI.handleAi(value); + ai: params => { + nativeAPI.ai(params); }, aiText: value => { nativeAPI.aiText(value); diff --git a/src/p5.dance.js b/src/p5.dance.js index 3ffcfc02..a328dd37 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -1118,18 +1118,15 @@ module.exports = class DanceParty { }, this); } - handleAi(params) { + ai(params) { console.log('handle AI:', params); - this.setBackgroundEffect( - params.backgroundEffect, - params.backgroundColor - ); - - this.setForegroundEffect(params.foregroundEffect); + if (params?.backgroundEffect && params?.backgroundColor) { + this.setBackgroundEffect(params.backgroundEffect, params.backgroundColor); + } - if (params.setDancer) { - //this.makeNewDanceSprite('MOOSE', 'harold', null); + if (params?.foregroundEffect) { + this.setForegroundEffect(params.foregroundEffect); } } @@ -1144,10 +1141,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); From 8736e71b0fb453210d77e72668b391f2cc28153c Mon Sep 17 00:00:00 2001 From: breville Date: Tue, 26 Sep 2023 03:33:34 +0000 Subject: [PATCH 3/4] Try a different syntax --- src/p5.dance.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/p5.dance.js b/src/p5.dance.js index a328dd37..6c94c4fc 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -1121,12 +1121,17 @@ module.exports = class DanceParty { ai(params) { console.log('handle AI:', params); - if (params?.backgroundEffect && params?.backgroundColor) { - this.setBackgroundEffect(params.backgroundEffect, params.backgroundColor); - } + if (params) { + if (params.backgroundEffect && params.backgroundColor) { + this.setBackgroundEffect( + params.backgroundEffect, + params.backgroundColor + ); + } - if (params?.foregroundEffect) { - this.setForegroundEffect(params.foregroundEffect); + if (params.foregroundEffect) { + this.setForegroundEffect(params.foregroundEffect); + } } } From 729d1d6841e33f85e6bd4f14efaa4d17f78a4909 Mon Sep 17 00:00:00 2001 From: breville Date: Tue, 26 Sep 2023 06:42:57 +0000 Subject: [PATCH 4/4] Update comment --- src/p5.dance.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p5.dance.js b/src/p5.dance.js index 6c94c4fc..059c2312 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -1118,6 +1118,7 @@ module.exports = class DanceParty { }, this); } + // Called when executing the AI block. ai(params) { console.log('handle AI:', params); @@ -1135,7 +1136,7 @@ module.exports = class DanceParty { } } - // Called when executing the AI block. + // Called when executing the free-text AI block. async aiText(value) { console.log('AI:', value);