Skip to content

Commit 5332c32

Browse files
committed
feat: echo command input to main stream for user
1 parent 98f667e commit 5332c32

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

electron/renderer/pages/grid.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { v4 as uuid } from 'uuid';
1111
import { getExperienceMindState } from '../../common/game/get-experience-mindstate.js';
1212
import type {
1313
ExperienceGameEvent,
14+
GameCommandMessage,
1415
GameEvent,
1516
GameEventMessage,
1617
RoomGameEvent,
@@ -280,6 +281,37 @@ const GridPage: React.FC = (): ReactNode => {
280281
};
281282
}, [logger, gameEventsSubject$]);
282283

284+
// When the user sends a command, echo it to the main game stream so that
285+
// the user sees what they sent and can correlate to the game response.
286+
useEffect(() => {
287+
const unsubscribe = window.api.onMessage(
288+
'game:command',
289+
(_event: IpcRendererEvent, message: GameCommandMessage) => {
290+
const { command } = message;
291+
logger.debug('game:command', { command });
292+
gameLogLineSubject$.next({
293+
eventId: uuid(),
294+
// TODO create some constants for known stream ids, '' = main window
295+
streamId: '',
296+
// TODO clean up this mess
297+
styles: css({
298+
fontFamily: `Verdana, ${euiTheme.font.familySerif}`,
299+
fontSize: '14px',
300+
fontWeight: euiTheme.font.weight.regular,
301+
color: euiTheme.colors.subduedText,
302+
lineHeight: 'initial',
303+
paddingLeft: euiTheme.size.s,
304+
paddingRight: euiTheme.size.s,
305+
}),
306+
text: `> ${command}`,
307+
});
308+
}
309+
);
310+
return () => {
311+
unsubscribe();
312+
};
313+
}, [logger, gameLogLineSubject$, euiTheme]);
314+
283315
// TODO move to a new GameCommandInput component
284316
const onKeyDownCommandInput = useCallback<
285317
KeyboardEventHandler<HTMLInputElement>

0 commit comments

Comments
 (0)