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

83 lines
2.9 KiB
TypeScript

import { HandConnection, HandTo, BalanceWeight } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName: Move["move"] = "pull by dancers";
class PullByDancersSingleVariant extends SingleVariantMoveInterpreter<PullByDancers, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
// TODO Might make sense to think of pull by as not a full swap?
// e.g., in Blue and Green Candles, it's treated as only getting to
// ShortLinesPosition.Middle* before doing an allemande.
return this.handlePairedMove(this.move.parameters.who, ({ startPos, around, withPos }) => {
const hand = this.move.parameters.hand ? Hand.Right : Hand.Left;
const balanceBeats = this.move.parameters.bal
? this.move.beats > 4
? this.move.beats - 4
: 2
: 0;
const balancePartBeats = balanceBeats / 2;
const pullBeats = this.move.beats - balanceBeats;
// TODO Adjust facing?
const startPosition = {
...startPos,
hands: new Map<Hand, HandConnection>([
[
hand,
{ hand, to: around === "Center" ? HandTo.DiagonalAcrossCircle : HandTo.DancerForward }
]])
};
const passBy: PartialLowLevelMove = {
beats: pullBeats,
endPosition: { ...withPos, facing: startPos.facing },
movementPattern: {
kind: SemanticAnimationKind.PassBy,
around,
side: hand,
withHands: true,
facing: "Start",
otherPath: "Swap",
}
};
if (this.move.parameters.bal) {
return this.combine([
{
beats: balancePartBeats,
endPosition: {
...startPosition,
balance: BalanceWeight.Forward,
},
movementPattern: {
kind: SemanticAnimationKind.Linear,
}
},
{
beats: balancePartBeats,
endPosition: {
...startPosition,
balance: BalanceWeight.Backward,
},
movementPattern: {
kind: SemanticAnimationKind.Linear,
}
},
passBy], startPosition);
} else {
return this.combine([passBy], startPosition);
}
});
}
}
class PullByDancers extends MoveInterpreter<typeof moveName> {
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new PullByDancersSingleVariant(this, startingPos);
}
}
moveInterpreters.set(moveName, PullByDancers);