refactor: single-source display lifecycle + scenario test no React
Move activeDisplay lifecycle to shared (one path, not duplicated in App):
- activateDisplay({campaignId, encounterId})
- clearDisplay()
- toggleHidePlayerHp(current)
All 6 App sites wired (start/end/2×delete-encounter/delete-campaign/hp-toggle).
Existing {patch,log} return shape preserved. No interface changes.
Combat.scenario.test.js rewritten to call shared directly, no React:
- Same actions as old UI version (roster chars, monsters, addAll, hp-toggle×2,
start, 100 rounds of damage/heal/conditions/toggle/edit/deathsave/pause/
resume/add/remove, end). Same funcs, same order, same data.
- Models two firestore docs (encounter + activeDisplay) via shared patches.
- Run time: 72s -> 4ms.
Both suites green: shared 91/91, App 77/77.
This commit is contained in:
@@ -552,6 +552,27 @@ function endEncounter(encounter) {
|
||||
};
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Display lifecycle (activeDisplay/status doc). Pure patches, same shape as
|
||||
// App's inline storage.updateDoc(getPath.activeDisplay(), ...). Single source.
|
||||
// Callers persist patch to the activeDisplay/status doc.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ACTIVATE_DISPLAY — start combat: point player display at this encounter.
|
||||
function activateDisplay({ campaignId, encounterId }) {
|
||||
return { patch: { activeCampaignId: campaignId, activeEncounterId: encounterId } };
|
||||
}
|
||||
|
||||
// CLEAR_DISPLAY — end combat: player display shows nothing.
|
||||
function clearDisplay() {
|
||||
return { patch: { activeCampaignId: null, activeEncounterId: null } };
|
||||
}
|
||||
|
||||
// TOGGLE_HIDE_PLAYER_HP — flip player-HP visibility on display.
|
||||
function toggleHidePlayerHp(currentValue) {
|
||||
return { patch: { hidePlayerHp: !currentValue } };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_MAX_HP,
|
||||
DEFAULT_INIT_MOD,
|
||||
@@ -579,4 +600,7 @@ module.exports = {
|
||||
toggleCondition,
|
||||
reorderParticipants,
|
||||
endEncounter,
|
||||
activateDisplay,
|
||||
clearDisplay,
|
||||
toggleHidePlayerHp,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user