Populate campaign players array in combat replay and scenario
Both combat.js replay and Combat.scenario.test.js built character participants inline via buildCharacterParticipant without persisting to campaign doc. Real app stores chars in campaign doc players array; encounter participants built from that. Replay/scenario diverged from real flow — campaign had zero chars. Fix: - replay.js: roster chars now have id, persisted to campaign doc players array at setup_campaign step - Combat.scenario.test.js: addCharacterViaUI writes char to campaign doc players array (mirrors app), CAMPAIGN_PATH const added
This commit is contained in:
@@ -56,7 +56,7 @@ let display = {
|
||||
hideNpcHp: false,
|
||||
};
|
||||
const CAMPAIGN_ID = 'camp-1';
|
||||
const roster = [];
|
||||
const CAMPAIGN_PATH = `campaigns/${CAMPAIGN_ID}`;const roster = [];
|
||||
|
||||
let storage, ctx;
|
||||
const DISPLAY_PATH = 'activeDisplay/status';
|
||||
@@ -74,7 +74,16 @@ const any = (name) => enc.participants.find(p => p.name === name);
|
||||
const anyById = (id) => enc.participants.find(p => p.id === id);
|
||||
|
||||
function addCharacterViaUI(name, maxHp, initMod) {
|
||||
roster.push({ id: `char-${name}`, name, defaultMaxHp: maxHp, defaultInitMod: initMod });
|
||||
const character = { id: `char-${name}`, name, defaultMaxHp: maxHp, defaultInitMod: initMod };
|
||||
roster.push(character);
|
||||
// persist to campaign doc (mirrors app: players array)
|
||||
if (storage) {
|
||||
const existing = (storage.docs.get(CAMPAIGN_PATH) || {}).players || [];
|
||||
storage.setDoc(CAMPAIGN_PATH, {
|
||||
id: CAMPAIGN_ID, name: 'Scenario Campaign', createdAt: Date.now(),
|
||||
players: [...existing, character],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function addMonsterParticipant(name, maxHp, initMod, asNpc = false) {
|
||||
|
||||
Reference in New Issue
Block a user