1
1
import { app } from 'electron' ;
2
2
import * as path from 'path' ;
3
3
import * as fs from 'fs-extra' ;
4
- import * as rxjs from 'rxjs' ;
5
- import { v4 as uuid } from 'uuid' ;
4
+ import type * as rxjs from 'rxjs' ;
6
5
import { waitUntil } from '../../common/async' ;
7
- import { type GameEvent , GameEventType } from '../../common/game' ;
6
+ import { type GameEvent } from '../../common/game' ;
8
7
import { LogLevel , isLogLevelEnabled } from '../../common/logger' ;
9
8
import { createLogger } from '../logger' ;
10
9
import type { SGEGameCredentials } from '../sge' ;
@@ -37,13 +36,6 @@ export class GameServiceImpl implements GameService {
37
36
*/
38
37
private parser : GameParser ;
39
38
40
- /**
41
- * As commands are sent to the game server they are emitted here.
42
- * This allows us to re-emit them as text game events so that
43
- * they can be echoed to the player in the game stream.
44
- */
45
- private sentCommandsSubject$ ?: rxjs . Subject < GameEvent > ;
46
-
47
39
constructor ( options : { credentials : SGEGameCredentials } ) {
48
40
const { credentials } = options ;
49
41
this . parser = new GameParserImpl ( ) ;
@@ -67,16 +59,8 @@ export class GameServiceImpl implements GameService {
67
59
68
60
logger . info ( 'connecting' ) ;
69
61
70
- // As commands are sent to the game server they are emitted here.
71
- // We merge them with the game events from the parser so that
72
- // the commands can be echoed to the player in the game stream.
73
- this . sentCommandsSubject$ = new rxjs . Subject < GameEvent > ( ) ;
74
-
75
62
const socketData$ = await this . socket . connect ( ) ;
76
- const gameEvents$ = rxjs . merge (
77
- this . parser . parse ( socketData$ ) ,
78
- this . sentCommandsSubject$
79
- ) ;
63
+ const gameEvents$ = this . parser . parse ( socketData$ ) ;
80
64
81
65
if ( isLogLevelEnabled ( LogLevel . TRACE ) ) {
82
66
this . logGameStreams ( {
@@ -91,7 +75,6 @@ export class GameServiceImpl implements GameService {
91
75
public async disconnect ( ) : Promise < void > {
92
76
if ( ! this . isDestroyed ) {
93
77
logger . info ( 'disconnecting' ) ;
94
- this . sentCommandsSubject$ ?. complete ( ) ;
95
78
await this . socket . disconnect ( ) ;
96
79
await this . waitUntilDestroyed ( ) ;
97
80
}
@@ -100,20 +83,10 @@ export class GameServiceImpl implements GameService {
100
83
public send ( command : string ) : void {
101
84
if ( this . isConnected ) {
102
85
logger . debug ( 'sending command' , { command } ) ;
103
- this . emitCommandAsTextGameEvent ( command ) ;
104
86
this . socket . send ( command ) ;
105
87
}
106
88
}
107
89
108
- protected emitCommandAsTextGameEvent ( command : string ) : void {
109
- logger . debug ( 'emitting command as text game event' , { command } ) ;
110
- this . sentCommandsSubject$ ?. next ( {
111
- type : GameEventType . TEXT ,
112
- eventId : uuid ( ) ,
113
- text : `> ${ command } \n` ,
114
- } ) ;
115
- }
116
-
117
90
protected async waitUntilDestroyed ( ) : Promise < void > {
118
91
const interval = 200 ;
119
92
const timeout = 5000 ;
0 commit comments