Skip to content

Commit

Permalink
Alternate calling pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
breville committed Sep 18, 2023
1 parent 60d6538 commit 15e6e8c
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/p5.dance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,28 +1121,26 @@ module.exports = class DanceParty {
}

// Called when executing the AI block.
ai(value) {
async ai(value) {
console.log('AI:', value);

// Call the main repo's doAI function which will transform this
// block's value into a useful response.
this.doAi(value)
.then(response => response.json())
.then(json => {
const params = JSON.parse(json.content);
console.log('handle AI:', params);

this.setBackgroundEffect(
params.backgroundEffect,
params.backgroundColor
);
const response = await this.doAi(value);

this.setForegroundEffect(params.foregroundEffect);
const params = JSON.parse(response);
console.log('handle AI:', params);

if (params.setDancer) {
this.makeNewDanceSprite('MOOSE', 'harold', null);
}
});
this.setBackgroundEffect(
params.backgroundEffect,
params.backgroundColor
);

this.setForegroundEffect(params.foregroundEffect);

if (params.setDancer) {
this.makeNewDanceSprite('MOOSE', 'harold', null);
}
}

// Music Helpers
Expand Down

0 comments on commit 15e6e8c

Please sign in to comment.