Compare commits

..

2 Commits

21 changed files with 569 additions and 1365 deletions

View File

@ -6,7 +6,7 @@ import { nameLibFigureParameters, Move, chooser_pairz } from "./libfigureMapper.
import { LowLevelMove, SemanticAnimation, SemanticAnimationKind, animateFromLowLevelMoves } from "./lowLevelMove.js"; import { LowLevelMove, SemanticAnimation, SemanticAnimationKind, animateFromLowLevelMoves } from "./lowLevelMove.js";
import { BalanceWeight, CirclePosition, CircleSide, CircleSideOrCenter, DancerDistance, Facing, HandConnection, HandTo, LongLines, PositionKind, SemanticPosition, ShortLinesPosition, StarGrip, handToDancerToSideInCircleFacingAcross, handsFourImproper, handsInCircle, handsInLine, handsInShortLine, oppositeFacing } from "./interpreterCommon.js"; import { BalanceWeight, CirclePosition, CircleSide, CircleSideOrCenter, DancerDistance, Facing, HandConnection, HandTo, LongLines, PositionKind, SemanticPosition, ShortLinesPosition, StarGrip, handToDancerToSideInCircleFacingAcross, handsFourImproper, handsInCircle, handsInLine, handsInShortLine, oppositeFacing } from "./interpreterCommon.js";
import { ContraDBDance } from "./danceLibrary.js"; import { ContraDBDance } from "./danceLibrary.js";
import { AllVariantsForMoveArgs, ErrorMoveInterpreter, LowLevelMovesForAllDancers, MoveAsLowLevelMovesArgs, SemanticPositionsForAllDancers, Variant, VariantCollection, errorMoveInterpreterCtor, moveInterpreters } from "./moves/_moveInterpreter.js"; import { errorMoveInterpreterCtor, moveInterpreters } from "./moves/_moveInterpreter.js";
// Import all individual move files. // Import all individual move files.
// ls [a-z]*.js | sed 's@.*@import "./moves/\0";@' // ls [a-z]*.js | sed 's@.*@import "./moves/\0";@'
@ -46,137 +46,54 @@ import "./moves/turnAlone.js";
import "./moves/upTheHall.js"; import "./moves/upTheHall.js";
// TODO Get rid of nextMove here once variants are actually supported by Swing. function moveAsLowLevelMoves({ move, nextMove, startingPos, numProgessions }: { move: Move; nextMove: Move; startingPos: Map<DancerIdentity, SemanticPosition>; numProgessions: number; }): Map<DancerIdentity, LowLevelMove[]> {
function allVariantsForMove({ move, nextMove, startingVariants, numProgessions }: { move: Move; nextMove: Move; startingVariants: AllVariantsForMoveArgs; numProgessions: number; }): VariantCollection {
const moveInterpreter = moveInterpreters.get(move.move) ?? errorMoveInterpreterCtor; const moveInterpreter = moveInterpreters.get(move.move) ?? errorMoveInterpreterCtor;
return new moveInterpreter({ move, nextMove, numProgessions }).allVariantsForMove(startingVariants); return new moveInterpreter({ move, nextMove, numProgessions }).moveAsLowLevelMoves({ startingPos });
} }
function danceAsLowLevelMoves(moves: Move[], startingPos: Map<DancerIdentity, SemanticPosition>): Map<DancerIdentity, LowLevelMove[]> {
function danceAsLowLevelMoves(moves: Move[], startingVariants: AllVariantsForMoveArgs): Map<DancerIdentity, LowLevelMove[]> { const res = new Map<DancerIdentity, LowLevelMove[]>([...startingPos.keys()].map(id => [id, []]));
let currentVariants = new Map<string, MoveAsLowLevelMovesArgs>(startingVariants); let currentPos = new Map<DancerIdentity, SemanticPosition>(startingPos);
let currentVariantMoves: Map<string, LowLevelMovesForAllDancers> = new Map<string, LowLevelMovesForAllDancers>(
[...startingVariants.keys()].map(name => [name, new Map<DancerIdentity, LowLevelMove[]>(DancerIdentity.all().map(id => [id, []]))]));
let numProgessions = 0; let numProgessions = 0;
for (let i = 0; i < moves.length; i++) { for (let i = 0; i < moves.length; i++) {
const move = moves[i]; const move = moves[i];
const nextMove = i === moves.length - 1 ? moves[0] : moves[i + 1]; const nextMove = i === moves.length - 1 ? moves[0] : moves[i + 1];
function updateVariants(newVariants: VariantCollection) {
let previousVariants = currentVariants;
let previousVariantMoves = currentVariantMoves;
try {
currentVariants = new Map<string, MoveAsLowLevelMovesArgs>();
currentVariantMoves = new Map<string, LowLevelMovesForAllDancers>();
variant: for (const [name, variant] of newVariants) {
const oldMoves = previousVariantMoves.get(variant.previousMoveVariant);
const oldPos = previousVariants.get(variant.previousMoveVariant);
if (!oldMoves || !oldPos) {
throw new Error("Referenced unknown previous variant: " + variant.previousMoveVariant);
}
const newMoves: LowLevelMovesForAllDancers = new Map<DancerIdentity, LowLevelMove[]>();
const newPositions = new Map<DancerIdentity, SemanticPosition>();
for (const [id, newMoveList] of variant.lowLevelMoves.entries()) {
const prevEnd = oldPos.startingPos.get(id)!;
const newStart = newMoveList[0].startPosition;
if ((prevEnd.setOffset ?? 0) != (newStart.setOffset ?? 0)
|| (prevEnd.lineOffset ?? 0) != (newStart.lineOffset ?? 0)
|| prevEnd.kind != newStart.kind
|| prevEnd.which != newStart.which
|| prevEnd.balance != newStart.balance
|| prevEnd.dancerDistance != newStart.dancerDistance) {
// TODO Should this be considered a bug?
// TODO Require more properties to match? facing? probably not hands.
//throw new Error("Moves start/end did not line up.");
continue variant;
}
newMoves.set(id, [...oldMoves.get(id)!, ...newMoveList]);
newPositions.set(id, newMoveList.at(-1)!.endPosition);
}
currentVariants.set(name, { startingPos: newPositions });
currentVariantMoves.set(name, newMoves);
}
} catch (ex) {
currentVariants = previousVariants;
currentVariantMoves = previousVariantMoves;
throw ex;
}
if (currentVariantMoves.size === 0) {
currentVariants = previousVariants;
currentVariantMoves = previousVariantMoves;
throw new Error("All variants were eliminated as possibilities.");
}
}
try { try {
if (i > 0 && move.beats === 0 && move.move === "slide along set") { if (i > 0 && move.beats === 0 && move.move === "slide along set") {
const slideLeft: boolean = move.parameters.slide; const slideLeft: boolean = move.parameters.slide;
for (const [name, currentPos] of currentVariants.entries()) { for (const [id, currPos] of currentPos.entries()) {
for (const [id, currPos] of currentPos.startingPos.entries()) { const slideAmount = (currPos.which.leftRightSide() === CircleSide.Left) === slideLeft ? +0.5 : -0.5;
const slideAmount = (currPos.which.leftRightSide() === CircleSide.Left) === slideLeft ? +0.5 : -0.5; const setOffset = (currPos.setOffset ?? 0) + slideAmount;
const setOffset = (currPos.setOffset ?? 0) + slideAmount; currentPos.set(id, { ...currPos, setOffset });
currentPos.startingPos.set(id, { ...currPos, setOffset });
const prevMove = currentVariantMoves.get(name)!.get(id)!.at(-1)!; const prevMove = res.get(id)!.at(-1)!;
prevMove.movementPattern.setSlideAmount = slideAmount; prevMove.movementPattern.setSlideAmount = slideAmount;
prevMove.endPosition.setOffset = setOffset; prevMove.endPosition.setOffset = setOffset;
}
} }
} else { } else {
const newMoves = allVariantsForMove({ move, nextMove, startingVariants: currentVariants, numProgessions }); const newMoves = moveAsLowLevelMoves({ move, nextMove, startingPos: currentPos, numProgessions });
if (newMoves.size === 0) { for (const [id, newMoveList] of newMoves.entries()) {
updateVariants(new ErrorMoveInterpreter({ move, nextMove, numProgessions }, res.get(id)!.push(...newMoveList);
"ERROR: " + move.move + " has no valid starting variants.").allVariantsForMove(currentVariants)); currentPos.set(id, newMoveList.at(-1)!.endPosition);
} else {
updateVariants(newMoves);
}
if (currentVariantMoves.size === 0) {
throw new Error("Variants selection somehow went down to zero?");
} }
} }
} }
catch (ex) { catch (ex) {
if (currentVariantMoves.size === 0) throw ex;
// catch exception so something can be displayed // catch exception so something can be displayed
const errorMessage: string = ex instanceof Error ? ex.message : ex; for (const [id, pos] of currentPos.entries()) {
const errorVariants = new ErrorMoveInterpreter({ move, nextMove, numProgessions }, errorMessage).allVariantsForMove(currentVariants); res.get(id)!.push({
updateVariants(errorVariants); beats: move.beats,
} startPosition: pos,
if (move.progression) numProgessions++; endPosition: pos,
} movementPattern: { kind: SemanticAnimationKind.StandStill },
move,
// If there's multiple variants, check if there's fewer that flow into the first move. startBeat: 0,
if (currentVariantMoves.size !== 1) { interpreterError: ex instanceof Error ? ex.message : ex,
let newMoves: VariantCollection | undefined; });
try {
newMoves = allVariantsForMove({ move: moves[0], nextMove: moves[1], startingVariants: currentVariants, numProgessions });
} catch {
newMoves = undefined;
}
if (newMoves) {
const firstMoveVariants = [...newMoves.values()].map(v => v.previousMoveVariant);
if (firstMoveVariants.length > 0) {
for (const variant of [...currentVariantMoves.keys()]) {
if (!firstMoveVariants.includes(variant)) {
currentVariantMoves.delete(variant);
}
}
} }
} }
} if (move.progression) numProgessions++;
const res = [...currentVariantMoves.values()].at(-1)!;
if (currentVariantMoves.size !== 1) {
res.get(DancerIdentity.OnesRobin)![0].interpreterError = "Expected exactly one variant. Found "
+ currentVariantMoves.size + ": " + [...currentVariantMoves.keys()].join(", ");
} }
try { try {
@ -184,20 +101,18 @@ function danceAsLowLevelMoves(moves: Move[], startingVariants: AllVariantsForMov
const progressionInSets = progression.y / setDistance; const progressionInSets = progression.y / setDistance;
// fixup end positions to match start of next move // fixup end positions to match start of next move
// TODO Handle progression.
for (const [id, lowLevelMoves] of res.entries()) { for (const [id, lowLevelMoves] of res.entries()) {
for (let i = 0; i < lowLevelMoves.length - 1; i++) { for (let i = 0; i < lowLevelMoves.length - 1; i++) {
if (!lowLevelMoves[i].endPosition) throw "endPosition is undefined"; if (!lowLevelMoves[i].endPosition) throw "endPosition is undefined";
lowLevelMoves[i].endPosition = lowLevelMoves[i + 1].startPosition; lowLevelMoves[i].endPosition = lowLevelMoves[i + 1].startPosition;
if (!lowLevelMoves[i].endPosition) throw "endPosition is undefined now"; if (!lowLevelMoves[i].endPosition) throw "endPosition is undefined now";
// TODO Exactly what is the StandStill fixup needed for? Can it be handled in other ways? Should it be rotation only?
/*
if (lowLevelMoves[i].movementPattern.kind === SemanticAnimationKind.StandStill) { if (lowLevelMoves[i].movementPattern.kind === SemanticAnimationKind.StandStill) {
lowLevelMoves[i].startPosition = lowLevelMoves[i].endPosition; lowLevelMoves[i].startPosition = lowLevelMoves[i].endPosition;
if (i > 0) { if (i > 0) {
lowLevelMoves[i - 1].endPosition = lowLevelMoves[i].startPosition; lowLevelMoves[i - 1].endPosition = lowLevelMoves[i].startPosition;
} }
} }
*/
} }
// If progression isn't detected properly, do nothing. // If progression isn't detected properly, do nothing.
if (progressionInSets === 0) { if (progressionInSets === 0) {
@ -219,44 +134,24 @@ function danceAsLowLevelMoves(moves: Move[], startingVariants: AllVariantsForMov
} }
} }
function improperShortWaves(slideTo: Hand) {
return new Map<DancerIdentity, SemanticPosition>([...handsFourImproper.entries()].map(
([id, pos]) => ([id, {
kind: PositionKind.ShortLines,
which: pos.which.toShortLines(slideTo),
facing: pos.which.facingUpOrDown(),
}])
));
}
function improperUnfoldToShortLines(center: CircleSide.Bottom | CircleSide.Top) {
return new Map<DancerIdentity, SemanticPosition>([...handsFourImproper.entries()].map(
([id, pos]) => ([id, {
kind: PositionKind.ShortLines,
which: pos.which.unfoldToShortLines(center),
facing: center === CircleSide.Top ? Facing.Down : Facing.Up,
}])
));
}
function improperLongWaves(facingOut: DanceRole) {
return new Map<DancerIdentity, SemanticPosition>([...handsFourImproper.entries()].map(
([id, pos]) => ([id, {
...pos,
facing: id.danceRole === facingOut ? pos.which.facingOut() : pos.which.facingAcross(),
hands: handsInLine({ wavy: true, which: pos.which, facing: undefined })
}])
));
}
function StartingPosForFormation(formation: common.StartFormation, dance?: ContraDBDance): Map<DancerIdentity, SemanticPosition> { function StartingPosForFormation(formation: common.StartFormation, dance?: ContraDBDance): Map<DancerIdentity, SemanticPosition> {
const preamble = dance?.preamble ?? ""; const preamble = dance?.preamble ?? "";
if (preamble.includes("Starts in short waves, right hands to neighbors")) { if (preamble.includes("Starts in short waves, right hands to neighbors")) {
return improperShortWaves(Hand.Left); return new Map<DancerIdentity, SemanticPosition>([...handsFourImproper.entries()].map(
([id, pos]) => ([id, {
kind: PositionKind.ShortLines,
which: pos.which.toShortLines(Hand.Left),
facing: pos.which.isTop() ? Facing.Down : Facing.Up,
}])
));
} else if (preamble.includes("face down the hall in lines of 4, 1s splitting the 2s")) { } else if (preamble.includes("face down the hall in lines of 4, 1s splitting the 2s")) {
return improperUnfoldToShortLines(CircleSide.Top); return new Map<DancerIdentity, SemanticPosition>([...handsFourImproper.entries()].map(
} else if (preamble.includes("Long waves, larks face out")) { ([id, pos]) => ([id, {
return improperLongWaves(DanceRole.Lark); kind: PositionKind.ShortLines,
which: pos.which.unfoldToShortLines(CircleSide.Top),
facing: Facing.Down,
}])
));
} }
switch (formation) { switch (formation) {
@ -303,27 +198,6 @@ function StartingPosForFormation(formation: common.StartFormation, dance?: Contr
} }
} }
function startingVariantsForFormation(formation: common.StartFormation, dance?: ContraDBDance) : AllVariantsForMoveArgs {
const defaultFormation = StartingPosForFormation(formation, dance);
if (formation !== "improper" || defaultFormation !== handsFourImproper) {
return new Map<string, MoveAsLowLevelMovesArgs>([
["Initial", { startingPos: defaultFormation }]
]);
} else {
// Handle various different starting position that all count as "improper" like short/long waves, etc.
return new Map<string, MoveAsLowLevelMovesArgs>([
["InitialCircle", { startingPos: handsFourImproper }],
["InitialShortWavesLeft", { startingPos: improperShortWaves(Hand.Left) }],
["InitialShortWavesRight", { startingPos: improperShortWaves(Hand.Right) }],
["InitialShortLinesDown", { startingPos: improperUnfoldToShortLines(CircleSide.Top) }],
["InitialShortLinesUp", { startingPos: improperUnfoldToShortLines(CircleSide.Bottom) }],
["InitialLongWavesLarksOut", { startingPos: improperLongWaves(DanceRole.Lark) }],
["InitialLongWavesRobinsOut", { startingPos: improperLongWaves(DanceRole.Robin) }],
]);
}
}
export let mappedDance: Move[]; export let mappedDance: Move[];
export let interpretedDance: Map<DancerIdentity, LowLevelMove[]>; export let interpretedDance: Map<DancerIdentity, LowLevelMove[]>;
@ -331,7 +205,7 @@ export let interpretedAnimation: animation.Animation;
export function loadDance(dance: ContraDBDance): animation.Animation { export function loadDance(dance: ContraDBDance): animation.Animation {
mappedDance = dance.figures.map(nameLibFigureParameters); mappedDance = dance.figures.map(nameLibFigureParameters);
interpretedDance = danceAsLowLevelMoves(mappedDance, startingVariantsForFormation(dance.start_type, dance)); interpretedDance = danceAsLowLevelMoves(mappedDance, StartingPosForFormation(dance.start_type, dance));
interpretedAnimation = animateFromLowLevelMoves(interpretedDance); interpretedAnimation = animateFromLowLevelMoves(interpretedDance);
return interpretedAnimation; return interpretedAnimation;

View File

@ -1,4 +1,4 @@
import { DanceRole, DancerIdentity, Rotation } from "./danceCommon.js"; import { DancerIdentity, Rotation } from "./danceCommon.js";
import { Hand } from "./rendererConstants.js"; import { Hand } from "./rendererConstants.js";
export enum PositionKind { export enum PositionKind {
@ -21,14 +21,6 @@ export enum CircleSide {
Right = "Right", Right = "Right",
} }
export type CircleSideOrCenter = CircleSide | "Center"; export type CircleSideOrCenter = CircleSide | "Center";
export function isLeftRightCircleSide(side: CircleSideOrCenter): side is CircleSide.Left | CircleSide.Right {
return side === CircleSide.Left || side === CircleSide.Right;
}
export function isTopBottomCircleSide(side: CircleSideOrCenter): side is CircleSide.Top | CircleSide.Bottom {
return side === CircleSide.Top || side === CircleSide.Bottom;
}
export class CirclePosition { export class CirclePosition {
public static readonly TopLeft = new CirclePosition(CirclePositionEnum.TopLeft); public static readonly TopLeft = new CirclePosition(CirclePositionEnum.TopLeft);
public static readonly BottomLeft = new CirclePosition(CirclePositionEnum.BottomLeft); public static readonly BottomLeft = new CirclePosition(CirclePositionEnum.BottomLeft);
@ -51,29 +43,6 @@ export class CirclePosition {
: CirclePosition.BottomRight; : CirclePosition.BottomRight;
} }
public static fromSwing(side: CircleSide, swingRole: DanceRole, facing: "In" | "Out" | "Across" | Facing.Up | Facing.Down) {
if (isLeftRightCircleSide(side)) {
if (facing === Facing.Up || facing === Facing.Down) {
throw new Error("Ending a swing in a circle on the left/right side facing up/down doesn't make sense.");
} else if (facing === "Across") {
facing = "In";
}
return this.fromSides(side,
(side === CircleSide.Left) !== (swingRole === DanceRole.Lark) !== (facing === "In") ? CircleSide.Bottom : CircleSide.Top);
} else {
if (facing === Facing.Up || facing === Facing.Down) {
facing = (facing === Facing.Up) === (side === CircleSide.Top) ? "Out" : "In";
} else if (facing === "Across") {
throw new Error("Ending a swing in a circle on the top/bottom side facing across doesn't make sense.");
}
return this.fromSides(
(side === CircleSide.Top) !== (swingRole === DanceRole.Lark) !== (facing === "In") ? CircleSide.Left : CircleSide.Right,
side);
}
}
private static enumValueToNumber(enumValue: CirclePositionEnum) : number { private static enumValueToNumber(enumValue: CirclePositionEnum) : number {
switch (enumValue) { switch (enumValue) {
case CirclePositionEnum.TopLeft: case CirclePositionEnum.TopLeft:
@ -136,14 +105,6 @@ export class CirclePosition {
][CirclePosition.enumValueToNumber(this.enumValue)]; ][CirclePosition.enumValueToNumber(this.enumValue)];
} }
public swapOnSide(side: CircleSide) : CirclePosition {
if (side === CircleSide.Bottom || side === CircleSide.Top) {
return this.swapAcross();
} else {
return this.swapUpAndDown();
}
}
public toShortLines(slideTo: Hand) : ShortLinesPosition { public toShortLines(slideTo: Hand) : ShortLinesPosition {
return slideTo === Hand.Left return slideTo === Hand.Left
? [ ? [
@ -212,28 +173,6 @@ export class CirclePosition {
return this.enumValue === CirclePositionEnum.TopLeft || this.enumValue === CirclePositionEnum.BottomRight; return this.enumValue === CirclePositionEnum.TopLeft || this.enumValue === CirclePositionEnum.BottomRight;
} }
public isOnLeft(around: CircleSide, facing: Facing.Down | Facing.Up | Facing.Left | Facing.Right | Facing.CenterOfCircle | "Out") {
if (facing === Facing.CenterOfCircle) {
facing = facingInAround(around);
} else if (facing === "Out") {
facing = oppositeFacing(facingInAround(around));
}
if (around === CircleSide.Bottom || around === CircleSide.Top) {
if (facing === Facing.Left || facing === Facing.Right) {
throw new Error("Cannot face " + facing + " and have a left/right side around " + around);
}
return (around === CircleSide.Bottom) !== (facing === Facing.Down) !== (this.isLeft());
} else {
if (facing === Facing.Up || facing === Facing.Down) {
throw new Error("Cannot face " + facing + " and have a left/right side around " + around);
}
return (around === CircleSide.Left) !== (facing === Facing.Right) !== (this.isTop());
}
}
public facingAcross() : Facing.Left | Facing.Right { public facingAcross() : Facing.Left | Facing.Right {
return this.isLeft() ? Facing.Right : Facing.Left; return this.isLeft() ? Facing.Right : Facing.Left;
} }
@ -269,25 +208,6 @@ export class ShortLinesPosition {
this.enumValue = enumValue; this.enumValue = enumValue;
} }
public static fromSide(side: CircleSide.Left | CircleSide.Right, which: "Far" | "Middle") {
if (side === CircleSide.Left) {
return which === "Far" ? ShortLinesPosition.FarLeft : ShortLinesPosition.MiddleLeft;
} else {
return which === "Far" ? ShortLinesPosition.FarRight : ShortLinesPosition.MiddleRight;
}
}
public static fromSwing(side: "Center" | CircleSide.Left | CircleSide.Right, swingRole: DanceRole, facing: Facing.Up | Facing.Down) {
if (side === "Center") {
return this.fromSide(
(swingRole === DanceRole.Lark) !== (facing === Facing.Down) ? CircleSide.Right : CircleSide.Left,
"Middle");
} else {
return this.fromSide(side,
(side === CircleSide.Left) !== (swingRole === DanceRole.Lark) !== (facing === Facing.Down) ? "Far" : "Middle");
}
}
private static enumValueToNumber(enumValue: ShortLinesPositionEnum) : number { private static enumValueToNumber(enumValue: ShortLinesPositionEnum) : number {
switch (enumValue) { switch (enumValue) {
case ShortLinesPositionEnum.FarLeft: case ShortLinesPositionEnum.FarLeft:
@ -343,25 +263,13 @@ export class ShortLinesPosition {
} }
public shift(dir: Hand, facing: Facing.Up | Facing.Down): ShortLinesPosition { public shift(dir: Hand, facing: Facing.Up | Facing.Down): ShortLinesPosition {
const { newPos, wrap } = this.shiftWithWrap(dir, facing);
if (wrap) {
throw new Error("Invalid shift: " + this + " facing " + facing + " to " + dir + ".");
}
return newPos;
}
public shiftWithWrap(dir: Hand, facing: Facing.Up | Facing.Down): { newPos: ShortLinesPosition, wrap?: -1 | 1 } {
const shift = (dir === Hand.Left) === (facing === Facing.Down) ? -1 : +1; const shift = (dir === Hand.Left) === (facing === Facing.Down) ? -1 : +1;
const newNum = ShortLinesPosition.enumValueToNumber(this.enumValue) + shift; const newNum = ShortLinesPosition.enumValueToNumber(this.enumValue) + shift;
const newPos = ShortLinesPosition.get(ShortLinesPosition.numberToEnumValue(newNum)) if (newNum < 0 || newNum > 3) {
if (newNum < 0) { throw new Error("Invalid shift: " + this + " facing " + facing + " to " + dir + ".");
return { newPos, wrap: -1 };
} else if (newNum > 3) {
return { newPos, wrap: +1 };
} else {
return { newPos };
} }
return ShortLinesPosition.get(ShortLinesPosition.numberToEnumValue(newNum));
} }
public isMiddle() : boolean { public isMiddle() : boolean {
@ -387,14 +295,6 @@ export class ShortLinesPosition {
return this.isLeft() === this.isMiddle() ? Facing.Left : Facing.Right; return this.isLeft() === this.isMiddle() ? Facing.Left : Facing.Right;
} }
public facingAcross() : Facing.Left | Facing.Right {
return this.isLeft() ? Facing.Right : Facing.Left;
}
public isToLeftOf(otherPos: ShortLinesPosition): boolean {
return this.enumValue < otherPos.enumValue;
}
public toString() : string { public toString() : string {
return this.enumValue.toString(); return this.enumValue.toString();
} }
@ -410,11 +310,7 @@ export enum Facing {
Left = "Left", Left = "Left",
Right = "Right", Right = "Right",
} }
export function oppositeFacing(facing: Facing.Up | Facing.Down) : Facing.Up | Facing.Down; export function oppositeFacing(facing: Facing.Up | Facing.Down | Facing.Left | Facing.Right | Facing.LeftInCircle | Facing.RightInCircle) {
export function oppositeFacing(facing: Facing.Left | Facing.Right) : Facing.Left | Facing.Right;
export function oppositeFacing(facing: Facing.LeftInCircle | Facing.RightInCircle) : Facing.LeftInCircle | Facing.RightInCircle;
export function oppositeFacing(facing: Facing.Up | Facing.Down | Facing.Left | Facing.Right) : Facing.Up | Facing.Down | Facing.Left | Facing.Right;
export function oppositeFacing(facing: Facing.Up | Facing.Down | Facing.Left | Facing.Right | Facing.LeftInCircle | Facing.RightInCircle) : Facing {
switch (facing) { switch (facing) {
case Facing.LeftInCircle: case Facing.LeftInCircle:
return Facing.RightInCircle; return Facing.RightInCircle;
@ -430,25 +326,6 @@ export function oppositeFacing(facing: Facing.Up | Facing.Down | Facing.Left | F
return Facing.Left; return Facing.Left;
} }
} }
export function isFacingUpOrDown(facing: Facing | "Across"): facing is Facing.Up | Facing.Down {
return facing === Facing.Up || facing === Facing.Down;
}
export function facingInAround(side: CircleSide) : Facing.Down | Facing.Up | Facing.Left | Facing.Right {
switch (side) {
case CircleSide.Bottom:
return Facing.Up;
break;
case CircleSide.Top:
return Facing.Down;
break;
case CircleSide.Left:
return Facing.Right;
break;
case CircleSide.Right:
return Facing.Left;
break;
}
}
export enum StarGrip { export enum StarGrip {
HandsAcross = "HandsAcross", HandsAcross = "HandsAcross",
@ -552,27 +429,24 @@ export const handsFourImproper: Map<DancerIdentity, SemanticPosition & { kind: P
}], }],
]); ]);
export function handsInLongLines(wavy: boolean) { export function handsInShortLine({ which, facing, wavy }: { which: ShortLinesPosition; facing: Facing.Up | Facing.Down; wavy: boolean; }): Map<Hand, HandConnection> {
return new Map<Hand, HandConnection>([ return which.isMiddle() ? new Map<Hand, HandConnection>([
[Hand.Left, { hand: wavy ? Hand.Right : Hand.Left, to: HandTo.DancerLeft }], [Hand.Left, { hand: wavy ? Hand.Right : Hand.Left, to: HandTo.DancerLeft }],
[Hand.Right, { hand: wavy ? Hand.Left : Hand.Right, to: HandTo.DancerRight }], [Hand.Right, { hand: wavy ? Hand.Left : Hand.Right, to: HandTo.DancerRight }],
]) : new Map<Hand, HandConnection>([
which.isLeft() === (facing === Facing.Up)
? [Hand.Left, { hand: wavy ? Hand.Right : Hand.Left, to: HandTo.DancerLeft }]
: [Hand.Right, { hand: wavy ? Hand.Left : Hand.Right, to: HandTo.DancerRight }]
]); ]);
} }
export function handsInShortLine({ which, facing, wavy }: { which: ShortLinesPosition; facing: Facing.Up | Facing.Down; wavy: boolean; }): Map<Hand, HandConnection> {
return which.isMiddle()
? handsInLongLines(wavy)
: new Map<Hand, HandConnection>([
which.isLeft() === (facing === Facing.Up)
? [Hand.Left, { hand: wavy ? Hand.Right : Hand.Left, to: HandTo.DancerLeft }]
: [Hand.Right, { hand: wavy ? Hand.Left : Hand.Right, to: HandTo.DancerRight }]
]);
}
export function handsInLine(args: { wavy: boolean, which: ShortLinesPosition | CirclePosition, facing?: Facing }) { export function handsInLine(args: { wavy: boolean, which: ShortLinesPosition | CirclePosition, facing?: Facing }) {
if (args.which instanceof ShortLinesPosition && (args.facing === Facing.Up || args.facing === Facing.Down)) { if (args.which instanceof ShortLinesPosition && (args.facing === Facing.Up || args.facing === Facing.Down)) {
return handsInShortLine({ wavy: args.wavy, which: args.which, facing: args.facing }); return handsInShortLine({ wavy: args.wavy, which: args.which, facing: args.facing });
} else { } else {
return handsInLongLines(args.wavy); return new Map<Hand, HandConnection>([
[Hand.Left, { hand: args.wavy ? Hand.Right : Hand.Left, to: HandTo.DancerLeft }],
[Hand.Right, { hand: args.wavy ? Hand.Left : Hand.Right, to: HandTo.DancerRight }],
]);
} }
} }
export function handToDancerToSideInCircleFacingAcross(which: CirclePosition): Map<Hand, HandConnection> { export function handToDancerToSideInCircleFacingAcross(which: CirclePosition): Map<Hand, HandConnection> {
@ -588,94 +462,4 @@ export function handToDancerToSideInCircleFacingUpOrDown(which: CirclePosition):
? [Hand.Right, { hand: Hand.Left, to: HandTo.DancerRight }] ? [Hand.Right, { hand: Hand.Left, to: HandTo.DancerRight }]
: [Hand.Left, { hand: Hand.Right, to: HandTo.DancerLeft }] : [Hand.Left, { hand: Hand.Right, to: HandTo.DancerLeft }]
]); ]);
}
export function facingAdjacent(pos: SemanticPosition, otherPos: SemanticPosition): Facing | undefined {
if (pos.kind !== otherPos.kind) {
return undefined;
}
if (pos.kind === PositionKind.ShortLines) {
if (otherPos.kind !== PositionKind.ShortLines) {
return undefined;
}
if ((pos.setOffset ?? 0) !== (otherPos.setOffset ?? 0)) {
return undefined;
}
if ((pos.lineOffset ?? 0) !== (otherPos.lineOffset ?? 0)) {
if (pos.which === ShortLinesPosition.FarLeft && otherPos.which === ShortLinesPosition.FarRight
&& ((pos.lineOffset ?? 0) - 1) === (otherPos.lineOffset ?? 0)) {
return Facing.Left;
} else if (pos.which === ShortLinesPosition.FarRight && otherPos.which === ShortLinesPosition.FarLeft
&& ((pos.lineOffset ?? 0) + 1) === (otherPos.lineOffset ?? 0)) {
return Facing.Right;
} else {
return undefined;
}
}
if (otherPos.which.isToLeftOf(pos.which)) {
return Facing.Left;
} else {
return Facing.Right;
}
} else if (pos.kind === PositionKind.Circle) {
if (otherPos.kind !== PositionKind.Circle) {
return undefined;
}
if ((pos.lineOffset ?? 0) !== (otherPos.lineOffset ?? 0)) {
// TODO
return undefined;
}
if ((pos.setOffset ?? 0) !== (otherPos.setOffset ?? 0)) {
// TODO
return undefined;
}
if (pos.which.leftRightSide() === otherPos.which.leftRightSide()) {
if (pos.which.topBottomSide() === otherPos.which.topBottomSide()) {
return undefined;
}
if ((pos.lineOffset ?? 0) !== (otherPos.lineOffset ?? 0)) {
return undefined;
}
if ((pos.setOffset ?? 0) === (otherPos.setOffset ?? 0)) {
return pos.which.facingUpOrDown();
} else if (((pos.setOffset ?? 0) + 1) === (otherPos.setOffset ?? 0) && pos.which.isTop()) {
return Facing.Up;
} else if (((pos.setOffset ?? 0) - 1) === (otherPos.setOffset ?? 0) && !pos.which.isTop()) {
return Facing.Down;
}
} else if (pos.which.topBottomSide() === otherPos.which.topBottomSide()) {
if ((pos.setOffset ?? 0) === (otherPos.setOffset ?? 0)) {
return undefined;
}
if ((pos.lineOffset ?? 0) !== (otherPos.lineOffset ?? 0)) {
return pos.which.facingAcross();
} else if (((pos.lineOffset ?? 0) + 1) === (otherPos.lineOffset ?? 0) && pos.which.isLeft()) {
return Facing.Left;
} else if (((pos.lineOffset ?? 0) - 1) === (otherPos.lineOffset ?? 0) && !pos.which.isLeft()) {
return Facing.Right;
}
} else {
// Opposite corners of circle.
return undefined;
}
} else {
throw new Error("Unexpected PositionKind: " + otherPos.kind);
}
}
export function facingRequireAdjacent(pos: SemanticPosition, otherPos: SemanticPosition, moveName: string): Facing {
const res = facingAdjacent(pos, otherPos);
if (!res) {
throw new Error("Cannot " + moveName + " when not adjacent to paired dancer.");
}
return res;
} }

View File

@ -34,7 +34,7 @@ type chooser_slice_return = "straight" | "diagonal" | "none";
type chooser_all_or_center_or_outsides = "all" | "center" | "outsides"; type chooser_all_or_center_or_outsides = "all" | "center" | "outsides";
type chooser_down_the_hall_ender = "turn-alone" | "turn-couple" | "circle" | "cozy" | "cloverleaf" | "thread-needle" | "right-high" | "sliding-doors" | ""; type chooser_down_the_hall_ender = "turn-alone" | "turn-couple" | "circle" | "cozy" | "cloverleaf" | "thread-needle" | "right-high" | "sliding-doors" | "";
type chooser_zig_zag_ender = "" | "ring" | "allemande"; type chooser_zig_zag_ender = "" | "ring" | "allemande";
type chooser_hey_length = "full" | "half" | "less than half" | "between half and full" | { dancer: chooser_pairz, time: 1 | 2}; type chooser_hey_length = "full" | "half" | "less than half" | "between half and full";
type chooser_swing_prefix = "none" | "balance" | "meltdown"; type chooser_swing_prefix = "none" | "balance" | "meltdown";
type chooser_dancers = "everyone" | "gentlespoon" | "gentlespoons" | "ladle" | "ladles" | "partners" | "neighbors" | "ones" | "twos" | "same roles" | "first corners" | "second corners" | "first gentlespoon" | "first ladle" | "second gentlespoon" | "second ladle" | "shadows"; type chooser_dancers = "everyone" | "gentlespoon" | "gentlespoons" | "ladle" | "ladles" | "partners" | "neighbors" | "ones" | "twos" | "same roles" | "first corners" | "second corners" | "first gentlespoon" | "first ladle" | "second gentlespoon" | "second ladle" | "shadows";
type chooser_pair = "gentlespoons" | "ladles" | "ones" | "twos" | "first corners" | "second corners"; type chooser_pair = "gentlespoons" | "ladles" | "ones" | "twos" | "first corners" | "second corners";
@ -410,20 +410,7 @@ export function nameLibFigureParameters(move: LibFigureMove): Move {
.map((v, i, a) => a.indexOf(v) === i && a.lastIndexOf(v) === i ? v : v + (a.slice(0, i).filter(el => el === v).length + 1)); .map((v, i, a) => a.indexOf(v) === i && a.lastIndexOf(v) === i ? v : v + (a.slice(0, i).filter(el => el === v).length + 1));
const parameters = {}; const parameters = {};
for (let i = 0; i < parameterNames.length; i++) { for (let i = 0; i < parameterNames.length; i++) {
if (parameterNames[i] === "until") { parameters[parameterNames[i]] = move.parameter_values[i];
// parse chooser_hey_length
const hey_length: string = move.parameter_values[i];
if (hey_length.includes('%%')) {
parameters[parameterNames[i]] = {
dancer: hey_length.slice(0, -3),
time: parseInt(hey_length.at(-1)!),
};
} else {
parameters[parameterNames[i]] = hey_length;
}
} else {
parameters[parameterNames[i]] = move.parameter_values[i];
}
} }
const beats: number = parameters["beats"]; const beats: number = parameters["beats"];
parameters["beats"] = undefined; parameters["beats"] = undefined;

View File

@ -77,8 +77,6 @@ export type SemanticAnimation = {
// If true, move in close while rotating. // If true, move in close while rotating.
close: boolean, close: boolean,
facing?: animation.RotationAnimationFacing,
} | { } | {
kind: SemanticAnimationKind.Swing, kind: SemanticAnimationKind.Swing,
@ -294,7 +292,7 @@ function SemanticToSetPosition(semantic: SemanticPosition): DancerSetPosition {
&& (semantic.balance === BalanceWeight.Backward || semantic.balance === BalanceWeight.Forward)) { && (semantic.balance === BalanceWeight.Backward || semantic.balance === BalanceWeight.Forward)) {
balanceOffset = { balanceOffset = {
x: 0, x: 0,
y: Math.sign(position.y) * ( y: position.y * (
semantic.balance === BalanceWeight.Forward semantic.balance === BalanceWeight.Forward
? -balanceAmount ? -balanceAmount
: balanceAmount) : balanceAmount)
@ -354,9 +352,9 @@ function SemanticToSetPosition(semantic: SemanticPosition): DancerSetPosition {
case HandTo.DancerRight: case HandTo.DancerRight:
return OffsetPlus({ x: +1, y: 0 }, balanceHandAdjustment); return OffsetPlus({ x: +1, y: 0 }, balanceHandAdjustment);
case HandTo.DancerForward: case HandTo.DancerForward:
const armLength = yAmount + (semantic.balance === BalanceWeight.Backward ? balanceAmount : semantic.balance === BalanceWeight.Forward ? -balanceAmount : 0); const armLength = yAmount + (semantic.balance === BalanceWeight.Backward ? balanceAmount : 0);
if (hand === connection.hand) { if (hand === connection.hand) {
return { x: 0, y: +armLength }; return { x: 0, y: +armLength/2 };
} else { } else {
return { x: dancerWidth / 2 * (hand === Hand.Left ? -1 : +1), y: +armLength }; return { x: dancerWidth / 2 * (hand === Hand.Left ? -1 : +1), y: +armLength };
} }
@ -657,7 +655,7 @@ function animateLowLevelMoveWithoutSlide(move: LowLevelMove): animation.Animatio
width: 1, width: 1,
height: 1, height: 1,
}, },
facing: move.movementPattern.facing ?? animation.RotationAnimationFacing.Forward, facing: animation.RotationAnimationFacing.Forward,
closer: move.movementPattern.close ? { closer: move.movementPattern.close ? {
transitionBeats: 1, transitionBeats: 1,
minDistance: 1, minDistance: 1,

View File

@ -1,5 +1,5 @@
import { CoupleRole, DanceRole, DancerIdentity, ExtendedDancerIdentity } from "../danceCommon.js"; import { CoupleRole, DanceRole, DancerIdentity, ExtendedDancerIdentity } from "../danceCommon.js";
import { BalanceWeight, CirclePosition, CircleSideOrCenter, DancerDistance, LongLines, PositionKind, SemanticPosition } from "../interpreterCommon.js"; import { CirclePosition, CircleSideOrCenter, PositionKind, SemanticPosition } from "../interpreterCommon.js";
import { Move, chooser_pairz } from "../libfigureMapper.js"; import { Move, chooser_pairz } from "../libfigureMapper.js";
import { LowLevelMove, SemanticAnimation, SemanticAnimationKind } from "../lowLevelMove.js"; import { LowLevelMove, SemanticAnimation, SemanticAnimationKind } from "../lowLevelMove.js";
@ -9,7 +9,7 @@ export const moveInterpreters: Map<MoveName, MoveInterpreterCtor<MoveName>> = ne
export interface MoveInterpreterCtorArgs<N extends MoveName> { export interface MoveInterpreterCtorArgs<N extends MoveName> {
move: Move & { move: N }; move: Move & { move: N };
nextMove?: Move; nextMove: Move;
numProgessions: number; numProgessions: number;
} }
export type SemanticPositionsForAllDancers = Map<DancerIdentity, SemanticPosition>; export type SemanticPositionsForAllDancers = Map<DancerIdentity, SemanticPosition>;
@ -18,13 +18,11 @@ export interface MoveAsLowLevelMovesArgs {
} }
export type LowLevelMovesForAllDancers = Map<DancerIdentity, LowLevelMove[]>; export type LowLevelMovesForAllDancers = Map<DancerIdentity, LowLevelMove[]>;
export interface Variant { export interface Variant {
previousMoveVariant: string, previousMoveVariant?: string,
lowLevelMoves: LowLevelMovesForAllDancers, lowLevelMoves: LowLevelMovesForAllDancers,
}; };
export type VariantCollection = Map<string, Variant>; export type VariantCollection = Map<string, Variant>;
export type AllVariantsForMoveArgs = Map<string, MoveAsLowLevelMovesArgs>;
export type PartialLowLevelMove = { export type PartialLowLevelMove = {
remarks?: string, remarks?: string,
beats: number, beats: number,
@ -34,7 +32,8 @@ export type PartialLowLevelMove = {
}; };
export interface ISingleVariantMoveInterpreter { export interface ISingleVariantMoveInterpreter {
moveAsVariants: (previousMoveVariant: string | undefined) => VariantCollection; moveAsLowLevelMoves: () => LowLevelMovesForAllDancers;
moveAsVariants: () => VariantCollection;
}; };
export abstract class SingleVariantMoveInterpreter<T extends MoveInterpreter<N>, N extends MoveName> implements ISingleVariantMoveInterpreter { export abstract class SingleVariantMoveInterpreter<T extends MoveInterpreter<N>, N extends MoveName> implements ISingleVariantMoveInterpreter {
@ -44,38 +43,17 @@ export abstract class SingleVariantMoveInterpreter<T extends MoveInterpreter<N>,
constructor(moveInterpreter: T, startingPos: SemanticPositionsForAllDancers) { constructor(moveInterpreter: T, startingPos: SemanticPositionsForAllDancers) {
this.moveInterpreter = moveInterpreter; this.moveInterpreter = moveInterpreter;
this.startingPos = startingPos; this.startingPos = startingPos;
const checkDistance = !this.moveInterpreter.allowStartingClose();
const checkBalance = !this.moveInterpreter.allowStartingBalance();
const checkLongLines = !this.moveInterpreter.allowStartingLongLines();
if (checkBalance || checkDistance || checkLongLines) {
for (const [id, startPos] of this.startingPos) {
if (checkBalance && startPos.balance) {
throw new Error("Can not start " + this.move.move + " with balance weight " + startPos.balance);
}
if (checkDistance && startPos.dancerDistance && startPos.dancerDistance !== DancerDistance.Normal) {
throw new Error("Can not start " + this.move.move + " at dancerDistance " + startPos.dancerDistance);
}
if (checkLongLines && startPos.longLines) {
throw new Error("Can not start " + this.move.move + " at long lines " + startPos.longLines);
}
}
}
} }
get move() : Move & { move: N } { get move() : Move & { move: N } {
return this.moveInterpreter.move; return this.moveInterpreter.move;
} }
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { abstract moveAsLowLevelMoves(): LowLevelMovesForAllDancers;
throw new Error("You must implement either moveAsLowLevelMoves() or moveAsVariants().");
}
// TODO It would make more sense for previousMoveVariant to get passed into the constructor... moveAsVariants(): VariantCollection {
// ... but that requires touching every subclass, so it's an annoying refactor.
moveAsVariants(previousMoveVariant: string): VariantCollection {
return new Map<string, Variant>([ return new Map<string, Variant>([
["default", { lowLevelMoves: this.moveAsLowLevelMoves(), previousMoveVariant }] ["default", { lowLevelMoves: this.moveAsLowLevelMoves() }]
]); ]);
} }
@ -315,10 +293,10 @@ export abstract class SingleVariantMoveInterpreter<T extends MoveInterpreter<N>,
} : undefined); } : undefined);
} }
errorStandStill(error?: string) { errorStandStill() {
return this.handleMove(({ startPos }) => { return this.handleMove(({ startPos }) => {
return [{ return [{
interpreterError: error ?? ("UNKNOWN MOVE '" + this.move.move + "': standing still"), interpreterError: "UNKNOWN MOVE '" + this.move.move + "': standing still",
move: this.move, move: this.move,
startBeat: 0, startBeat: 0,
beats: this.move.beats, beats: this.move.beats,
@ -334,7 +312,7 @@ export abstract class SingleVariantMoveInterpreter<T extends MoveInterpreter<N>,
export abstract class MoveInterpreter<N extends MoveName> { export abstract class MoveInterpreter<N extends MoveName> {
public readonly move: Move & { move: N }; public readonly move: Move & { move: N };
public readonly nextMove?: Move; public readonly nextMove: Move;
public readonly numProgressions: number; public readonly numProgressions: number;
constructor({ move, nextMove, numProgessions }: MoveInterpreterCtorArgs<N>) { constructor({ move, nextMove, numProgessions }: MoveInterpreterCtorArgs<N>) {
@ -343,97 +321,21 @@ export abstract class MoveInterpreter<N extends MoveName> {
this.numProgressions = numProgessions; this.numProgressions = numProgessions;
} }
allowStartingClose(): boolean {
// Swings can end close, but most moves can't start close, so do this check by default for all moves.
return false;
}
allowStartingBalance(): boolean {
// Make moves that support balance beforehand explicitly opt-in.
return false;
}
allowStartingLongLines(): boolean {
// Long lines is used for tweaking positioning; most moves don't know about it.
return false;
}
abstract buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter; abstract buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter;
// TODO Better name? moveAsLowLevelMoves({ startingPos }: MoveAsLowLevelMovesArgs): LowLevelMovesForAllDancers {
moveAsVariants({ startingPos }: MoveAsLowLevelMovesArgs, previousMoveVariant: string): VariantCollection { return this.buildSingleVariantMoveInterpreter(startingPos).moveAsLowLevelMoves();
return this.buildSingleVariantMoveInterpreter(startingPos).moveAsVariants(previousMoveVariant);
}
allVariantsForMove(args: AllVariantsForMoveArgs): VariantCollection {
const res = new Map<string, Variant>();
let error;
for (const [variantName, variantArgs] of args.entries()) {
let newVariants: VariantCollection;
try {
newVariants = this.moveAsVariants(variantArgs, variantName);
} catch (ex) {
// TODO Maybe have a way to distinguish invalid start from error processing move?
error = ex;
// If this variant can't be processed, just continue.
continue;
}
for (const [newVariantName, variant] of newVariants) {
let combinedVariantName: string;
if (args.size === 1) {
combinedVariantName = newVariantName;
} else if (newVariants.size === 1) {
combinedVariantName = variantName;
} else {
combinedVariantName = newVariantName + "_from_" + variantName;
}
res.set(combinedVariantName, variant);
}
}
if (res.size === 0) throw error;
else if (res.size > 1) {
// TODO Try to reduce variants if possible.
// XXX TODO Simple hack: perfer starting improper in a circle.
if ([...res.values()].find(v => v.previousMoveVariant === "InitialCircle")) {
for (const key of [...res.entries()].filter(([k, v]) => v.previousMoveVariant !== "InitialCircle").map(([k, v]) => k)) {
res.delete(key);
}
}
}
return res;
} }
} }
class ErrorSingleVariantMoveInterpreter extends SingleVariantMoveInterpreter<ErrorMoveInterpreter, MoveName> { class DefaultSingleVariantMoveInterpreter extends SingleVariantMoveInterpreter<DefaultMoveInterpreter, MoveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
return this.errorStandStill(this.moveInterpreter.error); return this.errorStandStill();
} }
} }
export class ErrorMoveInterpreter extends MoveInterpreter<MoveName> { class DefaultMoveInterpreter extends MoveInterpreter<MoveName> {
public readonly error?: string;
constructor(args: MoveInterpreterCtorArgs<MoveName>, error?: string) {
super(args);
this.error = error;
}
override allowStartingBalance(): boolean {
return true;
}
override allowStartingClose(): boolean {
return true;
}
override allowStartingLongLines(): boolean {
return true;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
//throw new Error("Method not implemented."); throw new Error("Method not implemented.");
return new ErrorSingleVariantMoveInterpreter(this, startingPos);
} }
} }
export const errorMoveInterpreterCtor: MoveInterpreterCtor<MoveName> = ErrorMoveInterpreter;Error export const errorMoveInterpreterCtor: MoveInterpreterCtor<MoveName> = DefaultMoveInterpreter;

View File

@ -1,7 +1,7 @@
import { SemanticPosition, PositionKind, CircleSide, Facing, CirclePosition, LongLines, HandConnection, DancerDistance } from "../interpreterCommon.js"; import { SemanticPosition, PositionKind, CircleSide, Facing, CirclePosition, LongLines, HandConnection } from "../interpreterCommon.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
type allemandeMoves = "allemande" | "allemande orbit" | "gyre"; type allemandeMoves = "allemande" | "allemande orbit" | "gyre";
@ -10,36 +10,32 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
// Need to store this locally so checking move.move restricts move.parameters. // Need to store this locally so checking move.move restricts move.parameters.
const move = this.move; const move = this.move;
for (const [id, pos] of this.startingPos.entries()) { const allemandeCircling = move.move === "allemande orbit" ? move.parameters.circling1 : move.parameters.circling;
if (this.findPairOpposite(this.move.parameters.who, id) === null) { const byHandOrShoulder = (move.move === "gyre" ? move.parameters.shoulder : move.parameters.hand) ? Hand.Right : Hand.Left;
if (pos.dancerDistance && pos.dancerDistance !== DancerDistance.Normal) {
throw new Error("Dancers not involved in allemande must start at normal dancer distance."); // TODO Not sure if this is right.
} const swap = allemandeCircling % 360 === 180;
if (pos.longLines) { const returnToStart = allemandeCircling % 360 === 0;
throw new Error("Dancers not involved in allemande must start not in long lines."); const intoWave = !swap && !returnToStart && allemandeCircling % 90 == 0;
} const intoWavePositions = !intoWave ? 0 : (allemandeCircling % 360 === 90) === (byHandOrShoulder === Hand.Left) ? 1 : -1;
} if (!swap && !returnToStart && !intoWave) {
// TODO Support allemande that's not a swap or no-op.
throw "Unsupported allemande circle amount: " + allemandeCircling;
} }
return this.handlePairedMove(this.move.parameters.who, ({ startPos, around, withId, withPos }) => { return this.handlePairedMove(move.parameters.who, ({ startPos, around, withId, withPos }) => {
if (startPos.kind === PositionKind.ShortLines && withPos.kind === PositionKind.ShortLines let endPosition: SemanticPosition = startPos;
&& startPos.which.leftRightSide() != withPos.which.leftRightSide() let startingPos = startPos;
&& (!startPos.which.isMiddle() || !withPos.which.isMiddle())) { if (swap) {
throw new Error("Allemande in short lines must either be on same side of set or in the middle.");
}
let endPosition: SemanticPosition = {...startPos, dancerDistance: undefined, longLines: undefined, balance: undefined };
let startingPos = {...startPos };
if (this.moveInterpreter.swap) {
// TODO This was more complicated. Is this wrong? // TODO This was more complicated. Is this wrong?
endPosition = {...withPos, dancerDistance: undefined, longLines: undefined, balance: undefined }; endPosition = withPos;
} else if (this.moveInterpreter.intoWave) { } else if (intoWave) {
if (startPos.kind === PositionKind.ShortLines) { if (startPos.kind === PositionKind.ShortLines) {
if (around === CircleSide.Left || around === CircleSide.Right) { if (around === CircleSide.Left || around === CircleSide.Right) {
// Fix startPos if necessary. Needed because pass through always swaps but sometimes shouldn't. // Fix startPos if necessary. Needed because pass through always swaps but sometimes shouldn't.
let startWhich = startPos.which; let startWhich = startPos.which;
if ((startPos.facing === Facing.Up || startPos.facing === Facing.Down) && if ((startPos.facing === Facing.Up || startPos.facing === Facing.Down) &&
((this.moveInterpreter.byHandOrShoulder === Hand.Right) ((byHandOrShoulder === Hand.Right)
!== (startPos.facing === Facing.Up) !== (startPos.facing === Facing.Up)
!== startPos.which.isLeftOfSide())) { !== startPos.which.isLeftOfSide())) {
startWhich = startPos.which.swapOnSide() startWhich = startPos.which.swapOnSide()
@ -51,14 +47,14 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
const endWhich = CirclePosition.fromSides(startingPos.which.leftRightSide(), const endWhich = CirclePosition.fromSides(startingPos.which.leftRightSide(),
startWhich.isLeftOfSide() startWhich.isLeftOfSide()
!== (this.moveInterpreter.byHandOrShoulder === Hand.Right) !== (byHandOrShoulder === Hand.Right)
!== (this.moveInterpreter.intoWavePositions === 1) !== (intoWavePositions === 1)
? CircleSide.Top ? CircleSide.Top
: CircleSide.Bottom); : CircleSide.Bottom);
endPosition = { endPosition = {
kind: PositionKind.Circle, kind: PositionKind.Circle,
which: endWhich, which: endWhich,
facing: (startingPos.facing === Facing.Up) === (this.moveInterpreter.intoWavePositions === 1) facing: (startingPos.facing === Facing.Up) === (intoWavePositions === 1)
? endWhich.facingAcross() ? endWhich.facingAcross()
: endWhich.facingOut(), : endWhich.facingOut(),
setOffset: startingPos.setOffset, setOffset: startingPos.setOffset,
@ -70,7 +66,7 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
} else { } else {
if (around === "Center") { if (around === "Center") {
const startCenter = startPos.longLines === LongLines.Center; const startCenter = startPos.longLines === LongLines.Center;
const endWhich = startPos.which.circleRight(this.moveInterpreter.intoWavePositions); const endWhich = startPos.which.circleRight(intoWavePositions);
endPosition = { endPosition = {
kind: PositionKind.Circle, kind: PositionKind.Circle,
which: endWhich, which: endWhich,
@ -80,11 +76,11 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
lineOffset: startPos.lineOffset, lineOffset: startPos.lineOffset,
} }
} else { } else {
const endWhich = startPos.which.toShortLines(this.moveInterpreter.intoWavePositions === 1 ? Hand.Right : Hand.Left); const endWhich = startPos.which.toShortLines(intoWavePositions === 1 ? Hand.Right : Hand.Left);
endPosition = { endPosition = {
kind: PositionKind.ShortLines, kind: PositionKind.ShortLines,
which: endWhich, which: endWhich,
facing: endWhich.isLeftOfSide() === (this.moveInterpreter.byHandOrShoulder === Hand.Left) ? Facing.Up : Facing.Down, facing: endWhich.isLeftOfSide() === (byHandOrShoulder === Hand.Left) ? Facing.Up : Facing.Down,
setOffset: startPos.setOffset, setOffset: startPos.setOffset,
lineOffset: startPos.lineOffset, lineOffset: startPos.lineOffset,
} }
@ -94,23 +90,30 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
return this.combine([ return this.combine([
{ {
beats: this.move.beats, beats: move.beats,
endPosition, endPosition,
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.RotateAround, kind: SemanticAnimationKind.RotateAround,
minAmount: this.moveInterpreter.byHandOrShoulder === Hand.Right ? this.moveInterpreter.allemandeCircling : -this.moveInterpreter.allemandeCircling, minAmount: byHandOrShoulder === Hand.Right ? allemandeCircling : -allemandeCircling,
around, around,
byHand: move.move === "allemande" || move.move === "allemande orbit" ? this.moveInterpreter.byHandOrShoulder : undefined, byHand: move.move === "allemande" || move.move === "allemande orbit" ? byHandOrShoulder : undefined,
close: true, close: true,
}, },
}, },
], { ], {
...startingPos, ...startingPos,
hands: startPos.hands && move.move !== "gyre" hands: startPos.hands && move.move !== "gyre"
? new Map<Hand, HandConnection>([...startPos.hands.entries()].filter(([h, c]) => h === this.moveInterpreter.byHandOrShoulder)) ? new Map<Hand, HandConnection>([...startPos.hands.entries()].filter(([h, c]) => h === byHandOrShoulder))
: undefined : undefined
}); });
}, move.move !== "allemande orbit" ? undefined : ({ id, startPos }) => { }, move.move !== "allemande orbit" ? undefined : ({ id, startPos }) => {
const orbitAmount = move.parameters.circling2;
const swap = orbitAmount % 360 === 180;
if (!swap && orbitAmount % 360 !== 0) {
// TODO Support allemande that's not a swap or no-op.
throw "Unsupported allemande orbit amount: " + orbitAmount;
}
const startingPos: SemanticPosition = { const startingPos: SemanticPosition = {
...startPos, ...startPos,
hands: undefined, hands: undefined,
@ -118,7 +121,7 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
dancerDistance: undefined, dancerDistance: undefined,
} }
let endPosition: SemanticPosition; let endPosition: SemanticPosition;
if (this.moveInterpreter.orbitSwap) { if (swap) {
if (startingPos.kind === PositionKind.Circle) { if (startingPos.kind === PositionKind.Circle) {
endPosition = endPosition =
{ {
@ -145,7 +148,7 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.RotateAround, kind: SemanticAnimationKind.RotateAround,
// Orbit is opposite direction of allemande. // Orbit is opposite direction of allemande.
minAmount: this.moveInterpreter.byHandOrShoulder === Hand.Right ? -this.moveInterpreter.orbitCircling : +this.moveInterpreter.orbitCircling, minAmount: byHandOrShoulder === Hand.Right ? -orbitAmount : +orbitAmount,
around: "Center", around: "Center",
byHand: undefined, byHand: undefined,
close: false, close: false,
@ -157,55 +160,6 @@ class AllemandeSingleVariant extends SingleVariantMoveInterpreter<Allemande, all
} }
class Allemande extends MoveInterpreter<allemandeMoves> { class Allemande extends MoveInterpreter<allemandeMoves> {
public readonly allemandeCircling: number;
public readonly orbitCircling: number;
public readonly byHandOrShoulder: Hand;
public readonly swap: boolean;
public readonly orbitSwap: boolean;
public readonly returnToStart: boolean;
public readonly intoWave: boolean;
public readonly intoWavePositions: number;
constructor(args: MoveInterpreterCtorArgs<allemandeMoves>) {
super(args);
this.allemandeCircling = this.move.move === "allemande orbit" ? this.move.parameters.circling1 : this.move.parameters.circling;
this.byHandOrShoulder = (this.move.move === "gyre" ? this.move.parameters.shoulder : this.move.parameters.hand) ? Hand.Right : Hand.Left;
// TODO Not sure if this is right.
this.swap = this.allemandeCircling % 360 === 180;
this.returnToStart = this.allemandeCircling % 360 === 0;
this.intoWave = !this.swap && !this.returnToStart && this.allemandeCircling % 90 == 0;
this.intoWavePositions = !this.intoWave
? 0
: (this.allemandeCircling % 360 === 90) === (this.byHandOrShoulder === Hand.Left)
? +1
: -1;
if (!this.swap && !this.returnToStart && !this.intoWave) {
// TODO Support allemande that's not a swap or no-op.
throw "Unsupported allemande circle amount: " + this.allemandeCircling;
}
if (this.move.move === "allemande orbit") {
this.orbitCircling = this.move.parameters.circling2;
this.orbitSwap = this.orbitCircling % 360 === 180;
if (!this.orbitSwap && this.orbitCircling % 360 !== 0) {
// TODO Support allemande that's not a swap or no-op.
throw "Unsupported allemande orbit amount: " + this.orbitCircling;
}
} else {
this.orbitCircling = 0;
this.orbitSwap = false;
}
}
override allowStartingClose(): boolean {
return true;
}
override allowStartingLongLines(): boolean {
return true;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new AllemandeSingleVariant(this, startingPos); return new AllemandeSingleVariant(this, startingPos);
} }

View File

@ -1,100 +1,39 @@
import { BalanceWeight, Facing, HandConnection, HandTo, PositionKind, facingAdjacent, facingRequireAdjacent } from "../interpreterCommon.js"; import { BalanceWeight } from "../interpreterCommon.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, Variant, VariantCollection, moveInterpreters } from "./_moveInterpreter.js";
const moveName = "balance"; 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?
class BalanceSingleVariant extends SingleVariantMoveInterpreter<Balance, typeof moveName> { return this.combine([
private static readonly balanceOptions : [BalanceWeight, BalanceWeight | undefined, Hand | undefined][]= [ {
// TODO Any others? beats: this.moveInterpreter.forwardBeats,
[BalanceWeight.Forward, undefined, undefined], endPosition: { ...startPos, balance: BalanceWeight.Forward },
[BalanceWeight.Forward, BalanceWeight.Backward, undefined], movementPattern: { kind: SemanticAnimationKind.Linear },
// TODO Should be left/right/inside/outside hands? },
[BalanceWeight.Forward, BalanceWeight.Backward, Hand.Left], {
[BalanceWeight.Forward, BalanceWeight.Backward, Hand.Right], beats: this.moveInterpreter.backwardBeats,
[BalanceWeight.Right, BalanceWeight.Backward, undefined], endPosition: { ...startPos, balance: BalanceWeight.Backward },
[BalanceWeight.Right, BalanceWeight.Left, undefined], movementPattern: { kind: SemanticAnimationKind.Linear },
[BalanceWeight.Left, BalanceWeight.Right, undefined], },
]; ], startPos);
});
moveAsVariants(previousMoveVariant: string): VariantCollection {
const res = new Map<string, Variant>();
for (const [firstWeight, secondWeight, hand] of BalanceSingleVariant.balanceOptions) {
// If balancing someone, need to know by which hand.
if ((hand === undefined) !== (this.move.parameters.who === "everyone")) continue;
try {
res.set((firstWeight?.toString() ?? "") + (secondWeight?.toString() ?? "") + (hand === undefined ? "" : hand.toString() + "Hand"), {
lowLevelMoves: this.moveAsLowLevelMovesWeights(firstWeight, secondWeight, hand),
previousMoveVariant
});
}
catch { }
}
return res;
}
moveAsLowLevelMovesWeights(firstWeight?: BalanceWeight, secondWeight?: BalanceWeight, hand?: Hand): LowLevelMovesForAllDancers {
if (this.move.parameters.who !== "everyone") {
return this.handlePairedMove(this.move.parameters.who, ({ startPos, withPos }) => {
// TODO Does this need to support balancing inside/outside hands? If so how to identify them?
const hands = hand === undefined ? startPos.hands : new Map<Hand, HandConnection>([[hand, {hand, to: HandTo.DancerForward}]]);
const facing = facingRequireAdjacent(startPos, withPos, this.move.move);
const startingPos = {...startPos, facing, hands};
return this.combine([
{
beats: this.moveInterpreter.balancePartBeats,
endPosition: { ...startingPos, balance: firstWeight, hands },
movementPattern: { kind: SemanticAnimationKind.Linear },
},
{
beats: this.moveInterpreter.balancePartBeats,
endPosition: { ...startingPos, balance: secondWeight, hands },
movementPattern: { kind: SemanticAnimationKind.Linear },
},
], startingPos);
});
} else {
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?
if (startPos.kind === PositionKind.Circle && startPos.facing === Facing.CenterOfCircle) {
if (firstWeight === BalanceWeight.Left || firstWeight === BalanceWeight.Right || firstWeight === BalanceWeight.Backward
|| secondWeight === BalanceWeight.Left || secondWeight === BalanceWeight.Right || secondWeight === BalanceWeight.Backward) {
throw new Error("Balancing left or right in a circle is unsupported.");
}
}
return this.combine([
{
beats: this.moveInterpreter.balancePartBeats,
endPosition: { ...startPos, balance: firstWeight },
movementPattern: { kind: SemanticAnimationKind.Linear },
},
{
beats: this.moveInterpreter.balancePartBeats,
endPosition: { ...startPos, balance: secondWeight },
movementPattern: { kind: SemanticAnimationKind.Linear },
},
], startPos);
});
}
} }
} }
class Balance extends MoveInterpreter<typeof moveName> { class Balance extends MoveInterpreter<"balance"> {
public readonly balancePartBeats: number; public readonly forwardBeats: number;
public readonly backwardBeats: number;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) { constructor(args: MoveInterpreterCtorArgs<"balance">) {
super(args); super(args);
this.balancePartBeats = this.move.beats / 2; this.forwardBeats = this.move.beats / 2;
this.backwardBeats = this.move.beats - this.forwardBeats;
} }
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
@ -102,4 +41,4 @@ class Balance extends MoveInterpreter<typeof moveName> {
} }
} }
moveInterpreters.set(moveName, Balance); moveInterpreters.set("balance", Balance);

View File

@ -1,4 +1,4 @@
import { BalanceWeight, Facing, HandConnection, HandTo, PositionKind, SemanticPosition, handsInCircle } from "../interpreterCommon.js"; import { BalanceWeight, Facing, HandConnection, HandTo, PositionKind, SemanticPosition } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js"; import { Move } from "../libfigureMapper.js";
import { LowLevelMove, SemanticAnimationKind } from "../lowLevelMove.js"; import { LowLevelMove, SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
@ -11,11 +11,14 @@ export function balanceCircleInAndOut(move: Move, startPos: SemanticPosition, ba
} }
balanceBeats ??= 4; balanceBeats ??= 4;
const balancePartBeats = balanceBeats / 2; const balancePartBeats = balanceBeats/2;
const holdingHandsInCircle: SemanticPosition = {...startPos, const holdingHandsInCircle: SemanticPosition = {...startPos,
facing: Facing.CenterOfCircle, facing: Facing.CenterOfCircle,
hands: handsInCircle, hands: new Map<Hand, HandConnection>([
[Hand.Left, { hand: Hand.Right, to: HandTo.LeftInCircle }],
[Hand.Right, { hand: Hand.Left, to: HandTo.RightInCircle }],
]),
}; };
const circleBalancedIn: SemanticPosition = {...holdingHandsInCircle, const circleBalancedIn: SemanticPosition = {...holdingHandsInCircle,
balance: BalanceWeight.Forward, balance: BalanceWeight.Forward,

View File

@ -1,30 +1,14 @@
import { DanceRole, CoupleRole } from "../danceCommon.js"; import { DanceRole, CoupleRole } from "../danceCommon.js";
import { SemanticPosition, Facing, HandConnection, HandTo, BalanceWeight, handsInLine, LongLines } from "../interpreterCommon.js"; import { SemanticPosition, Facing, HandConnection, HandTo, BalanceWeight } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js"; import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, Variant, VariantCollection, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName: Move["move"] = "box circulate"; const moveName: Move["move"] = "box circulate";
class BoxCirculateSingleVariant extends SingleVariantMoveInterpreter<BoxCirculate, typeof moveName> { class BoxCirculateSingleVariant extends SingleVariantMoveInterpreter<BoxCirculate, typeof moveName> {
moveAsVariants(previousMoveVariant: string): VariantCollection { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
const res = new Map<string, Variant>();
for (const crossPartway of (this.move.note?.includes("catch") ? [true] : [true, false])) {
try {
res.set(crossPartway ? "CrossPartway" : "Normal", {
lowLevelMoves: this.moveAsLowLevelMovesCross(crossPartway),
previousMoveVariant
});
}
catch { }
}
return res;
}
moveAsLowLevelMovesCross(crossPartway: boolean): LowLevelMovesForAllDancers {
const circulateRight: boolean = this.move.parameters.hand; const circulateRight: boolean = this.move.parameters.hand;
const whoCrosses = this.move.parameters.who; const whoCrosses = this.move.parameters.who;
return this.handleCircleMove(({ id, startPos }) => { return this.handleCircleMove(({ id, startPos }) => {
@ -50,7 +34,7 @@ class BoxCirculateSingleVariant extends SingleVariantMoveInterpreter<BoxCirculat
// Starts in long wavy lines. // Starts in long wavy lines.
const startingPos: SemanticPosition = { const startingPos: SemanticPosition = {
...startPos, ...startPos,
facing: isCrossing ? startPos.which.facingAcross() : startPos.which.facingOut(), facing: isCrossing === startPos.which.isLeft() ? Facing.Right : Facing.Left,
hands: new Map<Hand, HandConnection>([ hands: new Map<Hand, HandConnection>([
[Hand.Left, { hand: Hand.Left, to: HandTo.DancerLeft }], [Hand.Left, { hand: Hand.Left, to: HandTo.DancerLeft }],
[Hand.Right, { hand: Hand.Right, to: HandTo.DancerRight }], [Hand.Right, { hand: Hand.Right, to: HandTo.DancerRight }],
@ -77,7 +61,6 @@ class BoxCirculateSingleVariant extends SingleVariantMoveInterpreter<BoxCirculat
...startingPos, ...startingPos,
which: isCrossing ? startingPos.which.swapAcross() : startingPos.which.swapUpAndDown(), which: isCrossing ? startingPos.which.swapAcross() : startingPos.which.swapUpAndDown(),
facing: isCrossing ? startingPos.facing : startingPos.facing === Facing.Right ? Facing.Left : Facing.Right, facing: isCrossing ? startingPos.facing : startingPos.facing === Facing.Right ? Facing.Left : Facing.Right,
longLines: isCrossing && crossPartway ? LongLines.Center : undefined,
}, },
movementPattern: { movementPattern: {
// TODO Not sure loop should really be linear... // TODO Not sure loop should really be linear...

View File

@ -1,41 +1,44 @@
import { HandConnection, HandTo, BalanceWeight, facingRequireAdjacent } from "../interpreterCommon.js"; import { HandConnection, HandTo, BalanceWeight } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName = "box the gnat"; const moveName: Move["move"] = "box the gnat";
class BoxTheGnatSingleVariant extends SingleVariantMoveInterpreter<BoxTheGnat, typeof moveName> { class BoxTheGnatSingleVariant extends SingleVariantMoveInterpreter<BoxTheGnat, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
return this.handlePairedMove(this.move.parameters.who, ({ startPos, around, withPos }) => { 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) { const hand = this.move.parameters.hand ? Hand.Right : Hand.Left;
throw new Error(this.move.move + " shouldn't start with holding left hands. Something went wrong."); const balanceBeats = this.move.parameters.bal
} ? this.move.beats > 4
if (startPos.balance && startPos.balance !== BalanceWeight.Backward) { ? this.move.beats - 4
throw new Error(this.move.move + " shouldn't start with balance weight " + startPos.balance); : 2
} : 0;
const balancePartBeats = balanceBeats / 2;
const twirlBeats = this.move.beats - balanceBeats;
const facing = facingRequireAdjacent(startPos, withPos, this.move.move); // TODO Adjust facing?
const startPosition = { ...startPos, hands: this.moveInterpreter.hands, facing }; const startPosition = { ...startPos, hands: new Map<Hand, HandConnection>([[hand, { hand, to: HandTo.DancerForward }]]) };
if (around === "Center") { if (around === "Center") {
throw "TwirlSwap around center is unsupported."; throw "TwirlSwap around center is unsupported.";
} }
const twirl: PartialLowLevelMove = { const twirl: PartialLowLevelMove = {
beats: this.moveInterpreter.twirlBeats, beats: twirlBeats,
endPosition: { ...withPos, balance: undefined }, endPosition: withPos,
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.TwirlSwap, kind: SemanticAnimationKind.TwirlSwap,
around, around,
hand: this.moveInterpreter.hand, hand,
} }
}; };
if (this.move.parameters.bal) { if (this.move.parameters.bal) {
return this.combine([ return this.combine([
{ {
beats: this.moveInterpreter.balancePartBeats, beats: balancePartBeats,
endPosition: { endPosition: {
...startPosition, ...startPosition,
balance: BalanceWeight.Forward, balance: BalanceWeight.Forward,
@ -45,7 +48,7 @@ class BoxTheGnatSingleVariant extends SingleVariantMoveInterpreter<BoxTheGnat, t
} }
}, },
{ {
beats: this.moveInterpreter.balancePartBeats, beats: balancePartBeats,
endPosition: { endPosition: {
...startPosition, ...startPosition,
balance: BalanceWeight.Backward, balance: BalanceWeight.Backward,
@ -63,29 +66,6 @@ class BoxTheGnatSingleVariant extends SingleVariantMoveInterpreter<BoxTheGnat, t
} }
class BoxTheGnat extends MoveInterpreter<typeof moveName> { class BoxTheGnat extends MoveInterpreter<typeof moveName> {
public readonly hand: Hand;
public readonly hands: Map<Hand, HandConnection>;
public readonly balancePartBeats: number;
public readonly twirlBeats: number;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) {
super(args);
this.hand = this.move.parameters.hand ? Hand.Right : Hand.Left;
this.hands = new Map<Hand, HandConnection>([[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 { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new BoxTheGnatSingleVariant(this, startingPos); return new BoxTheGnatSingleVariant(this, startingPos);
} }

View File

@ -1,4 +1,3 @@
import { RotationAnimationFacing } from "../animation.js";
import { Move } from "../libfigureMapper.js"; import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
@ -15,10 +14,8 @@ class ButterflyWhirlSingleVariant extends SingleVariantMoveInterpreter<Butterfly
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.RotateAround, kind: SemanticAnimationKind.RotateAround,
around: startPos.which.leftRightSide(), around: startPos.which.leftRightSide(),
// TODO hand around isn't the same as allemande...
byHand: startPos.which.isOnLeftLookingAcross() ? Hand.Right : Hand.Left, byHand: startPos.which.isOnLeftLookingAcross() ? Hand.Right : Hand.Left,
facing: startPos.which.isOnLeftLookingAcross()
? RotationAnimationFacing.Forward
: RotationAnimationFacing.Backward,
close: true, close: true,
minAmount: 360, minAmount: 360,
} }
@ -28,10 +25,6 @@ class ButterflyWhirlSingleVariant extends SingleVariantMoveInterpreter<Butterfly
} }
class ButterflyWhirl extends MoveInterpreter<typeof moveName> { class ButterflyWhirl extends MoveInterpreter<typeof moveName> {
override allowStartingClose(): boolean {
return true;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new ButterflyWhirlSingleVariant(this, startingPos); return new ButterflyWhirlSingleVariant(this, startingPos);
} }

View File

@ -1,4 +1,4 @@
import { HandConnection, HandTo, CircleSide, Facing, facingInAround, oppositeFacing } from "../interpreterCommon.js"; import { HandConnection, HandTo, CircleSide, Facing } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js"; import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
@ -8,17 +8,10 @@ const moveName: Move["move"] = "California twirl";
class CaliforniaTwirlSingleVariant extends SingleVariantMoveInterpreter<CaliforniaTwirl, typeof moveName> { class CaliforniaTwirlSingleVariant extends SingleVariantMoveInterpreter<CaliforniaTwirl, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
return this.handleCirclePairedMove(this.move.parameters.who, ({ startPos, around }) => { return this.handleCirclePairedMove(this.move.parameters.who, ({ startPos }) => {
if (around === "Center") { // TODO does "who" matter here or is it entirely positional? At least need to know who to omit.
throw new Error("Don't know how to " + this.move.move + " around the center.");
}
if (startPos.facing === Facing.LeftInCircle || startPos.facing === Facing.RightInCircle) { const onLeft: boolean = startPos.which.isOnLeftLookingUpAndDown();
throw new Error("Don't know how to " + this.move.move + " starting facing " + startPos.facing);
}
const facing = startPos.facing === Facing.CenterOfCircle ? facingInAround(around) : startPos.facing;
const onLeft: boolean = startPos.which.isOnLeft(around, startPos.facing);
// TODO get rid of this 1 beat set up and make it part of TwirlSwap? // TODO get rid of this 1 beat set up and make it part of TwirlSwap?
return this.combine([ return this.combine([
{ {
@ -28,7 +21,7 @@ class CaliforniaTwirlSingleVariant extends SingleVariantMoveInterpreter<Californ
hands: new Map<Hand, HandConnection>([onLeft hands: new Map<Hand, HandConnection>([onLeft
? [Hand.Right, { to: HandTo.DancerRight, hand: Hand.Left }] ? [Hand.Right, { to: HandTo.DancerRight, hand: Hand.Left }]
: [Hand.Left, { to: HandTo.DancerLeft, hand: Hand.Right }]]), : [Hand.Left, { to: HandTo.DancerLeft, hand: Hand.Right }]]),
facing, facing: startPos.which.topBottomSide() === CircleSide.Top ? Facing.Down : Facing.Up,
}, },
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.Linear, kind: SemanticAnimationKind.Linear,
@ -38,12 +31,12 @@ class CaliforniaTwirlSingleVariant extends SingleVariantMoveInterpreter<Californ
beats: this.move.beats - 1, beats: this.move.beats - 1,
endPosition: { endPosition: {
...startPos, ...startPos,
which: startPos.which.swapOnSide(around), which: startPos.which.swapAcross(),
facing: oppositeFacing(facing), facing: startPos.which.topBottomSide() === CircleSide.Top ? Facing.Up : Facing.Down,
}, },
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.TwirlSwap, kind: SemanticAnimationKind.TwirlSwap,
around, around: startPos.which.topBottomSide(),
hand: onLeft ? Hand.Right : Hand.Left, hand: onLeft ? Hand.Right : Hand.Left,
} }
}], startPos); }], startPos);

View File

@ -1,4 +1,4 @@
import { DancerDistance, Facing, handsInCircle } from "../interpreterCommon.js"; import { Facing, handsInCircle } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js"; import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";

View File

@ -22,9 +22,6 @@ class DownTheHallSingleVariant extends SingleVariantMoveInterpreter<DownTheHall,
} }
return this.handleMove(({ startPos }) => { return this.handleMove(({ startPos }) => {
const startFacing = this.move.parameters.facing === "backward" ? Facing.Up : Facing.Down; const startFacing = this.move.parameters.facing === "backward" ? Facing.Up : Facing.Down;
if (startPos.facing !== startFacing && (startPos.facing === Facing.Up || startPos.facing === Facing.Down)) {
throw new Error("Started facing the wrong direction.");
}
const startWhich: ShortLinesPosition = startPos.kind === PositionKind.ShortLines const startWhich: ShortLinesPosition = startPos.kind === PositionKind.ShortLines
? startPos.which ? startPos.which
// TODO Is this always the right way to convert circle to short lines? // TODO Is this always the right way to convert circle to short lines?

View File

@ -1,242 +1,263 @@
import { DancerIdentity } from "../danceCommon.js"; import { DancerIdentity } from "../danceCommon.js";
import { SemanticPosition, PositionKind, ShortLinesPosition, CirclePosition, CircleSide, Facing } from "../interpreterCommon.js"; import { SemanticPosition, PositionKind, ShortLinesPosition, CirclePosition, CircleSide, Facing } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { LowLevelMove, SemanticAnimationKind } from "../lowLevelMove.js"; import { LowLevelMove, SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
import { dancerIsPair } from "../libfigure/util.js"; import { dancerIsPair } from "../libfigure/util.js";
const moveName = "hey"; const moveName: Move["move"] = "hey";
type HeyStep = {
kind: "StandStill" | "Loop" | "CenterPass" | "EndsPassIn" | "EndsPassOut" | "Ricochet",
endPosition: SemanticPosition,
}
function fixupHeyOtherPath(withoutOtherPath: Map<DancerIdentity, (LowLevelMove & { heyStep?: HeyStep })[]>): Map<DancerIdentity, LowLevelMove[]> {
const numSteps = withoutOtherPath.get(DancerIdentity.OnesLark)!.length;
for (let i = 0; i < numSteps; i++) {
for (const id of withoutOtherPath.keys()) {
const lowLevelMove = withoutOtherPath.get(id)![i];
if (lowLevelMove.movementPattern.kind !== SemanticAnimationKind.PassBy
|| !lowLevelMove.heyStep
|| lowLevelMove.movementPattern.otherPath) {
continue;
}
const heyStepKind = lowLevelMove.heyStep.kind;
let foundPair = false;
for (const otherId of withoutOtherPath.keys()) {
const otherLowLevelMove = withoutOtherPath.get(otherId)![i];
if (id === otherId
|| otherLowLevelMove.movementPattern.kind !== SemanticAnimationKind.PassBy
|| !otherLowLevelMove.heyStep
|| otherLowLevelMove.movementPattern.otherPath) {
continue;
}
const otherHeyStepKind = otherLowLevelMove.heyStep.kind;
if (heyStepKind === "CenterPass" && otherHeyStepKind === "CenterPass"
|| (lowLevelMove.startPosition.which.leftRightSide() === otherLowLevelMove.startPosition.which.leftRightSide()
&& (heyStepKind === "EndsPassIn" && otherHeyStepKind === "EndsPassOut"
|| heyStepKind === "EndsPassOut" && otherHeyStepKind === "EndsPassIn"))) {
lowLevelMove.movementPattern.otherPath = {
start: { ...otherLowLevelMove.startPosition, setOffset: lowLevelMove.startPosition.setOffset, lineOffset: lowLevelMove.startPosition.lineOffset },
end: { ...otherLowLevelMove.endPosition, setOffset: lowLevelMove.endPosition.setOffset, lineOffset: lowLevelMove.endPosition.lineOffset },
}
otherLowLevelMove.movementPattern.otherPath = {
start: { ...lowLevelMove.startPosition, setOffset: otherLowLevelMove.startPosition.setOffset, lineOffset: otherLowLevelMove.startPosition.lineOffset },
end: { ...lowLevelMove.endPosition, setOffset: otherLowLevelMove.endPosition.setOffset, lineOffset: otherLowLevelMove.endPosition.lineOffset },
}
foundPair = true;
break;
}
}
if (!foundPair && heyStepKind === "EndsPassOut") {
// Then other is standing still.
const pos = {
...([...withoutOtherPath.values()]
.map(otherMoves => otherMoves[i])
.filter(m => m.movementPattern.kind === SemanticAnimationKind.StandStill
&& m.endPosition.which.leftRightSide() === lowLevelMove.endPosition.which.leftRightSide())
[0].endPosition),
setOffset: lowLevelMove.startPosition.setOffset, lineOffset: lowLevelMove.startPosition.lineOffset
}
lowLevelMove.movementPattern.otherPath = { start: pos, end: pos };
}
}
for (const id of withoutOtherPath.keys()) {
const lowLevelMove = withoutOtherPath.get(id)![i];
if (lowLevelMove.movementPattern.kind === SemanticAnimationKind.PassBy
&& !lowLevelMove.movementPattern.otherPath) {
throw new Error("Failed to fill in otherPath for " + id + " on hey step " + i);
}
}
}
// Object was mutated.
return withoutOtherPath;
}
class HeySingleVariant extends SingleVariantMoveInterpreter<Hey, typeof moveName> { class HeySingleVariant extends SingleVariantMoveInterpreter<Hey, typeof moveName> {
heyStepToPartialLowLevelMove(heyStep: HeyStep): PartialLowLevelMove & { heyStep: HeyStep } { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
return { // Needed for inner functions... that probably should be methods.
beats: this.moveInterpreter.heyPartBeats, const move = this.move;
// TODO use circle positions on ends? ... unless hey ends in a box the gnat or similar...
endPosition: heyStep.endPosition,
movementPattern: heyStep.kind === "StandStill" ? {
kind: SemanticAnimationKind.StandStill,
} : heyStep.kind === "Loop" ? {
// TODO Loop should probably be its own kind? Or RotateAround?
kind: SemanticAnimationKind.Linear,
minRotation: this.moveInterpreter.endsShoulder === Hand.Right ? +180 : -180,
} : heyStep.kind === "Ricochet" ? {
// TODO This is a hack.
kind: SemanticAnimationKind.PassBy,
around: heyStep.endPosition.which.leftRightSide(),
withHands: false,
otherPath: "Swap",
facing: "Start",
side: this.moveInterpreter.endsShoulder,
} : {
kind: SemanticAnimationKind.PassBy,
around: heyStep.kind === "CenterPass" ? "Center" : heyStep.endPosition.which.leftRightSide(),
withHands: false,
side: heyStep.kind === "CenterPass" ? this.moveInterpreter.centerShoulder : this.moveInterpreter.endsShoulder,
facing: "Start",
otherPath: undefined!, // Placeholder, fixup later.
},
heyStep,
};
}
continueHey(prevStep: HeyStep, stepsLeft: number, type HeyStep = {
{ beenInCenter, endsInCircle, inCenterFirst }: kind: "StandStill" | "Loop" | "CenterPass" | "EndsPassIn" | "EndsPassOut" | "Ricochet",
{ beenInCenter: boolean, endsInCircle: boolean, inCenterFirst: boolean }): HeyStep { endPosition: SemanticPosition,
// TODO Not sure why type checker requires rechecking this here.
if (this.move.move !== "hey") throw new Error("Unreachable.");
// Continuing hey so everyone is either passing (in center or on ends) or looping on ends.
if (prevStep.endPosition.kind === PositionKind.Circle) {
if (prevStep.endPosition.facing === prevStep.endPosition.which.facingAcross()) {
if (stepsLeft === 0) {
return {
kind: "StandStill",
endPosition: prevStep.endPosition,
}
}
return {
kind: "EndsPassIn",
endPosition: {
kind: PositionKind.ShortLines,
which: prevStep.endPosition.which.isLeft() ? ShortLinesPosition.MiddleLeft : ShortLinesPosition.MiddleRight,
facing: prevStep.endPosition.which.facingAcross(),
setOffset: prevStep.endPosition.setOffset,
lineOffset: prevStep.endPosition.lineOffset,
},
}
}
else {
if (stepsLeft === 1 && !endsInCircle) {
return {
kind: "Loop",
endPosition: {
kind: PositionKind.ShortLines,
which: prevStep.endPosition.which.isLeft() ? ShortLinesPosition.FarLeft : ShortLinesPosition.FarRight,
facing: prevStep.endPosition.which.facingAcross(),
setOffset: prevStep.endPosition.setOffset,
lineOffset: prevStep.endPosition.lineOffset,
},
}
}
return {
kind: "Loop",
endPosition: {
...prevStep.endPosition,
which: prevStep.endPosition.which.swapUpAndDown(),
facing: prevStep.endPosition.which.facingAcross()
},
}
}
} }
else if (prevStep.endPosition.kind === PositionKind.ShortLines) {
const isFacingSide = prevStep.endPosition.facing === prevStep.endPosition.which.facingSide(); if (this.move.parameters.dir !== "across") {
const inMiddle = prevStep.endPosition.which.isMiddle(); throw new Error("Unsupported hey direction: " + this.move.parameters.dir);
if (!inMiddle && !isFacingSide) { }
return {
kind: "Loop", let heyParts: number;
endPosition: { ...prevStep.endPosition, facing: prevStep.endPosition.which.facingSide() }, switch (this.move.parameters.until) {
case "half":
heyParts = 4;
break;
case "full":
heyParts = 8;
break;
default:
throw new Error("Unsupported hey 'until': " + this.move.parameters.until);
}
const heyPartBeats: number = this.move.beats / heyParts;
// TODO is this right?
const firstPassInCenter: boolean = dancerIsPair(this.move.parameters.who);
const centerShoulder = firstPassInCenter === this.move.parameters.shoulder ? Hand.Right : Hand.Left;
const endsShoulder = centerShoulder.opposite();
function fixupHeyOtherPath(withoutOtherPath: Map<DancerIdentity, (LowLevelMove & { heyStep?: HeyStep })[]>): Map<DancerIdentity, LowLevelMove[]> {
const numSteps = withoutOtherPath.get(DancerIdentity.OnesLark)!.length;
for (let i = 0; i < numSteps; i++) {
for (const id of withoutOtherPath.keys()) {
const lowLevelMove = withoutOtherPath.get(id)![i];
if (lowLevelMove.movementPattern.kind !== SemanticAnimationKind.PassBy
|| !lowLevelMove.heyStep
|| lowLevelMove.movementPattern.otherPath) {
continue;
}
const heyStepKind = lowLevelMove.heyStep.kind;
let foundPair = false;
for (const otherId of withoutOtherPath.keys()) {
const otherLowLevelMove = withoutOtherPath.get(otherId)![i];
if (id === otherId
|| otherLowLevelMove.movementPattern.kind !== SemanticAnimationKind.PassBy
|| !otherLowLevelMove.heyStep
|| otherLowLevelMove.movementPattern.otherPath) {
continue;
}
const otherHeyStepKind = otherLowLevelMove.heyStep.kind;
if (heyStepKind === "CenterPass" && otherHeyStepKind === "CenterPass"
|| (lowLevelMove.startPosition.which.leftRightSide() === otherLowLevelMove.startPosition.which.leftRightSide()
&& (heyStepKind === "EndsPassIn" && otherHeyStepKind === "EndsPassOut"
|| heyStepKind === "EndsPassOut" && otherHeyStepKind === "EndsPassIn"))) {
lowLevelMove.movementPattern.otherPath = {
start: { ...otherLowLevelMove.startPosition, setOffset: lowLevelMove.startPosition.setOffset, lineOffset: lowLevelMove.startPosition.lineOffset },
end: { ...otherLowLevelMove.endPosition, setOffset: lowLevelMove.endPosition.setOffset, lineOffset: lowLevelMove.endPosition.lineOffset },
}
otherLowLevelMove.movementPattern.otherPath = {
start: { ...lowLevelMove.startPosition, setOffset: otherLowLevelMove.startPosition.setOffset, lineOffset: otherLowLevelMove.startPosition.lineOffset },
end: { ...lowLevelMove.endPosition, setOffset: otherLowLevelMove.endPosition.setOffset, lineOffset: otherLowLevelMove.endPosition.lineOffset },
}
foundPair = true;
break;
}
}
if (!foundPair && heyStepKind === "EndsPassOut") {
// Then other is standing still.
const pos = {
...([...withoutOtherPath.values()]
.map(otherMoves => otherMoves[i])
.filter(m => m.movementPattern.kind === SemanticAnimationKind.StandStill
&& m.endPosition.which.leftRightSide() === lowLevelMove.endPosition.which.leftRightSide())
[0].endPosition),
setOffset: lowLevelMove.startPosition.setOffset, lineOffset: lowLevelMove.startPosition.lineOffset
}
lowLevelMove.movementPattern.otherPath = { start: pos, end: pos };
}
} }
} else if (inMiddle && isFacingSide) {
return { for (const id of withoutOtherPath.keys()) {
kind: "EndsPassOut", const lowLevelMove = withoutOtherPath.get(id)![i];
endPosition: { if (lowLevelMove.movementPattern.kind === SemanticAnimationKind.PassBy
...prevStep.endPosition, && !lowLevelMove.movementPattern.otherPath) {
kind: PositionKind.Circle, throw new Error("Failed to fill in otherPath for " + id + " on hey step " + i);
which: prevStep.endPosition.which.isLeft() }
? (this.moveInterpreter.endsShoulder === Hand.Right ? CirclePosition.TopLeft : CirclePosition.BottomLeft)
: (this.moveInterpreter.endsShoulder === Hand.Right ? CirclePosition.BottomRight : CirclePosition.TopRight),
},
} }
} }
else if (!isFacingSide) {
const rico = inCenterFirst
? beenInCenter
? this.move.parameters.rico3
: this.move.parameters.rico1
: beenInCenter
? this.move.parameters.rico4
: this.move.parameters.rico2;
if (rico) { // Object was mutated.
const onLeftSide = prevStep.endPosition.which.isLeft(); return withoutOtherPath;
return { }
kind: "Ricochet",
endPosition: { return fixupHeyOtherPath(this.handleMove(({ id, startPos }) => {
...prevStep.endPosition, const endsInCircle = startPos.kind === PositionKind.Circle;
kind: PositionKind.Circle, function heyStepToPartialLowLevelMove(heyStep: HeyStep): PartialLowLevelMove & { heyStep: HeyStep } {
which: CirclePosition.fromSides(prevStep.endPosition.which.leftRightSide(), return {
// TODO might be swapped beats: heyPartBeats,
(this.moveInterpreter.endsShoulder === Hand.Left) === onLeftSide ? CircleSide.Top : CircleSide.Bottom), // TODO use circle positions on ends? ... unless hey ends in a box the gnat or similar...
facing: onLeftSide ? Facing.Left : Facing.Right, endPosition: heyStep.endPosition,
movementPattern: heyStep.kind === "StandStill" ? {
kind: SemanticAnimationKind.StandStill,
} : heyStep.kind === "Loop" ? {
// TODO Loop should probably be its own kind? Or RotateAround?
kind: SemanticAnimationKind.Linear,
minRotation: endsShoulder === Hand.Right ? +180 : -180,
} : heyStep.kind === "Ricochet" ? {
// TODO This is a hack.
kind: SemanticAnimationKind.PassBy,
around: heyStep.endPosition.which.leftRightSide(),
withHands: false,
otherPath: "Swap",
facing: "Start",
side: endsShoulder,
} : {
kind: SemanticAnimationKind.PassBy,
around: heyStep.kind === "CenterPass" ? "Center" : heyStep.endPosition.which.leftRightSide(),
withHands: false,
side: heyStep.kind === "CenterPass" ? centerShoulder : endsShoulder,
facing: "Start",
otherPath: undefined!, // Placeholder, fixup later.
},
heyStep,
};
}
function continueHey(prevStep: HeyStep, stepsLeft: number, beenInCenter: boolean): HeyStep {
// TODO Not sure why type checker requires rechecking this here.
if (move.move !== "hey") throw new Error("Unreachable.");
// Continuing hey so everyone is either passing (in center or on ends) or looping on ends.
if (prevStep.endPosition.kind === PositionKind.Circle) {
if (prevStep.endPosition.facing === prevStep.endPosition.which.facingAcross()) {
if (stepsLeft === 0) {
return {
kind: "StandStill",
endPosition: prevStep.endPosition,
}
}
return {
kind: "EndsPassIn",
endPosition: {
kind: PositionKind.ShortLines,
which: prevStep.endPosition.which.isLeft() ? ShortLinesPosition.MiddleLeft : ShortLinesPosition.MiddleRight,
facing: prevStep.endPosition.which.facingAcross(),
setOffset: prevStep.endPosition.setOffset,
lineOffset: prevStep.endPosition.lineOffset,
},
}
}
else {
if (stepsLeft === 1 && !endsInCircle) {
return {
kind: "Loop",
endPosition: {
kind: PositionKind.ShortLines,
which: prevStep.endPosition.which.isLeft() ? ShortLinesPosition.FarLeft : ShortLinesPosition.FarRight,
facing: prevStep.endPosition.which.facingAcross(),
setOffset: prevStep.endPosition.setOffset,
lineOffset: prevStep.endPosition.lineOffset,
},
}
}
return {
kind: "Loop",
endPosition: {
...prevStep.endPosition,
which: prevStep.endPosition.which.swapUpAndDown(),
facing: prevStep.endPosition.which.facingAcross()
},
}
}
}
else if (prevStep.endPosition.kind === PositionKind.ShortLines) {
const isFacingSide = prevStep.endPosition.facing === prevStep.endPosition.which.facingSide();
const inMiddle = prevStep.endPosition.which.isMiddle();
if (!inMiddle && !isFacingSide) {
return {
kind: "Loop",
endPosition: { ...prevStep.endPosition, facing: prevStep.endPosition.which.facingSide() },
}
} else if (inMiddle && isFacingSide) {
return {
kind: "EndsPassOut",
endPosition: {
...prevStep.endPosition,
kind: PositionKind.Circle,
which: prevStep.endPosition.which.isLeft()
? (endsShoulder === Hand.Right ? CirclePosition.TopLeft : CirclePosition.BottomLeft)
: (endsShoulder === Hand.Right ? CirclePosition.BottomRight : CirclePosition.TopRight),
},
}
}
else if (!isFacingSide) {
const rico = inCenterFirst
? beenInCenter
? move.parameters.rico3
: move.parameters.rico1
: beenInCenter
? move.parameters.rico4
: move.parameters.rico2;
if (rico) {
const onLeftSide = prevStep.endPosition.which.isLeft();
return {
kind: "Ricochet",
endPosition: {
...prevStep.endPosition,
kind: PositionKind.Circle,
which: CirclePosition.fromSides(prevStep.endPosition.which.leftRightSide(),
// TODO might be swapped
(endsShoulder === Hand.Left) === onLeftSide ? CircleSide.Top : CircleSide.Bottom),
facing: onLeftSide ? Facing.Left : Facing.Right,
}
}
} else {
return {
kind: "CenterPass",
endPosition: {
...prevStep.endPosition,
which: prevStep.endPosition.which.swapSides()
},
}
}
}
else {
return {
kind: inMiddle ? "EndsPassOut" : "EndsPassIn",
endPosition: {
...prevStep.endPosition,
which: prevStep.endPosition.which.swapOnSide()
},
} }
} }
} else { } else {
return { throw new Error("Unexpected PositionKind: " + (<any>prevStep.endPosition).kind);
kind: "CenterPass",
endPosition: {
...prevStep.endPosition,
which: prevStep.endPosition.which.swapSides()
},
}
} }
} }
else {
return {
kind: inMiddle ? "EndsPassOut" : "EndsPassIn",
endPosition: {
...prevStep.endPosition,
which: prevStep.endPosition.which.swapOnSide()
},
}
}
} else {
throw new Error("Unexpected PositionKind: " + (<any>prevStep.endPosition).kind);
}
}
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { const inCenterFirst = firstPassInCenter && this.findPairOpposite(this.move.parameters.who, id) !== null
return fixupHeyOtherPath(this.handleMove(({ id, startPos }) => { || this.move.parameters.who2 && this.findPairOpposite(this.move.parameters.who2, id) !== null;
const endsInCircle = startPos.kind === PositionKind.Circle;
const inCenterFirst = this.moveInterpreter.firstPassInCenter && (this.findPairOpposite(this.move.parameters.who, id) !== null)
|| !!this.move.parameters.who2 && (this.findPairOpposite(this.move.parameters.who2, id) !== null);
let firstHeyStep: HeyStep; let firstHeyStep: HeyStep;
let startingPos: SemanticPosition; let startingPos: SemanticPosition;
if (this.moveInterpreter.firstPassInCenter) { if (firstPassInCenter) {
if (startPos.kind !== PositionKind.Circle) { if (startPos.kind !== PositionKind.Circle) {
throw new Error("Hey starting in center not from circle is unsupported."); throw new Error("Hey starting in center not from circle is unsupported.");
} }
@ -298,60 +319,18 @@ class HeySingleVariant extends SingleVariantMoveInterpreter<Hey, typeof moveName
const heySteps: HeyStep[] = [firstHeyStep]; const heySteps: HeyStep[] = [firstHeyStep];
let beenInCenter = firstHeyStep.kind === "CenterPass" || firstHeyStep.kind === "Ricochet"; let beenInCenter = firstHeyStep.kind === "CenterPass" || firstHeyStep.kind === "Ricochet";
for (let i = 1; i < this.moveInterpreter.heyParts; i++) { for (let i = 1; i < heyParts; i++) {
const nextHeyStep = this.continueHey(heySteps[i - 1], this.moveInterpreter.heyParts - i - 1, {beenInCenter, endsInCircle, inCenterFirst}); const isLast = i === heyParts - 1;
const nextHeyStep = continueHey(heySteps[i - 1], heyParts - i - 1, beenInCenter);
beenInCenter ||= nextHeyStep.kind === "CenterPass" || nextHeyStep.kind === "Ricochet"; beenInCenter ||= nextHeyStep.kind === "CenterPass" || nextHeyStep.kind === "Ricochet";
heySteps.push(nextHeyStep); heySteps.push(nextHeyStep);
} }
return this.combine(heySteps.map(s => this.heyStepToPartialLowLevelMove(s)), { ...startingPos, hands: undefined }); return this.combine(heySteps.map(heyStepToPartialLowLevelMove), { ...startingPos, hands: undefined });
})); }));
} }
} }
class Hey extends MoveInterpreter<typeof moveName> { class Hey extends MoveInterpreter<typeof moveName> {
public readonly heyParts: number;
public readonly heyPartBeats: number;
public readonly firstPassInCenter: boolean;
public readonly centerShoulder: Hand;
public readonly endsShoulder: Hand;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) {
super(args);
if (this.move.parameters.dir !== "across") {
throw new Error("Unsupported hey direction: " + this.move.parameters.dir);
}
if (typeof this.move.parameters.until === "string") {
switch (this.move.parameters.until) {
case "half":
this.heyParts = 4;
break;
case "full":
this.heyParts = 8;
break;
// TODO Are these right? Can it sometimes be 1 or 3 instead of 2?
case "less than half":
this.heyParts = 2;
break;
case "between half and full":
this.heyParts = 6;
default:
throw new Error("Unsupported hey 'until': " + this.move.parameters.until);
}
}
else {
// TODO Is this actually this simple?
this.heyParts = this.move.parameters.until.time === 1 ? 2 : 6;
//throw new Error("Unsupported hey 'until': " + this.move.parameters.until.dancer + " time " + this.move.parameters.until.time);
}
this.heyPartBeats = this.move.beats / this.heyParts;
// TODO is this right?
this.firstPassInCenter = dancerIsPair(this.move.parameters.who);
this.centerShoulder = this.firstPassInCenter === this.move.parameters.shoulder ? Hand.Right : Hand.Left;
this.endsShoulder = this.centerShoulder.opposite();
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new HeySingleVariant(this, startingPos); return new HeySingleVariant(this, startingPos);
} }

View File

@ -1,4 +1,4 @@
import { SemanticPosition, PositionKind, DancerDistance } from "../interpreterCommon.js"; import { SemanticPosition, PositionKind } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js"; import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
@ -12,10 +12,6 @@ class MadRobinSingleVariant extends SingleVariantMoveInterpreter<MadRobin, typeo
} }
return this.handleCircleMove(({ id, startPos }) => { return this.handleCircleMove(({ id, startPos }) => {
if (startPos.dancerDistance && startPos.dancerDistance !== DancerDistance.Normal) {
throw new Error(this.move.move + " can only start in normal DancerDistance.");
}
// Read who of mad robin to decide direction. // Read who of mad robin to decide direction.
const madRobinClockwise: boolean = (this.findPairOpposite(this.move.parameters.who, id) !== null) === startPos.which.isOnLeftLookingAcross(); const madRobinClockwise: boolean = (this.findPairOpposite(this.move.parameters.who, id) !== null) === startPos.which.isOnLeftLookingAcross();

View File

@ -1,71 +1,43 @@
import { HandConnection, HandTo, BalanceWeight, PositionKind, ShortLinesPosition, SemanticPosition } from "../interpreterCommon.js"; import { HandConnection, HandTo, BalanceWeight } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, Variant, VariantCollection, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName = "pull by dancers"; const moveName: Move["move"] = "pull by dancers";
class PullByDancersSingleVariant extends SingleVariantMoveInterpreter<PullByDancers, typeof moveName> { class PullByDancersSingleVariant extends SingleVariantMoveInterpreter<PullByDancers, typeof moveName> {
moveAsVariants(previousMoveVariant: string): VariantCollection { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
const res = new Map<string, Variant>();
for (const toShortLines of [true, false]) {
try {
res.set(toShortLines ? "ToShortLines" : "FullPullBy", {
lowLevelMoves: this.moveAsLowLevelMovesTo(toShortLines),
previousMoveVariant
});
}
catch { }
}
return res;
}
moveAsLowLevelMovesTo(toShortLines: boolean): LowLevelMovesForAllDancers {
// TODO Might make sense to think of pull by as not a full swap? // 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 // e.g., in Blue and Green Candles, it's treated as only getting to
// ShortLinesPosition.Middle* before doing an allemande. // ShortLinesPosition.Middle* before doing an allemande.
return this.handlePairedMove(this.move.parameters.who, ({ startPos, around, withPos }) => { return this.handlePairedMove(this.move.parameters.who, ({ startPos, around, withPos }) => {
if (toShortLines) { const hand = this.move.parameters.hand ? Hand.Right : Hand.Left;
if (startPos.kind !== PositionKind.Circle) { const balanceBeats = this.move.parameters.bal
throw new Error("ToShortLines variant of " + this.move.move + " only makes sense starting from a circle."); ? this.move.beats > 4
} ? this.move.beats - 4
} : 2
: 0;
const balancePartBeats = balanceBeats / 2;
const pullBeats = this.move.beats - balanceBeats;
// TODO Adjust facing? // TODO Adjust facing?
const startPosition = { const startPosition = {
...startPos, ...startPos,
hands: new Map<Hand, HandConnection>([ hands: new Map<Hand, HandConnection>([
[ [
this.moveInterpreter.hand, hand,
{ hand: this.moveInterpreter.hand, to: around === "Center" ? HandTo.DiagonalAcrossCircle : HandTo.DancerForward } { hand, to: around === "Center" ? HandTo.DiagonalAcrossCircle : HandTo.DancerForward }
]]), ]])
facing: startPos.which.facingAcross(),
}; };
const endPos: SemanticPosition = toShortLines
? {
...withPos,
hands: undefined,
facing: startPosition.facing,
kind: PositionKind.ShortLines,
which: ShortLinesPosition.fromSide(withPos.which.leftRightSide(), "Middle"),
longLines: undefined, // Needed to satisfy type-checker.
}
: {
...withPos,
hands: undefined,
facing: startPosition.facing,
};
const passBy: PartialLowLevelMove = { const passBy: PartialLowLevelMove = {
beats: this.moveInterpreter.pullBeats, beats: pullBeats,
endPosition: endPos, endPosition: { ...withPos, facing: startPos.facing },
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.PassBy, kind: SemanticAnimationKind.PassBy,
around, around,
side: this.moveInterpreter.hand, side: hand,
withHands: true, withHands: true,
facing: "Start", facing: "Start",
otherPath: "Swap", otherPath: "Swap",
@ -75,7 +47,7 @@ class PullByDancersSingleVariant extends SingleVariantMoveInterpreter<PullByDanc
if (this.move.parameters.bal) { if (this.move.parameters.bal) {
return this.combine([ return this.combine([
{ {
beats: this.moveInterpreter.balancePartBeats, beats: balancePartBeats,
endPosition: { endPosition: {
...startPosition, ...startPosition,
balance: BalanceWeight.Forward, balance: BalanceWeight.Forward,
@ -85,7 +57,7 @@ class PullByDancersSingleVariant extends SingleVariantMoveInterpreter<PullByDanc
} }
}, },
{ {
beats: this.moveInterpreter.balancePartBeats, beats: balancePartBeats,
endPosition: { endPosition: {
...startPosition, ...startPosition,
balance: BalanceWeight.Backward, balance: BalanceWeight.Backward,
@ -98,45 +70,11 @@ class PullByDancersSingleVariant extends SingleVariantMoveInterpreter<PullByDanc
} else { } else {
return this.combine([passBy], startPosition); return this.combine([passBy], startPosition);
} }
}, !toShortLines ? undefined : ({startPos}) => {
return this.combine([{
beats: this.move.beats,
movementPattern: {
kind: SemanticAnimationKind.Linear,
},
endPosition: {
...startPos,
kind: PositionKind.ShortLines,
which: ShortLinesPosition.fromSide(startPos.which.leftRightSide(), "Far"),
facing: startPos.which.facingAcross(),
hands: undefined,
longLines: undefined,
}
}], startPos);
}); });
} }
} }
class PullByDancers extends MoveInterpreter<typeof moveName> { class PullByDancers extends MoveInterpreter<typeof moveName> {
public readonly hand: Hand;
public readonly balancePartBeats: number;
public readonly pullBeats: number;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) {
super(args);
this.hand = this.move.parameters.hand ? Hand.Right : Hand.Left;
const balanceBeats = this.move.parameters.bal
? this.move.beats > 4
? this.move.beats - 4
: this.move.beats > 2
? 2
: this.move.beats / 2
: 0;
this.balancePartBeats = balanceBeats / 2;
this.pullBeats = this.move.beats - balanceBeats;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new PullByDancersSingleVariant(this, startingPos); return new PullByDancersSingleVariant(this, startingPos);
} }

View File

@ -9,7 +9,7 @@ const moveName: Move["move"] = "roll away";
class RollAwaySingleVariant extends SingleVariantMoveInterpreter<RollAway, typeof moveName> { class RollAwaySingleVariant extends SingleVariantMoveInterpreter<RollAway, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
// TODO maybe can roll away in short lines? // TODO maybe can roll away in short lines?
return this.handleCirclePairedMove(this.move.parameters.whom, ({ id, startPos, withPos }) => { return this.handleCirclePairedMove(this.move.parameters.who, ({ id, startPos, withPos }) => {
let isRoller: boolean; let isRoller: boolean;
switch (this.move.parameters.who) { switch (this.move.parameters.who) {
case "gentlespoons": case "gentlespoons":

View File

@ -1,14 +1,24 @@
import { PositionKind, SemanticPosition, Facing, BalanceWeight, handsInLine, CircleSide, handsInLongLines } from "../interpreterCommon.js"; import { PositionKind, SemanticPosition, Facing, BalanceWeight, handsInLine } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName = "Rory O'More"; const moveName: Move["move"] = "Rory O'More";
class RoryOMoreSingleVariant extends SingleVariantMoveInterpreter<RoryOMore, typeof moveName> { class RoryOMoreSingleVariant extends SingleVariantMoveInterpreter<RoryOMore, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
if (this.move.parameters.who !== "everyone") {
throw new Error(this.move.move + " that doesn't include everyone is unsupported.");
}
// TODO Could be in long or short lines. // TODO Could be in long or short lines.
const roryDir = this.move.parameters.slide ? Hand.Left : Hand.Right;
const balBeats = this.move.parameters.bal ? this.move.beats / 2 : 0;
const balPartBeats = balBeats / 2;
const roryBeats = this.move.beats - balBeats;
return this.handleMove(({ startPos }) => { return this.handleMove(({ startPos }) => {
const isShortLines: boolean = startPos.kind === PositionKind.ShortLines;
const startingPos: SemanticPosition = { const startingPos: SemanticPosition = {
...startPos, ...startPos,
hands: handsInLine({ wavy: true, which: startPos.which, facing: startPos.facing }) hands: handsInLine({ wavy: true, which: startPos.which, facing: startPos.facing })
@ -17,61 +27,38 @@ class RoryOMoreSingleVariant extends SingleVariantMoveInterpreter<RoryOMore, typ
let endPos: SemanticPosition; let endPos: SemanticPosition;
if (startPos.kind === PositionKind.ShortLines) { if (startPos.kind === PositionKind.ShortLines) {
if (startPos.facing !== Facing.Up && startPos.facing !== Facing.Down) { if (startPos.facing !== Facing.Up && startPos.facing !== Facing.Down) {
throw new Error("To be in short wavy lines, must be facing up or down, not " + startPos.facing); throw new Error("To be in wavy lines, must be facing up or down, not " + startPos.facing);
}
const { newPos: endWhich, wrap } = startPos.which.shiftWithWrap(this.moveInterpreter.dir, startPos.facing);
const endLineOffset = !wrap
? startPos.lineOffset
: (startPos.lineOffset ?? 0) + wrap;
if (wrap) {
startingPos.hands = handsInLongLines(true)
} }
const endWhich = startPos.which.shift(roryDir, startPos.facing);
endPos = { endPos = {
...startPos, ...startPos,
which: endWhich, which: endWhich,
hands: handsInLine({ wavy: true, which: endWhich, facing: startPos.facing }), hands: handsInLine({ wavy: true, which: endWhich, facing: startPos.facing })
lineOffset: endLineOffset,
}; };
} else { } else {
if (startPos.facing !== Facing.Left && startPos.facing !== Facing.Right) { throw new Error(this.move.move + " is currently only supported in short lines.");
throw new Error("To be in long wavy lines, must be facing left or right, not " + startPos.facing);
}
const endWhich = startPos.which.swapUpAndDown();
const sideTowards = (startPos.facing === Facing.Right)
=== (this.moveInterpreter.dir === Hand.Left)
? CircleSide.Bottom
: CircleSide.Top;
const endSetOffset = sideTowards === endWhich.topBottomSide()
? startPos.setOffset
: (startPos.setOffset ?? 0) + (sideTowards === CircleSide.Bottom ? +1 : -1);
endPos = {
...startPos,
which: endWhich,
hands: handsInLine({ wavy: true, which: endWhich, facing: startPos.facing }),
setOffset: endSetOffset,
};
} }
const maybeBalance: PartialLowLevelMove[] = (this.move.parameters.bal ? [ const maybeBalance: PartialLowLevelMove[] = (this.move.parameters.bal ? [
{ {
beats: this.moveInterpreter.balPartBeats, beats: balPartBeats,
endPosition: { ...startingPos, balance: this.moveInterpreter.dir === Hand.Left ? BalanceWeight.Left : BalanceWeight.Right }, endPosition: { ...startingPos, balance: roryDir === Hand.Left ? BalanceWeight.Left : BalanceWeight.Right },
movementPattern: { kind: SemanticAnimationKind.Linear }, movementPattern: { kind: SemanticAnimationKind.Linear },
}, },
{ {
beats: this.moveInterpreter.balPartBeats, beats: balPartBeats,
endPosition: { ...startingPos, balance: this.moveInterpreter.dir === Hand.Left ? BalanceWeight.Right : BalanceWeight.Left }, endPosition: { ...startingPos, balance: roryDir === Hand.Left ? BalanceWeight.Right : BalanceWeight.Left },
movementPattern: { kind: SemanticAnimationKind.Linear }, movementPattern: { kind: SemanticAnimationKind.Linear },
}, },
] : []); ] : []);
return this.combine([...maybeBalance, return this.combine([...maybeBalance,
{ {
beats: this.moveInterpreter.roryBeats, beats: roryBeats,
endPosition: endPos, endPosition: endPos,
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.Linear, kind: SemanticAnimationKind.Linear,
minRotation: this.moveInterpreter.dir === Hand.Right ? +360 : -360, minRotation: roryDir === Hand.Right ? +360 : -360,
handsDuring: "None", handsDuring: "None",
}, },
} }
@ -81,23 +68,6 @@ class RoryOMoreSingleVariant extends SingleVariantMoveInterpreter<RoryOMore, typ
} }
class RoryOMore extends MoveInterpreter<typeof moveName> { class RoryOMore extends MoveInterpreter<typeof moveName> {
public readonly dir: Hand;
public readonly balPartBeats: number;
public readonly roryBeats: number;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) {
super(args);
if (this.move.parameters.who !== "everyone") {
throw new Error(this.move.move + " that doesn't include everyone is unsupported.");
}
this.dir = this.move.parameters.slide ? Hand.Left : Hand.Right;
const balBeats = this.move.parameters.bal ? this.move.beats / 2 : 0;
this.balPartBeats = balBeats / 2;
this.roryBeats = this.move.beats - balBeats;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new RoryOMoreSingleVariant(this, startingPos); return new RoryOMoreSingleVariant(this, startingPos);
} }

View File

@ -1,17 +1,24 @@
import { DancerDistance, handToDancerToSideInCircleFacingAcross } from "../interpreterCommon.js"; import { DancerDistance, handToDancerToSideInCircleFacingAcross } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName = "star promenade"; const moveName: Move["move"] = "star promenade";
class StarPromenadeSingleVariant extends SingleVariantMoveInterpreter<StarPromenade, typeof moveName> { class StarPromenadeSingleVariant extends SingleVariantMoveInterpreter<StarPromenade, typeof moveName> {
moveAsLowLevelMoves(): LowLevelMovesForAllDancers { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
const starPromenadeHand = this.move.parameters.hand ? Hand.Right : Hand.Left;
const starPromenadeSwap = (this.move.parameters.circling % 360) === 180;
if (!starPromenadeSwap && (this.move.parameters.circling % 360 !== 0)) {
throw new Error(this.move.move + " circling by not a multiple of 180 degrees is unsupported.");
}
// TODO start promenade hands/show dancers close // TODO start promenade hands/show dancers close
return this.handleCircleMove(({ id, startPos }) => { return this.handleCircleMove(({ id, startPos }) => {
const inCenter = this.findPairOpposite(this.move.parameters.who, id) !== null; const inCenter = this.findPairOpposite(this.move.parameters.who, id) !== null;
// TODO Actually, does star promenade end facing out and butterfly whirl swaps? // TODO Actually, does star promenade end facing out and butterfly whirl swaps?
const endWhich = this.moveInterpreter.swap ? startPos.which.swapDiagonal() : startPos.which; const endWhich = starPromenadeSwap ? startPos.which.swapDiagonal() : startPos.which;
const endFacing = endWhich.facingAcross(); const endFacing = endWhich.facingAcross();
return this.combine([{ return this.combine([{
beats: this.move.beats, beats: this.move.beats,
@ -22,13 +29,11 @@ class StarPromenadeSingleVariant extends SingleVariantMoveInterpreter<StarPromen
dancerDistance: DancerDistance.Compact, dancerDistance: DancerDistance.Compact,
// TODO Perhaps different hands indication for "scooped"? // TODO Perhaps different hands indication for "scooped"?
hands: handToDancerToSideInCircleFacingAcross(endWhich), hands: handToDancerToSideInCircleFacingAcross(endWhich),
longLines: undefined,
balance: undefined,
}, },
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.RotateAround, kind: SemanticAnimationKind.RotateAround,
around: "Center", around: "Center",
byHand: inCenter ? this.moveInterpreter.hand : undefined, byHand: inCenter ? starPromenadeHand : undefined,
close: inCenter, close: inCenter,
minAmount: this.move.parameters.hand ? this.move.parameters.circling : -this.move.parameters.circling, minAmount: this.move.parameters.hand ? this.move.parameters.circling : -this.move.parameters.circling,
} }
@ -38,23 +43,6 @@ class StarPromenadeSingleVariant extends SingleVariantMoveInterpreter<StarPromen
} }
class StarPromenade extends MoveInterpreter<typeof moveName> { class StarPromenade extends MoveInterpreter<typeof moveName> {
public readonly hand: Hand;
public readonly swap: boolean;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) {
super(args);
this.hand = this.move.parameters.hand ? Hand.Right : Hand.Left;
this.swap = (this.move.parameters.circling % 360) === 180;
if (!this.swap && (this.move.parameters.circling % 360 !== 0)) {
throw new Error(this.move.move + " circling by not a multiple of 180 degrees is unsupported.");
}
}
override allowStartingLongLines(): boolean {
return true;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new StarPromenadeSingleVariant(this, startingPos); return new StarPromenadeSingleVariant(this, startingPos);
} }

View File

@ -1,77 +1,39 @@
import { CoupleRole, DanceRole } from "../danceCommon.js"; import { CoupleRole, DanceRole } from "../danceCommon.js";
import { LongLines, CircleSide, SemanticPosition, CirclePosition, Facing, PositionKind, HandConnection, HandTo, ShortLinesPosition, handsInLine, BalanceWeight, DancerDistance, isFacingUpOrDown, isLeftRightCircleSide } from "../interpreterCommon.js"; import { LongLines, CircleSide, SemanticPosition, CirclePosition, Facing, PositionKind, HandConnection, HandTo, ShortLinesPosition, handsInLine, BalanceWeight, DancerDistance } from "../interpreterCommon.js";
import { Move } from "../libfigureMapper.js";
import { SemanticAnimationKind } from "../lowLevelMove.js"; import { SemanticAnimationKind } from "../lowLevelMove.js";
import { Hand } from "../rendererConstants.js"; import { Hand } from "../rendererConstants.js";
import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, MoveInterpreterCtorArgs, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, Variant, VariantCollection, moveInterpreters } from "./_moveInterpreter.js"; import { ISingleVariantMoveInterpreter, LowLevelMovesForAllDancers, MoveInterpreter, PartialLowLevelMove, SemanticPositionsForAllDancers, SingleVariantMoveInterpreter, moveInterpreters } from "./_moveInterpreter.js";
const moveName = "swing"; const moveName: Move["move"] = "swing";
/* Possible swings:
* - default: start on left/right side, end facing across
* - give and take: start in one corner, end facing across
* - contra corners: just one pair, start on top/bottom side, end facing in to new circle
* - to short lines: start on left/right side, end facing up/down in short lines
* - same role: larks/robins go into center, end facing out
* - join short lines: just one pair in center, joins hands in short lines after
* - ... ?
*/
interface SwingEnd {
facing: "Across" | Facing.Up | Facing.Down,
close: boolean,
}
function swingEndString(swingEnd: SwingEnd): string {
return swingEnd.facing + (swingEnd.close ? "Close" : "");
}
const swingEndValues: SwingEnd[] = [
{ facing: "Across", close: false},
{ facing: "Across", close: true},
{ facing: Facing.Up, close: false},
{ facing: Facing.Up, close: true},
{ facing: Facing.Down, close: false},
{ facing: Facing.Down, close: true},
];
class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof moveName> { class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof moveName> {
moveAsVariants(previousMoveVariant: string): VariantCollection { moveAsLowLevelMoves(): LowLevelMovesForAllDancers {
const res = new Map<string, Variant>(); // TODO Use variants instead of nextMove
const nextMove = this.moveInterpreter.nextMove;
for (const swingEnd of swingEndValues) {
try {
res.set(swingEndString(swingEnd), {
lowLevelMoves: this.moveAsLowLevelMovesFacing(swingEnd),
previousMoveVariant
});
}
catch { }
}
return res;
}
moveAsLowLevelMovesFacing(swingEnd: SwingEnd): LowLevelMovesForAllDancers {
return this.handlePairedMove(this.move.parameters.who, ({ id, startPos, around, withId, withPos }) => { return this.handlePairedMove(this.move.parameters.who, ({ id, startPos, around, withId, withPos }) => {
if (startPos.longLines && startPos.longLines !== LongLines.Near) { // TODO swing can start from non-circle positions.
throw new Error(this.move.move + " shouldn't start with long lines " + startPos.longLines); // TODO swing end is only in notes / looking at next move.
}
// TODO better way to detect swing end?
// TODO more structured way to do this than enumerating next moves here?
// maybe instead of nextMove an optional endPosition for fixing up positions?
// ... but then every move would have to handle that...
const afterTake = startPos.longLines === LongLines.Near || withPos.longLines === LongLines.Near; const afterTake = startPos.longLines === LongLines.Near || withPos.longLines === LongLines.Near;
const toShortLines = nextMove.move === "down the hall" || nextMove.move === "up the hall";
if (around === "Center" && swingEnd.facing === "Across") { const endFacingAcross = (around === CircleSide.Left || around === CircleSide.Right) && !toShortLines;
throw new Error("Cannot end a swing around the center facing across.");
}
const toShortLines = around === "Center" || (isLeftRightCircleSide(around) && isFacingUpOrDown(swingEnd.facing));
const startWhich = startPos.which; const startWhich = startPos.which;
const startPosition: SemanticPosition = { const startPosition: SemanticPosition = {
...startPos, ...startPos,
facing: isLeftRightCircleSide(around) facing: around === CircleSide.Left || CircleSide.Right
? (startWhich instanceof CirclePosition ? (startWhich instanceof CirclePosition
? afterTake ? afterTake
? startPos.longLines === LongLines.Near ? startWhich.facingOut() : startWhich.facingAcross() ? startPos.longLines === LongLines.Near ? startWhich.facingOut() : startWhich.facingAcross()
: startWhich.facingUpOrDown() : (startWhich.topBottomSide() === CircleSide.Bottom ? Facing.Up : Facing.Down)
: startWhich.facingSide()) : startWhich.facingSide())
: startWhich.facingAcross(), : (startWhich.isLeft() ? Facing.Right : Facing.Left),
}; };
const swingRole = id.danceRole != withId.setIdentity.danceRole const swingRole = id.danceRole != withId.setIdentity.danceRole
@ -85,43 +47,71 @@ class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof move
? (withId.relativeLine > 0 ? DanceRole.Lark : DanceRole.Robin) ? (withId.relativeLine > 0 ? DanceRole.Lark : DanceRole.Robin)
: /* should be unreachable as this means withId is equal to id */ DanceRole.Lark; : /* should be unreachable as this means withId is equal to id */ DanceRole.Lark;
const endFacing = swingEnd.facing === "Across" ? startWhich.facingAcross() : swingEnd.facing; // TODO This assumes swing around right/left, not center or top/bottom.
const endWhich = toShortLines && /*always true, just for type-checker*/isFacingUpOrDown(swingEnd.facing) let endPosition: SemanticPosition;
? ShortLinesPosition.fromSwing(around, swingRole, swingEnd.facing) if (endFacingAcross) {
: CirclePosition.fromSwing(/*always true, just for type-checker*/<CircleSide>around, swingRole, swingEnd.facing) endPosition = {
...startPos,
const endHands = toShortLines kind: PositionKind.Circle,
? handsInLine({ wavy: false, which: endWhich, facing: endFacing }) which: startWhich instanceof CirclePosition
: new Map<Hand, HandConnection>([swingRole === DanceRole.Lark ? (startWhich.isOnLeftLookingAcross() === (swingRole === DanceRole.Lark)
? startWhich
: startWhich.swapUpAndDown())
: (startWhich.isLeft()
? (swingRole === DanceRole.Lark ? CirclePosition.BottomLeft : CirclePosition.TopLeft)
: (swingRole === DanceRole.Lark ? CirclePosition.TopRight : CirclePosition.BottomRight)),
facing: startWhich.leftRightSide() === CircleSide.Left ? Facing.Right : Facing.Left,
balance: undefined,
dancerDistance: undefined,
longLines: undefined,
hands: new Map<Hand, HandConnection>([swingRole === DanceRole.Lark
? [Hand.Right, { to: HandTo.DancerRight, hand: Hand.Left }] ? [Hand.Right, { to: HandTo.DancerRight, hand: Hand.Left }]
: [Hand.Left, { to: HandTo.DancerLeft, hand: Hand.Right }]]); : [Hand.Left, { to: HandTo.DancerLeft, hand: Hand.Right }]]),
};
} else if (toShortLines) {
const endFacing = nextMove.move === "down the hall" !== (nextMove.parameters.facing === "backward")
? Facing.Down
: Facing.Up;
const endWhich = startWhich.isLeft()
? ((endFacing === Facing.Down) === (swingRole === DanceRole.Lark) ? ShortLinesPosition.FarLeft : ShortLinesPosition.MiddleLeft)
: ((endFacing === Facing.Down) === (swingRole === DanceRole.Lark) ? ShortLinesPosition.MiddleRight : ShortLinesPosition.FarRight)
endPosition = {
...startPos,
kind: PositionKind.ShortLines,
which: endWhich,
facing: endFacing,
balance: undefined,
dancerDistance: undefined,
longLines: undefined,
hands: handsInLine({ wavy: false, which: endWhich, facing: endFacing }),
};
}
else {
// TODO Need to figure out the logic of knowing if this should be facing up or down.
// Probably based on knowing Ones vs. Twos? Also then the not-participating-dancers need their
// "standing still" to update that they are in a new set...
//throw new Error("Swing to new circle currently unsupported.");
endPosition = {
// end not facing across or in short lines, so transitioning to new circle like in many contra corners dances.
...startPos,
};
}
const partialEndPosition = { const swingBeats = this.move.parameters.prefix === "none" ? this.move.beats
...startPos, : this.move.parameters.prefix === "balance"
facing: endFacing, ? this.move.beats > 8 ? 8 : this.move.beats - 4
balance: undefined, : this.move.parameters.prefix === "meltdown"
dancerDistance: swingEnd.close ? DancerDistance.Compact : undefined, ? this.move.beats - 4
longLines: undefined, : (() => { throw "Unknown swing prefix: " + this.move.parameters.prefix })();
hands: endHands,
}
let endPosition: SemanticPosition = toShortLines ? {
...partialEndPosition,
kind: PositionKind.ShortLines,
which: <ShortLinesPosition>endWhich,
} : {
...partialEndPosition,
kind: PositionKind.Circle,
which: <CirclePosition>endWhich,
}
const swing: PartialLowLevelMove = { const swing: PartialLowLevelMove = {
beats: this.moveInterpreter.swingBeats, beats: swingBeats,
endPosition: endPosition, endPosition: endPosition,
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.Swing, kind: SemanticAnimationKind.Swing,
minAmount: 360, minAmount: 360,
around, around,
endFacing, endFacing: startWhich.leftRightSide() === CircleSide.Left ? Facing.Right : Facing.Left,
swingRole, swingRole,
afterTake, afterTake,
}, },
@ -131,6 +121,8 @@ class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof move
case "none": case "none":
return this.combine([swing,], startPosition); return this.combine([swing,], startPosition);
case "balance": case "balance":
// TODO Right length for balance?
const balancePartBeats = this.move.beats > 8 ? (this.move.beats - 8) / 2 : 2;
const startWithBalHands = { const startWithBalHands = {
...startPosition, ...startPosition,
hands: new Map<Hand, HandConnection>([ hands: new Map<Hand, HandConnection>([
@ -150,13 +142,13 @@ class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof move
}; };
return this.combine([ return this.combine([
{ {
beats: this.moveInterpreter.balancePartBeats, beats: balancePartBeats,
startPosition: startWithBalHands, startPosition: startWithBalHands,
endPosition: balForwardPos, endPosition: balForwardPos,
movementPattern: { kind: SemanticAnimationKind.Linear, }, movementPattern: { kind: SemanticAnimationKind.Linear, },
}, },
prevEnd => ({ prevEnd => ({
beats: this.moveInterpreter.balancePartBeats, beats: balancePartBeats,
endPosition: { endPosition: {
...prevEnd, ...prevEnd,
balance: BalanceWeight.Backward, balance: BalanceWeight.Backward,
@ -166,9 +158,10 @@ class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof move
swing, swing,
], startPosition); ], startPosition);
case "meltdown": case "meltdown":
const meltdownBeats = 4; // TODO right number here?
return this.combine([ return this.combine([
prevEnd => ({ prevEnd => ({
beats: this.moveInterpreter.meltdownBeats, beats: meltdownBeats,
endPosition: { ...prevEnd, dancerDistance: DancerDistance.Compact }, endPosition: { ...prevEnd, dancerDistance: DancerDistance.Compact },
movementPattern: { movementPattern: {
kind: SemanticAnimationKind.RotateAround, kind: SemanticAnimationKind.RotateAround,
@ -186,53 +179,6 @@ class SwingSingleVariant extends SingleVariantMoveInterpreter<Swing, typeof move
} }
class Swing extends MoveInterpreter<typeof moveName> { class Swing extends MoveInterpreter<typeof moveName> {
public readonly swingBeats: number;
public readonly balancePartBeats: number;
public readonly meltdownBeats: number;
constructor(args: MoveInterpreterCtorArgs<typeof moveName>) {
super(args);
switch(this.move.parameters.prefix) {
case "none":
this.balancePartBeats = 0;
this.meltdownBeats = 0;
this.swingBeats = this.move.beats;
break;
case "balance":
this.meltdownBeats = 0;
this.balancePartBeats = this.move.beats > 8
? (this.move.beats - 8) / 2
: this.move.beats > 4
? 2
: this.move.beats / 4;
this.swingBeats = this.move.beats - this.balancePartBeats * 2;
break;
case "meltdown":
this.balancePartBeats = 0;
this.meltdownBeats = this.move.beats >= 8 ? 4 : this.move.beats / 2;
this.swingBeats = this.move.beats - this.meltdownBeats;
break;
default:
throw new Error ("Unknown swing prefix: " + this.move.parameters.prefix);
}
this.swingBeats = this.move.parameters.prefix === "none" ? this.move.beats
: this.move.parameters.prefix === "balance"
? this.move.beats > 8 ? 8 : this.move.beats - 4
: this.move.parameters.prefix === "meltdown"
? this.move.beats - 4
: (() => { throw "Unknown swing prefix: " + this.move.parameters.prefix })();
}
override allowStartingClose(): boolean {
return true;
}
override allowStartingLongLines(): boolean {
// Long lines is used for LongLines.Near after give and take.
return true;
}
buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter { buildSingleVariantMoveInterpreter(startingPos: SemanticPositionsForAllDancers): ISingleVariantMoveInterpreter {
return new SwingSingleVariant(this, startingPos); return new SwingSingleVariant(this, startingPos);
} }