Skip to content

Commit 531d0a2

Browse files
committed
- Fixed issue with the parser that would sometimes create a line with just the speaker.
1 parent 8d1c51b commit 531d0a2

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 => {
@@ -277,13 +281,18 @@ export const sanitizeActions = (actions: any[]): any[] => {
277281
while ((match = dialogueRegex.exec(text)) !== null) {
278282
// Add any narration before this dialogue
279283
const narrationBefore = text.substring(lastIndex, match.index).trim()
280-
if (narrationBefore) {
284+
// If this chunk is ONLY a speaker label (e.g. "**Chime:**"), merge it into the dialogue.
285+
// This prevents creating a separate narration action for the label.
286+
const isLabelOnly = !!narrationBefore && isSpeakerLabel(narrationBefore)
287+
288+
if (narrationBefore && !isLabelOnly) {
281289
parts.push({ text: narrationBefore, isDialogue: false })
282290
}
283-
291+
284292
// Add the dialogue (with quotes)
285293
const dialogue = match[0] // Full match including quotes
286-
parts.push({ text: dialogue, isDialogue: true })
294+
const mergedDialogue = isLabelOnly ? `${narrationBefore} ${dialogue}`.trim() : dialogue
295+
parts.push({ text: mergedDialogue, isDialogue: true })
287296

288297
lastIndex = match.index + match[0].length
289298
}

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)