feat: rpg stats improvements

This commit is contained in:
Subarashimo
2025-12-04 20:40:02 +01:00
parent b5f5f6d9c5
commit 9f6c44745b
9 changed files with 310 additions and 98 deletions
+37
View File
@@ -217,6 +217,43 @@ export function parseJSONTrackerData(jsonData) {
}
}
// Parse attributes (RPG attributes like STR, DEX, etc.)
// Only parse if allowAIUpdateAttributes is enabled
const allowAIUpdateAttributes = trackerConfig?.userStats?.allowAIUpdateAttributes !== false; // Default to true for backwards compatibility
if (jsonData.attributes && typeof jsonData.attributes === 'object' && allowAIUpdateAttributes) {
debugLog('[RPG Parser] Parsing attributes:', Object.keys(jsonData.attributes));
const rpgAttributes = trackerConfig?.userStats?.rpgAttributes || [
{ id: 'str', name: 'STR', description: '', enabled: true },
{ id: 'dex', name: 'DEX', description: '', enabled: true },
{ id: 'con', name: 'CON', description: '', enabled: true },
{ id: 'int', name: 'INT', description: '', enabled: true },
{ id: 'wis', name: 'WIS', description: '', enabled: true },
{ id: 'cha', name: 'CHA', description: '', enabled: true }
];
for (const [attrName, value] of Object.entries(jsonData.attributes)) {
// Find matching attribute in config (case-insensitive)
const attrConfig = rpgAttributes.find(a =>
a && a.name && a.name.toLowerCase() === attrName.toLowerCase()
);
if (attrConfig && typeof value === 'number') {
// Store in classicStats using the attribute id
extensionSettings.classicStats[attrConfig.id] = Math.max(1, value);
debugLog(`[RPG Parser] Attribute ${attrConfig.name}: ${value}`);
}
}
} else if (jsonData.attributes && !allowAIUpdateAttributes) {
debugLog('[RPG Parser] Attributes found in response but allowAIUpdateAttributes is disabled - skipping update');
}
// Parse level (only if allowAIUpdateAttributes is enabled)
if (jsonData.level !== undefined && typeof jsonData.level === 'number' && allowAIUpdateAttributes) {
extensionSettings.level = Math.max(1, jsonData.level);
debugLog(`[RPG Parser] Level: ${extensionSettings.level}`);
} else if (jsonData.level !== undefined && !allowAIUpdateAttributes) {
debugLog('[RPG Parser] Level found in response but allowAIUpdateAttributes is disabled - skipping update');
}
// Parse status
if (jsonData.status) {
if (jsonData.status.mood) {