Merge branch 'main' into main

This commit is contained in:
Spicy Marinara
2026-04-02 20:41:21 +02:00
committed by GitHub
14 changed files with 768 additions and 104 deletions
+17 -4
View File
@@ -18,9 +18,10 @@ import {
lastActionWasSwipe,
setIsGenerating,
setLastActionWasSwipe,
$musicPlayerContainer
$musicPlayerContainer,
getSeparateGenerationId
} from '../../core/state.js';
import { saveChatData } from '../../core/persistence.js';
import { saveChatData, mirrorToSwipeInfo } from '../../core/persistence.js';
import {
generateSeparateUpdatePrompt
} from './promptBuilder.js';
@@ -218,7 +219,7 @@ export async function switchToPreset(presetName) {
* @param {Function} renderThoughts - UI function to render character thoughts
* @param {Function} renderInventory - UI function to render inventory
*/
export async function updateRPGData(renderUserStats, renderInfoBox, renderThoughts, renderInventory) {
export async function updateRPGData(renderUserStats, renderInfoBox, renderThoughts, renderInventory, generationId = null) {
if (isGenerating) {
// console.log('[RPG Companion] Already generating, skipping...');
return;
@@ -262,6 +263,14 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
});
}
// If a generationId was provided and the counter has since been incremented
// (by a deletion or a newer generation), discard this result entirely.
// The finally block still runs to restore button state.
if (generationId !== null && getSeparateGenerationId() !== generationId) {
// console.log('[RPG Companion] ⚠️ Separate generation result discarded — superseded (genId', generationId, '!= current', getSeparateGenerationId(), ')');
return;
}
if (response) {
// console.log('[RPG Companion] Raw AI response:', response);
const parsedData = parseResponse(response);
@@ -317,11 +326,15 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
}
const currentSwipeId = lastMessage.swipe_id || 0;
lastMessage.extra.rpg_companion_swipes[currentSwipeId] = {
const swipeEntry = {
userStats: parsedData.userStats,
infoBox: parsedData.infoBox,
characterThoughts: parsedData.characterThoughts
};
lastMessage.extra.rpg_companion_swipes[currentSwipeId] = swipeEntry;
// Mirror to swipe_info so this swipe survives page reload even if never manually edited
mirrorToSwipeInfo(lastMessage, currentSwipeId, swipeEntry);
// console.log('[RPG Companion] Stored separate mode RPG data for message swipe', currentSwipeId);
}