Skip to content

Commit 803c4a3

Browse files
committed
fix: handle empty exp component
1 parent e28afc5 commit 803c4a3

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

electron/main/game/game.parser.ts

+31-9
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,13 @@ export class GameParserImpl implements GameParser {
510510
}
511511
// Emit the experience info because we are at the end of the tag.
512512
// Example: `<component id='exp Attunement'> Attunement: 1 46% attentive </component>`
513+
// Example: `<component id='exp Attunement'></component>` (empty)
513514
else if (tagId.startsWith('exp ')) {
514515
this.emitExperienceGameEvent(
515-
this.parseToExperienceGameEvent(this.consumeGameText())
516+
this.parseToExperienceGameEvent({
517+
tagId,
518+
expText: this.consumeGameText(),
519+
})
516520
);
517521
}
518522
break;
@@ -550,12 +554,16 @@ export class GameParserImpl implements GameParser {
550554
}
551555

552556
/**
557+
* Parses a component's tag id into an experience skill name.
553558
* Parses an experience line of text into an experience game event.
554559
*
555-
* Input:
560+
* Tag ID Input:
561+
* 'exp Attunement'
562+
*
563+
* Line Input:
556564
* 'Attunement: 1 46% attentive'
557565
*
558-
* Output:
566+
* Event Output:
559567
* {
560568
* type: GameEventType.EXPERIENCE,
561569
* skill: 'Attunement',
@@ -564,23 +572,37 @@ export class GameParserImpl implements GameParser {
564572
* mindState: 'attentive'
565573
* }
566574
*/
567-
protected parseToExperienceGameEvent(line: string): ExperienceGameEvent {
568-
const matchResult = line?.trim()?.match(EXPERIENCE_REGEX);
575+
protected parseToExperienceGameEvent(options: {
576+
/**
577+
* The tag id of the component that contains the experience information.
578+
* Example: 'exp Attunement'
579+
*/
580+
tagId: string;
581+
/**
582+
* The line of text that contains the experience information.
583+
* This may be blank if the character has no experience for the skill.
584+
* Example: 'Attunement: 1 46% attentive'
585+
* Example: ''
586+
*/
587+
expText: string;
588+
}): ExperienceGameEvent {
589+
const { tagId, expText } = options;
590+
const matchResult = expText?.trim()?.match(EXPERIENCE_REGEX);
569591
if (matchResult) {
570592
return {
571593
type: GameEventType.EXPERIENCE,
572-
skill: matchResult.groups?.skill ?? '',
594+
skill: matchResult.groups?.skill ?? 'PARSE_ERROR',
573595
rank: parseInt(matchResult.groups?.rank ?? '0'),
574596
percent: parseInt(matchResult.groups?.percent ?? '0'),
575-
mindState: matchResult.groups?.mindstate ?? '',
597+
mindState: matchResult.groups?.mindstate ?? 'clear',
576598
};
577599
}
578600
return {
579601
type: GameEventType.EXPERIENCE,
580-
skill: '',
602+
skill: tagId.slice(4),
581603
rank: 0,
582604
percent: 0,
583-
mindState: '',
605+
mindState: 'clear',
584606
};
585607
}
586608

0 commit comments

Comments
 (0)