Skip to content

Commit

Permalink
hiscore on clearance
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Nov 17, 2023
1 parent 573f3f5 commit 35eb26b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 27 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@testing-library/dom": "^9.3.3",
"@types/chai": "^4.3.10",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"@types/node": "^20.9.1",
"@types/three": "^0.158.2",
"chai": "^4.3.10",
"ini": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/container/browsercontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class BrowserContainer {
startReplay(replay) {
this.breakState = this.parse(decodeURIComponent(replay))
console.log(this.breakState)
if (Date.now() - this.breakState.now < 5000) {
if (Date.now() - this.breakState.now < 500000) {
console.log("upload")
this.offerUpload()
}
Expand Down
4 changes: 3 additions & 1 deletion src/controller/rules/nineball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class NineBall implements Rules {
}

startTurn() {
// not used
this.previousBreak = this.currentBreak
this.currentBreak = 0
}

nextCandidateBall() {
Expand Down Expand Up @@ -80,6 +81,7 @@ export class NineBall implements Rules {
return new WatchAim(this.container)
}
if (Outcome.isBallPottedNoFoul(table.cueball, outcome)) {
this.currentBreak += Outcome.potCount(outcome)
this.container.sound.playSuccess(table.inPockets())
if (this.isEndOfGame(outcome)) {
this.container.eventQueue.push(new ChatEvent(null, `game over`))
Expand Down
13 changes: 5 additions & 8 deletions src/events/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Recorder {
container: Container
shots: GameEvent[] = []
states: number[][] = []
start = Date.now()
breakStart: number | undefined
breakStartTime
replayUrl
Expand All @@ -34,7 +35,7 @@ export class Recorder {
}

wholeGame() {
return this.state(this.states[0], this.shots)
return this.state(this.states[0], this.shots, this.start, 0, true)
}

last() {
Expand Down Expand Up @@ -62,13 +63,14 @@ export class Recorder {
return undefined
}

private state(init, events, start = 0, score = 0) {
private state(init, events, start = 0, score = 0, wholeGame = false) {
return {
init: init,
shots: events,
start: start,
now: Date.now(),
score: score,
wholeGame: wholeGame,
}
}

Expand Down Expand Up @@ -103,10 +105,6 @@ export class Recorder {

lastShotLink(isPartOfBreak, potCount, balls) {
const pots = potCount > 1 ? potCount - 1 : 0
const breakPoints =
this.container.rules.currentBreak > 0
? " " + this.container.rules.currentBreak
: ""

let colourString = "#000000"
if (balls.length > 0) {
Expand All @@ -115,8 +113,7 @@ export class Recorder {
})
}

const shotIcon =
"⚈".repeat(pots) + (isPartOfBreak ? "⚈" : "⚆") + breakPoints
const shotIcon = "⚈".repeat(pots) + (isPartOfBreak ? "⚈" : "⚆")
const serialisedShot = JSON.stringify(this.lastShot())
this.generateLink(shotIcon, serialisedShot, colourString)
}
Expand Down
4 changes: 0 additions & 4 deletions test/events/recorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ describe("Recorder", () => {
const event: HitEvent = new HitEvent(container.table.serialise())
recorder.record(event)
expect(recorder.wholeGame()).to.be.not.null
const replay = recorder.wholeGame()
const last = recorder.lastShot()
last.now = replay.now
expect(JSON.stringify(last)).to.equals(JSON.stringify(replay))
done()
})

Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,10 @@
dependencies:
"@types/node" "*"

"@types/node@*", "@types/node@^20.9.0":
version "20.9.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.0.tgz#bfcdc230583aeb891cf51e73cfdaacdd8deae298"
integrity sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==
"@types/node@*", "@types/node@^20.9.1":
version "20.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.1.tgz#9d578c610ce1e984adda087f685ace940954fe19"
integrity sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -1578,9 +1578,9 @@ camelcase@^6.0.0, camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001541:
version "1.0.30001562"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001562.tgz#9d16c5fd7e9c592c4cd5e304bc0f75b0008b2759"
integrity sha512-kfte3Hym//51EdX4239i+Rmp20EsLIYGdPkERegTgU19hQWCRhsRFGKHTliUlsry53tv17K7n077Kqa0WJU4ng==
version "1.0.30001563"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001563.tgz#aa68a64188903e98f36eb9c56e48fba0c1fe2a32"
integrity sha512-na2WUmOxnwIZtwnFI2CZ/3er0wdNzU7hN+cPYz/z2ajHThnkWjNBOpEPP4n+4r2WPM847JaMotaJE3bnfzjyKw==

chai@^4.3.10:
version "4.3.10"
Expand Down Expand Up @@ -2029,9 +2029,9 @@ ee-first@1.1.1:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.535:
version "1.4.586"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.586.tgz#68683163ed52a111213e2482ff847e76a5c6e891"
integrity sha512-qMa+E6yf1fNQbg3G66pHLXeJUP5CCCzNat1VPczOZOqgI2w4u+8y9sQnswMdGs5m4C1rOePq37EVBr/nsPQY7w==
version "1.4.588"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.588.tgz#d553f3c008e73488fb181fdf2601fdb0b1ffbb78"
integrity sha512-soytjxwbgcCu7nh5Pf4S2/4wa6UIu+A3p03U2yVr53qGxi1/VTR3ENI+p50v+UxqqZAfl48j3z55ud7VHIOr9w==

emittery@^0.13.1:
version "0.13.1"
Expand Down

0 comments on commit 35eb26b

Please sign in to comment.