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

45 lines
1.7 KiB
TypeScript

import { BalanceWeight } from "../interpreterCommon.js";
import { SemanticAnimationKind } from "../lowLevelMove.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
class BalanceSingleVariant extends SingleVariantMoveInterpreter<Balance, "balance"> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
return this.handleMove(({ startPos }) => {
// TODO Use who to determine facing?
// TODO Could be left to right, not back and forth?
// TODO How to determine hand... by next move, I guess?
return this.combine([
{
beats: this.moveInterpreter.forwardBeats,
endPosition: { ...startPos, balance: BalanceWeight.Forward },
movementPattern: { kind: SemanticAnimationKind.Linear },
},
{
beats: this.moveInterpreter.backwardBeats,
endPosition: { ...startPos, balance: BalanceWeight.Backward },
movementPattern: { kind: SemanticAnimationKind.Linear },
},
], startPos);
});
}
}
class Balance extends MoveInterpreter<"balance"> {
public readonly forwardBeats: number;
public readonly backwardBeats: number;
constructor(args: MoveInterpreterCtorArgs<"balance">) {
super(args);
this.forwardBeats = this.move.beats / 2;
this.backwardBeats = this.move.beats - this.forwardBeats;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new BalanceSingleVariant(this, startingPos);
}
}
moveInterpreters.set("balance", Balance);