Fix dice roll saving: only save when 'Save Roll' is clicked
- Add pendingDiceRoll variable to store temporary roll result - Clicking X or overlay now discards the roll without saving - Only save to settings when user explicitly clicks 'Save Roll' button - Prevents unwanted rolls from being saved to the sidebar display
This commit is contained in:
@@ -80,6 +80,9 @@ let isGenerating = false;
|
|||||||
// Tracks if we're currently doing a plot progression
|
// Tracks if we're currently doing a plot progression
|
||||||
let isPlotProgression = false;
|
let isPlotProgression = false;
|
||||||
|
|
||||||
|
// Temporary storage for pending dice roll (not saved until user clicks "Save Roll")
|
||||||
|
let pendingDiceRoll = null;
|
||||||
|
|
||||||
// UI Elements
|
// UI Elements
|
||||||
let $panelContainer = null;
|
let $panelContainer = null;
|
||||||
let $userStatsContainer = null;
|
let $userStatsContainer = null;
|
||||||
@@ -655,6 +658,8 @@ function setupDiceRoller() {
|
|||||||
|
|
||||||
// Close popup
|
// Close popup
|
||||||
$('#rpg-dice-popup-close, .rpg-dice-popup-overlay').on('click', function() {
|
$('#rpg-dice-popup-close, .rpg-dice-popup-overlay').on('click', function() {
|
||||||
|
// Discard pending roll without saving
|
||||||
|
pendingDiceRoll = null;
|
||||||
closeDicePopup();
|
closeDicePopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -663,8 +668,15 @@ function setupDiceRoller() {
|
|||||||
await rollDice();
|
await rollDice();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save roll button (closes popup)
|
// Save roll button (closes popup and saves the roll)
|
||||||
$('#rpg-dice-save-btn').on('click', function() {
|
$('#rpg-dice-save-btn').on('click', function() {
|
||||||
|
// Save the pending roll
|
||||||
|
if (pendingDiceRoll) {
|
||||||
|
extensionSettings.lastDiceRoll = pendingDiceRoll;
|
||||||
|
saveSettings();
|
||||||
|
updateDiceDisplay();
|
||||||
|
pendingDiceRoll = null;
|
||||||
|
}
|
||||||
closeDicePopup();
|
closeDicePopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -753,14 +765,13 @@ async function rollDice() {
|
|||||||
const total = rollResult.total || 0;
|
const total = rollResult.total || 0;
|
||||||
const rolls = rollResult.rolls || [];
|
const rolls = rollResult.rolls || [];
|
||||||
|
|
||||||
// Store result
|
// Store result temporarily (not saved until "Save Roll" is clicked)
|
||||||
extensionSettings.lastDiceRoll = {
|
pendingDiceRoll = {
|
||||||
formula: `${count}d${sides}`,
|
formula: `${count}d${sides}`,
|
||||||
total: total,
|
total: total,
|
||||||
rolls: rolls,
|
rolls: rolls,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
saveSettings();
|
|
||||||
|
|
||||||
// Hide animation and show result
|
// Hide animation and show result
|
||||||
$('#rpg-dice-animation').hide();
|
$('#rpg-dice-animation').hide();
|
||||||
@@ -773,8 +784,7 @@ async function rollDice() {
|
|||||||
$('#rpg-dice-result-details').text('');
|
$('#rpg-dice-result-details').text('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update sidebar display
|
// Don't update sidebar display yet - only update when user clicks "Save Roll"
|
||||||
updateDiceDisplay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user