Skip to content

Commit

Permalink
Merge pull request #50 from bownie/master
Browse files Browse the repository at this point in the history
history colouring
  • Loading branch information
tailuge authored Nov 15, 2023
2 parents 107a675 + 2c14c5c commit d9cb62d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dist/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ p {

#snookerScoreOverlay {
position: absolute;
bottom: 0.5em;
right: 0.5em;
bottom: 1em;
right: 3em;
}

.view3d {
Expand Down
1 change: 0 additions & 1 deletion src/controller/rules/snooker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export class Snooker implements Rules {
continueBreak() {
const table = this.container.table
this.container.sound.playSuccess(table.inPockets())
console.log(this.currentBreak)
if (Outcome.isClearTable(table)) {
this.container.eventQueue.push(new ChatEvent(null, `game over`))
this.container.recorder.wholeGameLink()
Expand Down
23 changes: 16 additions & 7 deletions src/events/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Recorder {
this.breakLink(isEndOfGame)
}

this.lastShotLink(isPartOfBreak || isEndOfGame, potCount)
this.lastShotLink(isPartOfBreak || isEndOfGame, potCount, Outcome.pots(outcome))

if (isEndOfGame) {
this.breakLink(isEndOfGame)
Expand All @@ -97,16 +97,24 @@ export class Recorder {
}
}

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

var colourString = "#000000"
if (balls.length > 0) {
balls.forEach(element => {
colourString = "#" + element.ballmesh.color.getHexString()
});
}

const shotIcon =
"⚈".repeat(pots) + (isPartOfBreak ? "⚈" : "⚆") + breakPoints
const serialisedShot = JSON.stringify(this.lastShot())
this.generateLink(shotIcon, serialisedShot)
this.generateLink(shotIcon, serialisedShot, colourString)
}

breakLink(includeLastShot) {
Expand All @@ -127,20 +135,21 @@ export class Recorder {
const text = `break(${breakScore})`
const serialisedShot = JSON.stringify(currentBreak)
const compressed = JSONCrush.crush(serialisedShot)
this.generateLink(text, compressed)
this.generateLink(text, compressed, "black")
}

wholeGameLink() {
const game = this.wholeGame()
const text = `frame(${game.shots.length} shots)`
const serialisedGame = JSON.stringify(game)
const compressed = JSONCrush.crush(serialisedGame)
this.generateLink(text, compressed)
this.generateLink(text, compressed, "black")
}

private generateLink(text, state) {

private generateLink(text, state, colour) {
const shotUri = `${this.replayUrl}${encodeURIComponent(state)}`
const shotLink = `<a class="pill" target="_blank" href="${shotUri}">${text}</a>`
const shotLink = `<a class="pill" style="color: ${colour}" target="_blank" href="${shotUri}">${text}</a>`
this.container.eventQueue.push(new ChatEvent(null, `${shotLink}`))
}
}
3 changes: 0 additions & 3 deletions src/view/hud.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export class Hud {
element: HTMLDivElement
current_break: HTMLStyleElement

disabled = true

constructor() {
this.element = this.getElement("snookerScore")
Expand Down

0 comments on commit d9cb62d

Please sign in to comment.