Update Refresh RPG Info buttons in index.js to call commitTrackerDataFromPriorMessage() before updateRPGData()
This commit is contained in:
@@ -42,7 +42,7 @@ import {
|
||||
setMusicPlayerContainer,
|
||||
clearSessionAvatarPrompts
|
||||
} from './src/core/state.js';
|
||||
import { loadSettings, saveSettings, saveChatData, loadChatData, updateMessageSwipeData } from './src/core/persistence.js';
|
||||
import { loadSettings, saveSettings, saveChatData, loadChatData, updateMessageSwipeData, commitTrackerDataFromPriorMessage } from './src/core/persistence.js';
|
||||
import { registerAllEvents } from './src/core/events.js';
|
||||
|
||||
// Generation & Parsing modules
|
||||
@@ -800,6 +800,17 @@ async function initUI() {
|
||||
// console.log('[RPG Companion] Extension is disabled. Please enable it in the Extensions tab.');
|
||||
return;
|
||||
}
|
||||
const currentChat = getContext().chat;
|
||||
let lastAssistantIndex = -1;
|
||||
for (let i = currentChat.length - 1; i >= 0; i--) {
|
||||
if (!currentChat[i].is_user && !currentChat[i].is_system) {
|
||||
lastAssistantIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastAssistantIndex !== -1) {
|
||||
commitTrackerDataFromPriorMessage(lastAssistantIndex);
|
||||
}
|
||||
await updateRPGData(renderUserStats, renderInfoBox, renderThoughts, renderInventory);
|
||||
});
|
||||
|
||||
@@ -808,6 +819,17 @@ async function initUI() {
|
||||
if (!extensionSettings.enabled) {
|
||||
return;
|
||||
}
|
||||
const currentChat = getContext().chat;
|
||||
let lastAssistantIndex = -1;
|
||||
for (let i = currentChat.length - 1; i >= 0; i--) {
|
||||
if (!currentChat[i].is_user && !currentChat[i].is_system) {
|
||||
lastAssistantIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastAssistantIndex !== -1) {
|
||||
commitTrackerDataFromPriorMessage(lastAssistantIndex);
|
||||
}
|
||||
await updateRPGData(renderUserStats, renderInfoBox, renderThoughts, renderInventory);
|
||||
});
|
||||
|
||||
|
||||
@@ -322,6 +322,8 @@ export function commitTrackerDataFromPriorMessage(currentMessageIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log('[RPG Companion] commitTrackerDataFromPriorMessage called with index', currentMessageIndex, '| chat.length =', chat.length);
|
||||
|
||||
for (let i = currentMessageIndex - 1; i >= 0; i--) {
|
||||
const message = chat[i];
|
||||
if (message.is_user || message.is_system) continue;
|
||||
@@ -329,6 +331,7 @@ export function commitTrackerDataFromPriorMessage(currentMessageIndex) {
|
||||
// Found the prior assistant message — commit its active swipe data
|
||||
const swipeId = message.swipe_id || 0;
|
||||
const swipeData = getSwipeData(message, swipeId);
|
||||
// console.log('[RPG Companion] Committing from chat[' + i + '] swipe', swipeId, '| has swipe data:', !!swipeData);
|
||||
committedTrackerData.userStats = swipeData?.userStats || null;
|
||||
committedTrackerData.infoBox = swipeData?.infoBox || null;
|
||||
const rawCharacterThoughts = swipeData?.characterThoughts;
|
||||
|
||||
Reference in New Issue
Block a user