Skip to content

Commit b9c5a4a

Browse files
committed
- Fixed issue with the parser that would sometimes create a line with just the speaker.
1 parent 81209f8 commit b9c5a4a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/utils/chatUtils.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// src/utils/chatUtils.ts
22
import l2d from '@/utils/json/l2d.json'
33

4-
// Helper to identify speaker labels
5-
const isSpeakerLabel = (s: string) => /^\s*(?:\*\*)?[^*]+?(?:\*\*)?\s*:\s*$/.test(s)
4+
// Helper to identify speaker labels.
5+
// Supports plain "Name:" and bolded "**Name:**" (colon inside the bold).
6+
const isSpeakerLabel = (s: string) => {
7+
const normalized = (s || '').replace(/\u00A0/g, ' ').trim()
8+
return /^\s*(?:\*\*)?\s*[^*:\n]+?\s*:\s*(?:\*\*)?\s*$/.test(normalized)
9+
}
610

711
// Helper to check if a word appears as a whole word in text (case-insensitive)
812
export const isWholeWordPresent = (text: string, word: string): boolean => {
@@ -282,13 +286,18 @@ export const sanitizeActions = (actions: any[]): any[] => {
282286
while ((match = dialogueRegex.exec(text)) !== null) {
283287
// Add any narration before this dialogue
284288
const narrationBefore = text.substring(lastIndex, match.index).trim()
285-
if (narrationBefore) {
289+
// If this chunk is ONLY a speaker label (e.g. "**Chime:**"), merge it into the dialogue.
290+
// This prevents creating a separate narration action for the label.
291+
const isLabelOnly = !!narrationBefore && isSpeakerLabel(narrationBefore)
292+
293+
if (narrationBefore && !isLabelOnly) {
286294
parts.push({ text: narrationBefore, isDialogue: false })
287295
}
288-
296+
289297
// Add the dialogue (with quotes)
290298
const dialogue = match[0] // Full match including quotes
291-
parts.push({ text: dialogue, isDialogue: true })
299+
const mergedDialogue = isLabelOnly ? `${narrationBefore} ${dialogue}`.trim() : dialogue
300+
parts.push({ text: mergedDialogue, isDialogue: true })
292301

293302
lastIndex = match.index + match[0].length
294303
}

src/utils/json/loadingMessages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"Riding the AZX...",
1818
"Receiving funds for the Admire...",
1919
"Exploring the surface...",
20-
"Debating whether coffee is best with milk or sugar..."
20+
"Debating whether coffee is best with milk or sugar...",
21+
"♫ Shadows of battlefields sighting the ashes faaaall... ♫"
2122
]

0 commit comments

Comments
 (0)