contra-renderer/www/js/moves/turnAlone.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

37 lines
1.5 KiB
TypeScript

import { SemanticPosition } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName: Move["move"] = "turn alone";
class TurnAloneSingleVariant extends SingleVariantMoveInterpreter<TurnAlone, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
if (this.move.parameters.who !== "everyone" || this.move.beats !== 0) {
throw new Error("turn alone unsupported except for changing to new circle.");
}
return this.handleCircleMove(({ startPos }) => {
const which = startPos.which.swapUpAndDown();
const startAndEndPos: SemanticPosition = {
...startPos,
which,
facing: which.facingUpOrDown(),
setOffset: (startPos.setOffset ?? 0) + (startPos.which.isTop() ? +0.5 : -0.5),
}
return this.combine([{
beats: this.move.beats,
endPosition: startAndEndPos,
movementPattern: { kind: SemanticAnimationKind.StandStill },
}], startAndEndPos);
});
}
}
class TurnAlone extends MoveInterpreter<typeof moveName> {
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new TurnAloneSingleVariant(this, startingPos);
}
}
moveInterpreters.set(moveName, TurnAlone);