Skip to content

Commit

Permalink
spectate
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Jan 8, 2025
1 parent bde94b3 commit 2d4849f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 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.

3 changes: 2 additions & 1 deletion src/controller/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PlaceBall } from "./placeball"
import { Replay } from "./replay"
import { Session } from "../network/client/session"
import { Spectate } from "./spectate"
import { NchanMessageRelay } from "../network/client/nchanmessagerelay"

/**
* Initial state of controller.
Expand All @@ -17,7 +18,7 @@ import { Spectate } from "./spectate"
export class Init extends ControllerBase {
override handleBegin(_: BeginEvent): Controller {
if (Session.isSpectator()) {
return new Spectate(this.container)
return new Spectate(this.container, new NchanMessageRelay(), Session.getInstance().tableId)
}

this.container.chat.showMessage("Start")
Expand Down
21 changes: 20 additions & 1 deletion src/controller/spectate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import { ControllerBase } from "./controllerbase"
import { Controller, Input } from "./controller"
import { MessageRelay } from "../network/client/messagerelay"
import { ChatEvent } from "../events/chatevent"

export class Spectate extends ControllerBase {
constructor(container) {

messageRelay: MessageRelay
tableId: string
messages: string[] = []
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", "."))
})
console.log("Spectate")
}

override handleChat(chatevent: ChatEvent): Controller {
console.log("Spectate chat",chatevent,this.messages.length)
return this
}


override handleInput(input: Input): Controller {
this.commonKeyHandler(input)
return this
Expand Down

0 comments on commit 2d4849f

Please sign in to comment.