Combat encounters: Add pre-encounter config modal, targeting fixes, and tracker integration

- Add pre-encounter narrative configuration modal with combat/summary style settings
- Change POV fields to text inputs (default: narrator) for custom character names
- Fix targeting system for enemies with spaces in names (e.g., 'Gilded Thrall 1')
- Display character-specific sprites/avatars in targeting modal instead of generic emojis
- Add combat difficulty scaling guidance to prevent trivial god defeats or endless wolf battles
- Integrate tracker updates in combat summary generation (together mode)
- Update auto-save logs description to clarify file storage vs chat history
- Apply extension theming to Close Combat Window button
This commit is contained in:
Spicy_Marinara
2025-12-27 16:06:06 +01:00
parent 436f3495f8
commit 3caa74fbf8
9 changed files with 3805 additions and 19 deletions
+130
View File
@@ -0,0 +1,130 @@
/**
* Encounter State Module
* Manages combat encounter state and history
*/
/**
* Current encounter state
*/
export let currentEncounter = {
active: false,
initialized: false,
combatHistory: [], // Array of {role: 'user'|'assistant'|'system', content: string}
combatStats: null, // Current combat stats (HP, party, enemies, etc.)
preEncounterContext: [], // Messages from before the encounter started
encounterStartMessage: '', // The message that triggered the encounter
encounterLog: [] // Full log of combat actions for final summary
};
/**
* Encounter logs storage (per chat)
*/
export let encounterLogs = {
// chatId: [
// {
// timestamp: Date,
// log: [],
// summary: string,
// result: 'victory'|'defeat'|'fled'
// }
// ]
};
/**
* Sets the current encounter state
* @param {object} encounter - The encounter state object
*/
export function setCurrentEncounter(encounter) {
currentEncounter = encounter;
}
/**
* Updates current encounter state with partial data
* @param {object} updates - Partial encounter state to merge
*/
export function updateCurrentEncounter(updates) {
Object.assign(currentEncounter, updates);
}
/**
* Resets the encounter state
*/
export function resetEncounter() {
currentEncounter = {
active: false,
initialized: false,
combatHistory: [],
combatStats: null,
preEncounterContext: [],
encounterStartMessage: '',
encounterLog: []
};
}
/**
* Adds a message to combat history
* @param {string} role - Message role ('user', 'assistant', or 'system')
* @param {string} content - Message content
*/
export function addCombatMessage(role, content) {
currentEncounter.combatHistory.push({ role, content });
}
/**
* Adds an entry to the encounter log
* @param {string} action - The action taken
* @param {string} result - The result of the action
*/
export function addEncounterLogEntry(action, result) {
currentEncounter.encounterLog.push({
timestamp: Date.now(),
action,
result
});
}
/**
* Saves an encounter log for a specific chat
* @param {string} chatId - The chat identifier
* @param {object} logData - The encounter log data
*/
export function saveEncounterLog(chatId, logData) {
if (!encounterLogs[chatId]) {
encounterLogs[chatId] = [];
}
encounterLogs[chatId].push({
timestamp: new Date(),
log: logData.log || [],
summary: logData.summary || '',
result: logData.result || 'unknown'
});
}
/**
* Gets encounter logs for a specific chat
* @param {string} chatId - The chat identifier
* @returns {Array} Array of encounter logs
*/
export function getEncounterLogs(chatId) {
return encounterLogs[chatId] || [];
}
/**
* Clears all encounter logs for a specific chat
* @param {string} chatId - The chat identifier
*/
export function clearEncounterLogs(chatId) {
if (encounterLogs[chatId]) {
delete encounterLogs[chatId];
}
}
/**
* Exports encounter logs as JSON
* @param {string} chatId - The chat identifier
* @returns {string} JSON string of encounter logs
*/
export function exportEncounterLogs(chatId) {
const logs = getEncounterLogs(chatId);
return JSON.stringify(logs, null, 2);
}
+16 -1
View File
@@ -11,8 +11,9 @@ import { Generate } from '../../../../../../../script.js';
/**
* Sets up the plot progression buttons inside the send form area.
* @param {Function} handlePlotClick - Callback function to handle plot button clicks
* @param {Function} handleEncounterClick - Callback function to handle encounter button click
*/
export function setupPlotButtons(handlePlotClick) {
export function setupPlotButtons(handlePlotClick, handleEncounterClick) {
// Remove existing buttons if any
$('#rpg-plot-buttons').remove();
@@ -50,6 +51,19 @@ export function setupPlotButtons(handlePlotClick) {
" tabindex="0" role="button">
<i class="fa-solid fa-forward"></i> Natural Plot
</button>
<button id="rpg-encounter-button" class="menu_button interactable" style="
background-color: #cc3333;
color: white;
border: none;
padding: 8px 12px;
border-radius: 4px;
font-size: 13px;
cursor: pointer;
margin: 0 4px;
display: inline-block;
" tabindex="0" role="button" title="Enter combat encounter">
<i class="fa-solid fa-fire"></i> Enter Encounter
</button>
</span>
`;
@@ -59,6 +73,7 @@ export function setupPlotButtons(handlePlotClick) {
// Add event handlers for buttons
$('#rpg-plot-random').on('click', () => handlePlotClick('random'));
$('#rpg-plot-natural').on('click', () => handlePlotClick('natural'));
$('#rpg-encounter-button').on('click', () => handleEncounterClick());
// Show/hide based on setting
togglePlotButtons();