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

46 lines
1.8 KiB
TypeScript

import { SemanticPosition, PositionKind } 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"] = "mad robin";
class MadRobinSingleVariant extends SingleVariantMoveInterpreter<MadRobin, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
if (this.move.parameters.circling !== 360) {
throw new Error("mad robin circling not exactly once is unsupported.");
}
return this.handleCircleMove(({ id, startPos }) => {
// Read who of mad robin to decide direction.
const madRobinClockwise: boolean = (this.findPairOpposite(this.move.parameters.who, id) !== null) === startPos.which.isOnLeftLookingAcross();
const startAndEndPos: SemanticPosition = {
kind: PositionKind.Circle,
which: startPos.which,
facing: startPos.which.facingAcross(),
setOffset: startPos.setOffset,
lineOffset: startPos.lineOffset,
}
return this.combine([{
beats: this.move.beats,
startPosition: startAndEndPos,
endPosition: startAndEndPos,
movementPattern: {
kind: SemanticAnimationKind.DoSiDo,
amount: madRobinClockwise ? this.move.parameters.circling : -this.move.parameters.circling,
around: startPos.which.leftRightSide(),
},
}]);
});
}
}
class MadRobin extends MoveInterpreter<typeof moveName> {
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new MadRobinSingleVariant(this, startingPos);
}
}
moveInterpreters.set(moveName, MadRobin);