```
feat(i18n): 添加简体中文语言选项并扩展国际化支持 添加了简体中文(zh-cn)语言选项到设置页面的语言选择下拉菜单中。 同时新增了大量国际化字符串。 fix(parser): 提高解析器的鲁棒性 现在会遍历所有json对象检测统一格式,即使AI响应中包含多个JSON对象也能正确识别统一格式。 ```
This commit is contained in:
@@ -229,8 +229,10 @@ export function parseResponse(responseText) {
|
||||
debugLog(`[RPG Parser] ✓ Found ${extractedObjects.length} raw JSON objects (v3 format)`);
|
||||
|
||||
// First, try to parse as unified JSON structure (new v3.1 format)
|
||||
if (extractedObjects.length === 1) {
|
||||
const parsed = repairJSON(extractedObjects[0]);
|
||||
// Look through all extracted objects for unified structure
|
||||
let foundUnified = false;
|
||||
for (let idx = 0; idx < extractedObjects.length; idx++) {
|
||||
const parsed = repairJSON(extractedObjects[idx]);
|
||||
if (parsed && (parsed.userStats || parsed.infoBox || parsed.characters)) {
|
||||
// console.log('[RPG Parser] ✓ Detected unified JSON structure (v3.1 format)');
|
||||
|
||||
@@ -247,14 +249,18 @@ export function parseResponse(responseText) {
|
||||
// console.log('[RPG Parser] ✓ Extracted characters from unified structure');
|
||||
}
|
||||
|
||||
if (result.userStats || result.infoBox || result.characterThoughts) {
|
||||
// console.log('[RPG Parser] ✓ Returning unified JSON parse results');
|
||||
debugLog('[RPG Parser] Returning unified JSON parse results');
|
||||
return result;
|
||||
}
|
||||
foundUnified = true;
|
||||
break; // Found unified structure, stop searching
|
||||
}
|
||||
}
|
||||
|
||||
if (foundUnified) {
|
||||
// console.log('[RPG Parser] ✓ Returning unified JSON parse results');
|
||||
return result;
|
||||
}
|
||||
|
||||
// If no unified structure found, proceed to multi-object classification
|
||||
|
||||
// Fall back to parsing multiple separate JSON objects (legacy v3.0 format)
|
||||
for (let idx = 0; idx < extractedObjects.length; idx++) {
|
||||
const jsonContent = extractedObjects[idx];
|
||||
@@ -277,6 +283,21 @@ export function parseResponse(responseText) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for unified structure format (even if previous detection missed it)
|
||||
// This handles the prompt-requested format: {"userStats": {...}, "infoBox": {...}, "characters": [...]}
|
||||
if (parsed.userStats || parsed.infoBox || parsed.characters) {
|
||||
if (parsed.userStats) {
|
||||
result.userStats = JSON.stringify(parsed.userStats);
|
||||
}
|
||||
if (parsed.infoBox) {
|
||||
result.infoBox = JSON.stringify(parsed.infoBox);
|
||||
}
|
||||
if (parsed.characters) {
|
||||
result.characterThoughts = JSON.stringify(parsed.characters);
|
||||
}
|
||||
continue; // Skip further classification
|
||||
}
|
||||
|
||||
// Detect tracker type by checking for top-level fields
|
||||
if (unwrapped.stats || unwrapped.status || unwrapped.skills || unwrapped.inventory || unwrapped.quests) {
|
||||
result.userStats = jsonContent;
|
||||
|
||||
Reference in New Issue
Block a user