fix: carry roster stats into encounters and add one-time sync choice

- use shared character participant builder for single-add and Add All so saved current HP, Max HP, AC, and stable state carry forward
- add End Encounter checkbox to override character writeback for one action
- default transient checkbox from campaign preference without persisting changes
- support explicit writeback override in shared endEncounter logic
- cover both add paths and modal enable/disable/reset behavior
This commit is contained in:
david raistrick committed 2026-10-13 22:18:35 -04:00
1 parent 8d71f0ba4b
commit bca406fca9
5 files changed
+272 -49

No files matched your search

+5 -3
View File
@@ -380,8 +380,7 @@ function makeParticipant(opts) {
};
}
function buildCharacterParticipant(character) {
const initiativeRoll = rollD20();
function buildCharacterParticipant(character, initiativeRoll = rollD20()) {
const modifier = character.defaultInitMod || 0;
const finalInitiative = initiativeRoll + modifier;
const maxHp = character.defaultMaxHp || DEFAULT_MAX_HP;
@@ -1168,7 +1167,10 @@ async function endEncounter(encounter, ctx) {
try {
campaign = ctx.campaign || await ctx.storage.getDoc(campaignPath);
} catch { campaign = null; }
if (campaign && campaign.syncCharacters && Array.isArray(campaign.players)) {
const syncCharacters = ctx.syncCharacters !== undefined
? ctx.syncCharacters
: campaign?.syncCharacters;
if (campaign && syncCharacters && Array.isArray(campaign.players)) {
const charParticipants = (encounter.participants || []).filter(p => p.originalCharacterId);
const oldValues = [];
let changed = false;