@@ -5,7 +5,12 @@ import Player from "../controller/src/model/Player"
55import Commentator from "../controller/src/model/Commentator"
66import io from "socket.io-client"
77
8- export default class OBS {
8+ enum Direction {
9+ in ,
10+ out
11+ }
12+
13+ export default class OBScoreClient {
914 private css : string = `
1015 background: #16171d;
1116 padding: 0px 5px;
@@ -40,27 +45,27 @@ export default class OBS {
4045 this . onUpdate = onUpdate
4146 }
4247
43- logBase ( msg : string , style : any ) {
48+ private logBase ( msg : string , style : any ) {
4449 console . log ( `%c[OBScore.js] ${ msg } ` , style )
4550 }
4651
47- log ( msg : string ) {
52+ public log ( msg : string ) {
4853 this . logBase ( msg , this . css + "color: #3b8eea;" )
4954 }
5055
51- logError ( msg : string ) {
56+ public logError ( msg : string ) {
5257 this . logBase ( msg , this . css + "color: #f13d30;" )
5358 }
5459
55- sendError ( error : Error ) {
60+ public sendError ( error : Error ) {
5661 if ( typeof this . socket !== "object" ) {
5762 throw new Error ( "Socket not available yet" )
5863 }
5964
6065 this . socket . emit ( emittable . clientError , error . stack )
6166 }
6267
63- connect ( server : string , callback ?: Function ) {
68+ public connect ( server : string , callback ?: Function ) {
6469 const socket = io ( server )
6570 this . socket = socket
6671
@@ -102,7 +107,7 @@ export default class OBS {
102107 } )
103108 }
104109
105- static stringifyLevel = ( level : Level ) => {
110+ public static stringifyLevel = ( level : Level ) => {
106111 if ( ! level . bracket ) {
107112 return "n/a"
108113 }
@@ -118,19 +123,43 @@ export default class OBS {
118123 }
119124 }
120125
121- static stringifyPlayer = ( player : Player ) => {
126+ public static stringifyPlayer = ( player : Player ) => {
122127 if ( ! player . sponsor ) {
123128 return player . tag
124129 }
125130
126131 return `${ player . sponsor } | ${ player . tag } `
127132 }
128133
129- static stringifyCommentator = ( commentator : Commentator ) => {
134+ public static stringifyCommentator = ( commentator : Commentator ) => {
130135 if ( ! commentator . sponsor ) {
131136 return commentator . tag
132137 }
133138
134139 return `${ commentator . sponsor } | ${ commentator . tag } `
135140 }
141+
142+ private static fade = ( element : HTMLElement , direction : Direction ) => {
143+ const animation = element . animate ( {
144+ opacity : direction === Direction . in ? [ 1 , 0 ] : [ 0 , 1 ]
145+ } , 300 )
146+
147+ return new Promise ( res => {
148+ animation . addEventListener ( "finish" , res )
149+ } )
150+ }
151+
152+ public static fadeIn = async ( element : HTMLElement ) => {
153+ await OBScoreClient . fade ( element , Direction . out )
154+ }
155+
156+ public static fadeOut = async ( element : HTMLElement ) => {
157+ await OBScoreClient . fade ( element , Direction . in )
158+ }
159+
160+ public static fadeInOut = async ( element : HTMLElement , changeMethod : Function ) => {
161+ await OBScoreClient . fadeOut ( element )
162+ changeMethod ( )
163+ await OBScoreClient . fadeIn ( element )
164+ }
136165}
0 commit comments