contra-renderer/www/js/moves/revolvingDoor.ts
Daniel Perelman 9fbf7d18ac [WIP] Refactor to split interpreter into one file per move.
Currently just copied over the existing code and applied the quick
fixes to get it to compile. Each move should be refactored to be handle
its parameters earlier where applicable. But variants support should
probably be added first so both refactors can happen together.
2023-10-15 05:25:06 -07:00

74 lines
2.7 KiB
TypeScript

import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName: Move["move"] = "revolving door";
class RevolvingDoorSingleVariant extends SingleVariantMoveInterpreter<RevolvingDoor, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
const byHand = this.move.parameters.hand ? Hand.Right : Hand.Left;
// TODO More parts? Or define an animation kind?
const waitBeats = 2;
const carryBeats = this.move.beats / 2;
const returnBeats = this.move.beats - carryBeats - waitBeats;
return this.handleCirclePairedMove(this.move.parameters.whom, ({ id, startPos }) => {
const isCarried = this.findPairOpposite(this.move.parameters.who, id) === null;
const startingPos = { ...startPos, hands: undefined };
// TODO animation here needs work.
if (isCarried) {
const endWhich = startPos.which.swapDiagonal();
return this.combine([
prevEnd => ({
beats: waitBeats,
endPosition: prevEnd,
movementPattern: { kind: SemanticAnimationKind.StandStill },
}),
{
beats: carryBeats,
endPosition: {
...startPos,
which: endWhich,
facing: endWhich.facingAcross(),
},
movementPattern: {
kind: SemanticAnimationKind.RotateAround,
minAmount: byHand === Hand.Right ? 180 : -180,
around: "Center",
byHand,
close: false,
},
},
prevEnd => ({
beats: returnBeats,
endPosition: prevEnd,
movementPattern: { kind: SemanticAnimationKind.StandStill },
}),
], startingPos);
} else {
return this.combine([
{
beats: this.move.beats,
endPosition: startPos,
movementPattern: {
kind: SemanticAnimationKind.RotateAround,
minAmount: byHand === Hand.Right ? 180 : -180,
around: "Center",
byHand,
close: true,
},
},
], startingPos);
}
});
}
}
class RevolvingDoor extends MoveInterpreter<typeof moveName> {
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new RevolvingDoorSingleVariant(this, startingPos);
}
}
moveInterpreters.set(moveName, RevolvingDoor);