Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history colouring #50

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a find fishing that out.

});
}

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