Skip to content

Commit

Permalink
spectate
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Jan 9, 2025
1 parent 825b62c commit 2f79bd0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 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 @@
"ts-jest": "29.2.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "5.7.2",
"typescript": "5.7.3",
"webpack": "5.97.1",
"webpack-cli": "6.0.1",
"webpack-dev-server": "5.2.0",
Expand Down
6 changes: 5 additions & 1 deletion src/controller/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import { NchanMessageRelay } from "../network/client/nchanmessagerelay"
export class Init extends ControllerBase {
override handleBegin(_: BeginEvent): Controller {
if (Session.isSpectator()) {
return new Spectate(this.container, new NchanMessageRelay(), Session.getInstance().tableId)
return new Spectate(
this.container,
new NchanMessageRelay(),
Session.getInstance().tableId
)
}

this.container.chat.showMessage("Start")
Expand Down
25 changes: 17 additions & 8 deletions src/controller/spectate.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
import { ControllerBase } from "./controllerbase"
import { Controller, Input } from "./controller"
import { AimEvent, Controller, HitEvent, Input } from "./controller"
import { MessageRelay } from "../network/client/messagerelay"
import { ChatEvent } from "../events/chatevent"
import { EventUtil } from "../events/eventutil"
import { GameEvent } from "../events/gameevent"

export class Spectate extends ControllerBase {

messageRelay: MessageRelay
tableId: string
messages: string[] = []
messages: GameEvent[] = []
constructor(container, messageRelay, tableId) {
super(container)
this.messageRelay = messageRelay
this.tableId = tableId
this.messageRelay.subscribe(this.tableId, (message) => {
console.log(message)
this.messages.push(message)
this.container.eventQueue.push(new ChatEvent("nchan", "."))
const event = EventUtil.fromSerialised(message)
this.messages.push(event)
if (event instanceof HitEvent || event instanceof AimEvent) {
this.container.eventQueue.push(event)
}
})
console.log("Spectate")
}

override handleChat(chatevent: ChatEvent): Controller {
console.log("Spectate chat",chatevent,this.messages.length)
override handleAim(event: AimEvent) {
this.container.table.cue.aim = event
this.container.table.cueball.pos.copy(event.pos)
return this
}

override handleHit(event: HitEvent) {
console.log("Spectate Hit")
this.container.table.updateFromSerialised(event.tablejson)
return this
}

override handleInput(input: Input): Controller {
this.commonKeyHandler(input)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4415,10 +4415,10 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

typescript@5.7.2:
version "5.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.2.tgz#3169cf8c4c8a828cde53ba9ecb3d2b1d5dd67be6"
integrity sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==
typescript@5.7.3:
version "5.7.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.3.tgz#919b44a7dbb8583a9b856d162be24a54bf80073e"
integrity sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==

undici-types@~5.26.4:
version "5.26.5"
Expand Down

0 comments on commit 2f79bd0

Please sign in to comment.