import { campaignChain } from '@datamoc/mw_games/mwl';
import { Campaign } from '@datamoc/mw_games/simulation';
const definition = {
id: 'prologue',
firstScenario: 'opening',
scenarios: [{ id: 'opening', nextScenario: 'siege' }, { id: 'siege' }],
};
const chain = campaignChain(definition, {
run: (scenario, state) => ({ outcome: 'completed', state, result: scenario.id }),
});
const campaign = new Campaign({ levels: chain.levels, start: chain.start, state: { gold: 100 } });
campaign.playCurrent();
console.log(campaign.currentLevel); // 'siege'
campaign.playCurrent();
console.log(campaign.currentLevel); // null - the chain is done
Points a
[campaign]atsimulation.Campaign: the order comes out of the content, the playing stays the game's.first_scenarioopens the campaign, and the first declared scenario opens it when the attribute is not set. Each scenario'snext_scenariois where it goes when it is won, and a scenario that ends the chain leaves it: the campaign finishes. A scenario that decides for itself keeps its decision, because a result carryingnextis passed through untouched - which is exactly what a runtime[endlevel]does when it overrides the authored chain.Malformed chains throw by name rather than being guessed at: no scenarios, the same id twice, or a
first_scenarionaming something the campaign does not have.