Skip to content

Commit 8c26979

Browse files
committed
code review
1 parent 1ac02b5 commit 8c26979

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/GeneratedDancer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Thin p5 adapter: owns a p5.Graphics mid-layer and gives its 2D context
22
// to the external renderer. CommonJS to match the rest of dance-party.
33

4-
// Map of move IDs to move names.
4+
// Map of move IDs to move names. These values are used to fetch source animation JSON.
55
const movesById = {
66
0: 'rest',
77
1: 'clap_high',

src/p5.dance.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const WATCHED_RANGES = [0, 1, 2];
3232

3333
const SIZE = constants.SIZE;
3434
const FRAMES = constants.FRAMES;
35+
36+
// Scale factor make the generated dancer appear the same size as other dance sprites.
37+
// At 1.0 scale, the rendered frame takes up the entire canvas.
3538
const GENERATED_DANCER_SCALE = 0.75;
3639

3740
// NOTE: min and max are inclusive
@@ -325,9 +328,7 @@ module.exports = class DanceParty {
325328
backgroundEffect.reset();
326329
}
327330

328-
if (this.generatedDancer) {
329-
this.generatedDancer.setSource(null);
330-
}
331+
this.setGeneratedDancerMove('rest');
331332

332333
let foregroundEffect = this.getForegroundEffect();
333334
if (foregroundEffect && foregroundEffect.reset) {
@@ -794,10 +795,6 @@ module.exports = class DanceParty {
794795
if (!this.spriteExists_(sprite)) {
795796
return;
796797
}
797-
if (sprite.isGenDancer) {
798-
this.generatedDancer.setSource(move);
799-
return;
800-
}
801798
// Number of valid full length moves
802799
const {fullLengthMoveCount} = this.world;
803800
if (typeof move === 'number') {
@@ -809,12 +806,17 @@ module.exports = class DanceParty {
809806
}
810807
sprite.mirroring = dir;
811808
sprite.mirrorX(dir);
812-
sprite.changeAnimation('anim' + move);
813-
if (sprite.animation.looping) {
814-
sprite.looping_frame = 0;
809+
810+
if (sprite.isGenDancer) {
811+
this.setGeneratedDancerMove(move);
812+
} else {
813+
sprite.changeAnimation('anim' + move);
814+
if (sprite.animation.looping) {
815+
sprite.looping_frame = 0;
816+
}
817+
sprite.animation.looping = true;
815818
}
816819
sprite.sinceLastFrame = 0;
817-
sprite.animation.looping = true;
818820
sprite.current_move = move;
819821
sprite.alternatingMoveInfo = undefined;
820822
}

0 commit comments

Comments
 (0)