import { HandConnection, HandTo, BalanceWeight, facingRequireAdjacent } from "../interpreterCommon.js"; import { SemanticAnimationKind } from "../lowLevelMove.js"; import { Hand } from "../rendererConstants.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; const moveName = "box the gnat"; class BoxTheGnatSingleVariant extends SingleVariantMoveInterpreter { moveAsLowLevelMoves(): LowLevelMovesForAllDancers { return this.handlePairedMove(this.move.parameters.who, ({ startPos, around, withPos }) => { if (startPos.hands && startPos.hands.get(Hand.Right) === undefined && startPos.hands.get(Hand.Left)?.hand === Hand.Left) { throw new Error(this.move.move + " shouldn't start with holding left hands. Something went wrong."); } if (startPos.balance && startPos.balance !== BalanceWeight.Backward) { throw new Error(this.move.move + " shouldn't start with balance weight " + startPos.balance); } const facing = facingRequireAdjacent(startPos, withPos, this.move.move); const startPosition = { ...startPos, hands: this.moveInterpreter.hands, facing }; if (around === "Center") { throw "TwirlSwap around center is unsupported."; } const twirl: PartialLowLevelMove = { beats: this.moveInterpreter.twirlBeats, endPosition: { ...withPos, balance: undefined }, movementPattern: { kind: SemanticAnimationKind.TwirlSwap, around, hand: this.moveInterpreter.hand, } }; if (this.move.parameters.bal) { return this.combine([ { beats: this.moveInterpreter.balancePartBeats, endPosition: { ...startPosition, balance: BalanceWeight.Forward, }, movementPattern: { kind: SemanticAnimationKind.Linear, } }, { beats: this.moveInterpreter.balancePartBeats, endPosition: { ...startPosition, balance: BalanceWeight.Backward, }, movementPattern: { kind: SemanticAnimationKind.Linear, } }, twirl], startPosition); } else { return this.combine([twirl], startPosition); } }); } } class BoxTheGnat extends MoveInterpreter { public readonly hand: Hand; public readonly hands: Map; public readonly balancePartBeats: number; public readonly twirlBeats: number; constructor(args: MoveInterpreterCtorArgs) { super(args); this.hand = this.move.parameters.hand ? Hand.Right : Hand.Left; this.hands = new Map([[this.hand, { hand: this.hand, to: HandTo.DancerForward }]]); const balanceBeats = this.move.parameters.bal ? this.move.beats > 4 ? this.move.beats - 4 : this.move.beats / 2 : 0; this.balancePartBeats = balanceBeats / 2; this.twirlBeats = this.move.beats - balanceBeats; } override allowStartingBalance(): boolean { return true; } buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { return new BoxTheGnatSingleVariant(this, startingPos); } } moveInterpreters.set(moveName, BoxTheGnat);