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

59 lines
2.3 KiB
TypeScript

import { Facing, SemanticPosition } from "../interpreterCommon.js";
import { SemanticAnimationKind, LowLevelMove } from "../lowLevelMove.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
import { balanceCircleInAndOut } from "./balanceTheRing.js";
class PetronellaSingleVariant extends SingleVariantMoveInterpreter<Petronella, "petronella"> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
// TODO These should be actual parameters, not parsing the notes...
const rightShoulder: boolean = !(this.move.note?.includes('left') ?? false);
const newCircle: boolean = this.move.note?.includes('end facing') ?? this.move.progression;
return this.handleCircleMove(({ startPos }) => {
let finalPosition = {
...startPos,
facing: Facing.CenterOfCircle,
which: startPos.which.circleRight(rightShoulder ? 1 : -1),
hands: undefined,
};
if (newCircle) {
finalPosition = {
...finalPosition,
which: finalPosition.which.swapUpAndDown(),
setOffset: (finalPosition.setOffset ?? 0) + (finalPosition.which.isTop() ? -0.5 : +0.5),
}
}
const spin: ((prevEnd: SemanticPosition) => PartialLowLevelMove) = prevEnd => ({
beats: this.move.beats - (this.move.parameters.bal ? 4 : 0),
startPosition: {
...prevEnd,
facing: Facing.CenterOfCircle,
hands: undefined,
},
endPosition: finalPosition,
movementPattern: {
kind: SemanticAnimationKind.Linear,
minRotation: rightShoulder ? 180 : -180,
handsDuring: "None",
},
});
if (this.move.parameters.bal) {
const balance: LowLevelMove[] = balanceCircleInAndOut(this.move, startPos);
return PetronellaSingleVariant.append([...balance], spin);
} else {
return this.combine([spin]);
}
});
}
}
class Petronella extends MoveInterpreter<"petronella"> {
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new PetronellaSingleVariant(this, startingPos);
}
}
moveInterpreters.set("petronella", Petronella);