Skip to content

Commit 4edaeaf

Browse files
committed
feat(game): improve display of inline links in text
1 parent 2562a9c commit 4edaeaf

File tree

3 files changed

+10
-49
lines changed

3 files changed

+10
-49
lines changed

electron/common/game/types.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export type GameEvent =
7777
| RoomGameEvent
7878
| ServerTimeGameEvent
7979
| RoundTimeGameEvent
80-
| CastTimeGameEvent
81-
| URLGameEvent;
80+
| CastTimeGameEvent;
8281

8382
export interface GameEventBase {
8483
/**
@@ -258,15 +257,6 @@ export interface CastTimeGameEvent extends GameEventBase {
258257
time: number;
259258
}
260259

261-
/**
262-
* <a href='https://elanthipedia.play.net/'>Elanthipedia</a>
263-
*/
264-
export interface URLGameEvent extends GameEventBase {
265-
type: GameEventType.URL;
266-
url: string; // e.g. 'https://elanthipedia.play.net/'
267-
text: string; // e.g. 'Elanthipedia'
268-
}
269-
270260
export enum GameEventType {
271261
/**
272262
* Text to display to the player.
@@ -358,10 +348,6 @@ export enum GameEventType {
358348
* the number of seconds to wait.
359349
*/
360350
CAST_TIME = 'CAST_TIME',
361-
/**
362-
* URL link to display to the player.
363-
*/
364-
URL = 'URL',
365351
}
366352

367353
export enum IndicatorType {

electron/main/game/game.parser.ts

+9-26
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export class GameParserImpl implements GameParser {
364364
break;
365365
case 'a':
366366
// This is a hyperlink, we only need the text.
367-
// Example: `<a href='https://drwiki.play.net'>Elanthipedia</a>`.
367+
// Example: `<a href='https://elanthipedia.play.net'>Elanthipedia</a>`
368368
// In this example, the text would be 'Elanthipedia'.
369369
this.gameText += text;
370370
break;
@@ -414,6 +414,9 @@ export class GameParserImpl implements GameParser {
414414
});
415415

416416
switch (tagName) {
417+
case 'a': // <a href='https://elanthipedia.play.net'>Elanthipedia</a>
418+
this.gameText += `<a href="${attributes.href}" target="_blank">`;
419+
break;
417420
case 'pushBold': // <pushBold/>
418421
// If this is nested inside text then it is an inline text style.
419422
// For example, emphasizing a person's name.
@@ -487,13 +490,6 @@ export class GameParserImpl implements GameParser {
487490
case 'castTime': // <castTime value='1703617016'/>
488491
this.emitCastTimeGameEvent(parseInt(attributes.value));
489492
break;
490-
case 'a': // <a href='https://elanthipedia.play.net/'>Elanthipedia</a>
491-
// Links are often found within a line of text.
492-
// Emit any game text up to this point.
493-
if (this.gameText.length > 0) {
494-
this.emitTextGameEvent(this.consumeGameText());
495-
}
496-
break;
497493
}
498494
}
499495

@@ -513,6 +509,11 @@ export class GameParserImpl implements GameParser {
513509
});
514510

515511
switch (tagName) {
512+
case 'a':
513+
// Close the hyperlink because we are at the end of the tag.
514+
// Example: `<a href='https://elanthipedia.play.net'>Elanthipedia</a>`
515+
this.gameText += `</a>`;
516+
break;
516517
case 'component':
517518
// Emit the room info because we are at the end of the tag.
518519
// Example: `<component id='room desc'>The hustle...</component>`
@@ -560,14 +561,6 @@ export class GameParserImpl implements GameParser {
560561
// Example: `<right>Empty</right>`
561562
this.emitRightHandGameEvent(this.consumeGameText());
562563
break;
563-
case 'a':
564-
// Emit the hyperlink because we are at the end of the tag.
565-
// Example: `<a href='https://elanthipedia.play.net/'>Elanthipedia</a>`
566-
this.emitUrlGameEvent({
567-
url: attributes.href,
568-
text: this.consumeGameText(),
569-
});
570-
break;
571564
}
572565

573566
if (this.activeTags.length > 0) {
@@ -826,16 +819,6 @@ export class GameParserImpl implements GameParser {
826819
});
827820
}
828821

829-
protected emitUrlGameEvent(options: { url: string; text: string }): void {
830-
const { url, text } = options;
831-
this.emitGameEvent({
832-
type: GameEventType.URL,
833-
eventId: uuid(),
834-
url,
835-
text: unescapeEntities(text),
836-
});
837-
}
838-
839822
protected emitGameEvent(gameEvent: GameEvent): void {
840823
logger.trace('emitting game event', { gameEvent });
841824
this.gameEventsSubject$.next(gameEvent);

electron/renderer/pages/game.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ const GamePage: React.FC = (): ReactNode => {
152152
text: gameEvent.text,
153153
});
154154
break;
155-
case GameEventType.URL:
156-
gameLogLineSubject$.next({
157-
eventId: gameEvent.eventId,
158-
streamId: gameStreamIdRef.current,
159-
styles: textStyles,
160-
text: `<a href="${gameEvent.url}" target="_blank">${gameEvent.text}</a>`,
161-
});
162-
break;
163155
case GameEventType.EXPERIENCE:
164156
// TODO need to track a map of skill names to their latest event
165157
// so that when we receive a new event we can update that skill

0 commit comments

Comments
 (0)