Skip to content

Commit

Permalink
fix recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Oct 22, 2023
1 parent 601f9dd commit fbd02f6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion dist/diagram.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/controller/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class Replay extends ControllerBase {
this.delay = delay
this.container.table.showTraces(true)
this.container.table.updateFromShortSerialised(this.init)
console.log(shots)
if (retry) {
const retryEvent = new BreakEvent(init, shots)
retryEvent.retry = true
Expand All @@ -38,10 +37,9 @@ export class Replay extends ControllerBase {

if (shot?.type === EventType.RERACK) {
const rerack = RerackEvent.fromJson((shot as RerackEvent).ballinfo)
console.log(rerack)
rerack.applyToController(this)
if (this.shots.length > 0) {
return this.playNextShot(delay)
this.playNextShot(delay)
}
return
}
Expand Down
7 changes: 6 additions & 1 deletion src/model/ball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ export class Ball {
}

serialise() {
return { pos: this.pos, vel: this.vel, rvel: this.rvel, state: this.state }
return {
pos: this.pos.clone(),
vel: this.vel,
rvel: this.rvel,
state: this.state,
}
}

static fromSerialised(data) {
Expand Down
19 changes: 8 additions & 11 deletions src/utils/rack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,19 @@ export class Rack {
const triangle: Vector3[] = []
const pos = new Vector3(TableGeometry.tableX / 2, 0, 0)
triangle.push(vec(pos))
//
// row 2
pos.add(this.diagonal)
triangle.push(vec(pos))
pos.sub(this.across)
triangle.push(vec(pos))
if (triangle.length === 3) {
return triangle
}

pos.add(this.diagonal).sub(this.across)
// row 3
pos.add(this.diagonal)
triangle.push(vec(pos))
pos.add(this.across)
pos.sub(this.across)
triangle.push(vec(pos))
pos.add(this.across)
pos.addScaledVector(this.across, 2)
triangle.push(vec(pos))
//
// row 4
pos.add(this.diagonal)
triangle.push(vec(pos))
pos.sub(this.across)
Expand All @@ -92,7 +89,7 @@ export class Rack {
triangle.push(vec(pos))
pos.sub(this.across)
triangle.push(vec(pos))
//
// row 5
pos.add(this.diagonal).sub(this.across)
triangle.push(vec(pos))
pos.add(this.across)
Expand All @@ -104,7 +101,7 @@ export class Rack {
pos.add(this.across)
triangle.push(vec(pos))

return triangle.slice(0, 3)
return triangle.slice(0, 4)
}

static rerack(key: Ball, table: Table) {
Expand Down
16 changes: 11 additions & 5 deletions test/rules/fourteenone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("FourteenOne", () => {
})

it("Fourteenone has 16 balls", (done) => {
expect(container.table.balls).to.be.length(4)
expect(container.table.balls).to.be.length(5)
done()
})

Expand All @@ -66,8 +66,9 @@ describe("FourteenOne", () => {
balls[i].pos.copy(PocketGeometry.pockets.pocketS.pocket.pos)
balls[i].state = State.InPocket
}
balls[0].pos.copy(new Vector3(0, edge + R * 2, 0))
balls[1].pos.copy(new Vector3(0, edge, 0))
balls[0].pos.copy(new Vector3(0, edge + R * 4.2, 0))
balls[1].pos.copy(new Vector3(0, edge + R * 2.1, 0))
balls[2].pos.copy(new Vector3(0, edge, 0))
}

function playShotWaitForOutcome() {
Expand Down Expand Up @@ -117,13 +118,18 @@ describe("FourteenOne", () => {
expect(watchEvent.json.rerack).to.be.true
expect(container.recoder.shots[1].type).to.be.equal("RERACK")

// play second hit (cueball into pocket)
const before = JSON.stringify(container.recoder.shots[1])

// play second pot
container.advance(1)
container.processEvents()
playShotWaitForOutcome()
container.advance(1)
container.processEvents()
expect(container.controller).to.be.an.instanceof(PlaceBall)
expect(container.controller).to.be.an.instanceof(Aim)

const after = JSON.stringify(container.recoder.shots[1])
expect(before).to.be.equal(after)
done()
})
})

0 comments on commit fbd02f6

Please sign in to comment.