11import { emittable , receivable } from "./events"
22import Scoreboard from "../controller/src/model/Scoreboard"
3+ import Level from "../controller/src/model/Level"
4+ import Player from "../controller/src/model/Player"
5+ import Commentator from "../controller/src/model/Commentator"
36import io from "socket.io-client"
47
58export default class OBS {
@@ -20,14 +23,17 @@ export default class OBS {
2023 onUpdate : ( scoreboard : Scoreboard ) => void ,
2124 timeout = 500
2225 ) {
23- if ( typeof name !== "string" )
26+ if ( typeof name !== "string" ) {
2427 throw new Error ( "name must be a string" )
28+ }
2529
26- if ( typeof onUpdate !== "function" )
30+ if ( typeof onUpdate !== "function" ) {
2731 throw new Error ( "onUpdate must be a function" )
32+ }
2833
29- if ( typeof timeout !== "number" )
34+ if ( typeof timeout !== "number" ) {
3035 throw new Error ( "timeout must be a number" )
36+ }
3137
3238 this . name = name
3339 this . timeout = timeout
@@ -95,4 +101,36 @@ export default class OBS {
95101 this . sendError ( event . error )
96102 } )
97103 }
104+
105+ static stringifyLevel = ( level : Level ) => {
106+ if ( ! level . bracket ) {
107+ return "n/a"
108+ }
109+
110+ if ( ! level . round ) {
111+ return level . bracket . long
112+ }
113+
114+ if ( level . number ) {
115+ return `${ level . bracket . long } ${ level . round . long } ${ level . number } `
116+ } else {
117+ return `${ level . bracket . long } ${ level . round . long } `
118+ }
119+ }
120+
121+ static stringifyPlayer = ( player : Player ) => {
122+ if ( ! player . sponsor ) {
123+ return player . tag
124+ }
125+
126+ return `${ player . sponsor } | ${ player . tag } `
127+ }
128+
129+ static stringifyCommentator = ( commentator : Commentator ) => {
130+ if ( ! commentator . sponsor ) {
131+ return commentator . tag
132+ }
133+
134+ return `${ commentator . sponsor } | ${ commentator . tag } `
135+ }
98136}
0 commit comments