@@ -510,9 +510,13 @@ export class GameParserImpl implements GameParser {
510
510
}
511
511
// Emit the experience info because we are at the end of the tag.
512
512
// Example: `<component id='exp Attunement'> Attunement: 1 46% attentive </component>`
513
+ // Example: `<component id='exp Attunement'></component>` (empty)
513
514
else if ( tagId . startsWith ( 'exp ' ) ) {
514
515
this . emitExperienceGameEvent (
515
- this . parseToExperienceGameEvent ( this . consumeGameText ( ) )
516
+ this . parseToExperienceGameEvent ( {
517
+ tagId,
518
+ expText : this . consumeGameText ( ) ,
519
+ } )
516
520
) ;
517
521
}
518
522
break ;
@@ -550,12 +554,16 @@ export class GameParserImpl implements GameParser {
550
554
}
551
555
552
556
/**
557
+ * Parses a component's tag id into an experience skill name.
553
558
* Parses an experience line of text into an experience game event.
554
559
*
555
- * Input:
560
+ * Tag ID Input:
561
+ * 'exp Attunement'
562
+ *
563
+ * Line Input:
556
564
* 'Attunement: 1 46% attentive'
557
565
*
558
- * Output:
566
+ * Event Output:
559
567
* {
560
568
* type: GameEventType.EXPERIENCE,
561
569
* skill: 'Attunement',
@@ -564,23 +572,37 @@ export class GameParserImpl implements GameParser {
564
572
* mindState: 'attentive'
565
573
* }
566
574
*/
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 ) ;
569
591
if ( matchResult ) {
570
592
return {
571
593
type : GameEventType . EXPERIENCE ,
572
- skill : matchResult . groups ?. skill ?? '' ,
594
+ skill : matchResult . groups ?. skill ?? 'PARSE_ERROR ' ,
573
595
rank : parseInt ( matchResult . groups ?. rank ?? '0' ) ,
574
596
percent : parseInt ( matchResult . groups ?. percent ?? '0' ) ,
575
- mindState : matchResult . groups ?. mindstate ?? '' ,
597
+ mindState : matchResult . groups ?. mindstate ?? 'clear ' ,
576
598
} ;
577
599
}
578
600
return {
579
601
type : GameEventType . EXPERIENCE ,
580
- skill : '' ,
602
+ skill : tagId . slice ( 4 ) ,
581
603
rank : 0 ,
582
604
percent : 0 ,
583
- mindState : '' ,
605
+ mindState : 'clear ' ,
584
606
} ;
585
607
}
586
608
0 commit comments