Compare commits

..

3 Commits

Author SHA1 Message Date
Spicy_Marinara 0d71dcca04 v3.3.1: Fix Recent Events reading from lastGeneratedData and add desktop thought panel collapse 2026-01-08 23:29:18 +01:00
Spicy Marinara 39e2a07829 Merge pull request #85 from tomt610/feature/update-complete-event
Add event emission when tracker update completes
2026-01-08 23:18:10 +01:00
tomt610 dedfead59e Add event emission when tracker update completes
Emits 'rpg_companion_update_complete' event after updateRPGData() finishes.
This allows other extensions (like Context Prewarm) to hook into the
completion of tracker updates and perform actions afterward.

The event is emitted in the finally block, so it fires regardless of
success or failure, after isGenerating is reset.
2026-01-08 22:12:06 +00:00
8 changed files with 79 additions and 28 deletions
+6 -7
View File
@@ -7,15 +7,14 @@ An immersive RPG extension for browsers that tracks character stats, scene infor
## 🆕 What's New
### v3.3.0
### v3.3.1
- Small upgrades to the combat system.
- Regex fix.
- Fixed External API logic.
- Even more minor bug fixes.
- Thought bubble can now be collapsed into an icon.
- Fixed a bug for Past Events being parsed incorrectly.
- Added event emission on when the tracker generation is complete.
**Special thanks to all the other contributors for this project:**
Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude, IDeathByte, Chungchandev, Joenunezb, and Amauragis.
Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude, IDeathByte, Chungchandev, Joenunezb, Amauragis, and Tomt610.
## 📥 Installation
@@ -268,7 +267,7 @@ If you enjoy this extension, consider supporting development:
## 🙏 Credits
**Contributors:**
SpicyMarinara, Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude, IDeathByte, Chungchandev, Joenunezb, and Amauragis.
SpicyMarinara, Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude, IDeathByte, Chungchandev, Joenunezb, Amauragis, and Tomt610.
## 🚀 Planned Features
+1 -1
View File
@@ -6,6 +6,6 @@
"js": "index.js",
"css": "style.css",
"author": "Marinara",
"version": "3.3.0",
"version": "3.3.1",
"homePage": "https://github.com/SpicyMarinara/rpg-companion-sillytavern"
}
+2 -2
View File
@@ -43,12 +43,12 @@
<i class="fa-solid fa-users"></i> <strong>Contributors:</strong>
</div>
<div style="opacity: 0.8; font-size: 0.9em;">
SpicyMarinara, Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude, IDeathByte, Chungchandev, Joenunezb, and Amauragis.
SpicyMarinara, Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude, IDeathByte, Chungchandev, Joenunezb, Amauragis, and Tomt610.
</div>
</div>
<div style="margin-top: 10px; text-align: center; opacity: 0.6; font-size: 0.85em;">
v3.2.6
v3.3.1
</div>
</div>
</div>
+9 -1
View File
@@ -3,8 +3,12 @@
* Handles API calls for RPG tracker generation
*/
import { generateRaw, chat } from '../../../../../../../script.js';
import { generateRaw, chat, eventSource } from '../../../../../../../script.js';
import { executeSlashCommandsOnChatInput } from '../../../../../../../scripts/slash-commands.js';
// Custom event name for when RPG Companion finishes updating tracker data
// Other extensions can listen for this event to know when RPG Companion is done
export const RPG_COMPANION_UPDATE_COMPLETE = 'rpg_companion_update_complete';
import {
extensionSettings,
lastGeneratedData,
@@ -397,6 +401,10 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
// This ensures the flag persists through both main generation AND tracker generation
// console.log('[RPG Companion] 🔄 Tracker generation complete - resetting lastActionWasSwipe to false');
setLastActionWasSwipe(false);
// Emit event for other extensions to know RPG Companion has finished updating
console.debug('[RPG Companion] Emitting RPG_COMPANION_UPDATE_COMPLETE event');
eventSource.emit(RPG_COMPANION_UPDATE_COMPLETE);
}
}
+5 -5
View File
@@ -498,19 +498,19 @@ export function renderInfoBox() {
if (config?.widgets?.recentEvents?.enabled) {
// Parse Recent Events from infoBox (supports both JSON and text formats)
let recentEvents = [];
if (committedTrackerData.infoBox) {
if (infoBoxData) {
// Try JSON format first
try {
const parsed = typeof committedTrackerData.infoBox === 'string'
? JSON.parse(committedTrackerData.infoBox)
: committedTrackerData.infoBox;
const parsed = typeof infoBoxData === 'string'
? JSON.parse(infoBoxData)
: infoBoxData;
if (parsed && Array.isArray(parsed.recentEvents)) {
recentEvents = parsed.recentEvents;
}
} catch (e) {
// Fall back to old text format
const recentEventsLine = committedTrackerData.infoBox.split('\n').find(line => line.startsWith('Recent Events:'));
const recentEventsLine = infoBoxData.split('\n').find(line => line.startsWith('Recent Events:'));
if (recentEventsLine) {
const eventsString = recentEventsLine.replace('Recent Events:', '').trim();
if (eventsString) {
+46 -7
View File
@@ -1847,9 +1847,9 @@ export function createThoughtPanel($message, thoughtsArray) {
}, 100);
}
} else {
// Desktop: show panel, hide icon with class
// Desktop: always start with panel expanded on page load/refresh
$thoughtPanel.css('display', 'block');
$thoughtIcon.addClass('rpg-force-hide');
$thoughtIcon.addClass('rpg-force-hide').removeClass('rpg-collapsed-desktop');
}
// Handle viewport changes between mobile and desktop
@@ -1880,24 +1880,62 @@ export function createThoughtPanel($message, thoughtsArray) {
wasMobileView = isMobileNow;
});
// Close button functionality (mobile only) - support both click and touch
// Close button functionality - support both click and touch
$thoughtPanel.find('.rpg-thought-close').on('click touchend', function(e) {
e.preventDefault();
e.stopPropagation();
// Only hide/show in mobile view
if (window.innerWidth <= 1000) {
const isMobileView = window.innerWidth <= 1000;
if (isMobileView) {
// Mobile: hide panel and show icon
$thoughtPanel.fadeOut(200, function() {
// Make sure icon is visible and clean state when panel closes (use selector, not variable)
const $icon = $('#rpg-thought-icon');
$icon.removeClass('rpg-hidden dragging');
$icon.data('just-dragged', false);
});
} else {
// Desktop: collapse to icon at panel position
const panelRect = $thoughtPanel[0].getBoundingClientRect();
const $icon = $('#rpg-thought-icon');
// Position icon where the panel is
$icon.css({
top: `${panelRect.top}px`,
left: isRightPanel ? `${panelRect.left}px` : 'auto',
right: isRightPanel ? 'auto' : `${window.innerWidth - panelRect.right}px`
});
// Mark as collapsed desktop state (session only, not persisted)
$icon.addClass('rpg-collapsed-desktop');
// Hide panel and show icon
$thoughtPanel.fadeOut(200, function() {
$icon.removeClass('rpg-hidden rpg-force-hide');
});
}
});
// Icon click/tap to show panel (mobile only)
// Icon click/tap to show panel
const handleThoughtIconTap = function(e) {
// Skip if we just finished dragging
const isMobileView = window.innerWidth <= 1000;
const $icon = $('#rpg-thought-icon');
// Desktop collapsed state: expand panel and hide icon
if (!isMobileView && $icon.hasClass('rpg-collapsed-desktop')) {
e.preventDefault();
e.stopPropagation();
// Remove collapsed state (no need to save, state is session-only)
$icon.addClass('rpg-force-hide').removeClass('rpg-collapsed-desktop');
// Show panel
$('#rpg-thought-panel').fadeIn(200);
return;
}
// Skip if we just finished dragging (mobile only)
if ($thoughtIcon.data('just-dragged')) {
return;
}
@@ -1995,3 +2033,4 @@ export function createThoughtPanel($message, thoughtsArray) {
}
});
}
+9 -4
View File
@@ -4732,11 +4732,16 @@ body:has(.rpg-panel.rpg-position-left) #sheld {
}
}
/* Force hide class for desktop mode - overrides media query */
#rpg-thought-icon.rpg-force-hide {
/* Force hide class for desktop mode - overrides media query (unless collapsed) */
#rpg-thought-icon.rpg-force-hide:not(.rpg-collapsed-desktop) {
display: none !important;
}
/* When collapsed in desktop, show icon */
#rpg-thought-icon.rpg-collapsed-desktop {
display: flex !important;
}
/* Hidden state that allows transitions */
#rpg-thought-icon.rpg-hidden {
opacity: 0;
@@ -4780,10 +4785,10 @@ body:has(.rpg-panel.rpg-position-left) #sheld {
color: var(--rpg-highlight, #e94560);
}
/* Hide close button in desktop view (panel doesn't close) */
/* Show close button in desktop view for collapsing */
@media (min-width: 1001px) {
.rpg-thought-close {
display: none !important;
display: flex !important;
}
}
+1 -1
View File
@@ -948,7 +948,7 @@
<h4 style="margin-top: 20px; margin-bottom: 10px;"><strong>Special thanks to all the other contributors for this project:</strong></h4>
<p style="margin-left: 20px; line-height: 1.6;">
Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude (???), IDeathByte, Chungchandev, Joenunezb, and Amauragis.
Paperboygold, Munimunigamer, Subarashimo, Lilminzyu, Claude (???), IDeathByte, Chungchandev, Joenunezb, Amauragis, and Tomt610.
</p>
<div style="margin-top: 20px; text-align: center;">