Merge branch 'sky15-second-wave'
This commit is contained in:
commit
6e2bb0ddab
@ -17,7 +17,7 @@
|
||||
</header>
|
||||
<h6>
|
||||
Chapter {chapter},
|
||||
<span class="battleNbr">battle {chapterBattle}?</span>
|
||||
<span class="battleNbr">battle {chapterBattle}</span>
|
||||
-- {status}
|
||||
</h6>
|
||||
<dl>
|
||||
@ -122,6 +122,8 @@
|
||||
$: character = battle?.character;
|
||||
$: city = battle?.city;
|
||||
|
||||
$: console.log(battle);
|
||||
|
||||
let chapter = 1 + parseInt(params.battleId / 2);
|
||||
let chapterBattle =
|
||||
params.battleId >= 7
|
||||
|
@ -9,6 +9,27 @@ const seedCampaign = {
|
||||
battles: [],
|
||||
};
|
||||
|
||||
export function updateBattle(campaign, battleId, status) {
|
||||
const battle = campaign.battles[battleId - 1];
|
||||
if (status === 'lost' && battle.wave == 1) {
|
||||
return u.updateIn(campaign, `battles.${battleId - 1}`, {
|
||||
wave: 2,
|
||||
});
|
||||
}
|
||||
campaign = u.updateIn(campaign, `battles.${battleId - 1}`, {
|
||||
status,
|
||||
});
|
||||
campaign = u(campaign, {
|
||||
battles: (battles) => [
|
||||
...battles,
|
||||
u(genNextBattle(battles), {
|
||||
id: battles.length + 1,
|
||||
}),
|
||||
],
|
||||
});
|
||||
return campaign;
|
||||
}
|
||||
|
||||
export function genApi(options = {}) {
|
||||
// if (options.local) MyPouch.plugin(pouchMem);
|
||||
if (options.pouch) options.pouch(PouchDB);
|
||||
@ -69,21 +90,7 @@ export function genApi(options = {}) {
|
||||
};
|
||||
|
||||
const setBattleVerdict = (battleId, status) => {
|
||||
let campaign = get(activeCampaign);
|
||||
|
||||
campaign = u.updateIn(campaign, `battles.${battleId - 1}`, {
|
||||
status,
|
||||
});
|
||||
|
||||
campaign = u(campaign, {
|
||||
battles: (battles) => [
|
||||
...battles,
|
||||
u(genNextBattle(campaign.battles), {
|
||||
id: battles.length + 1,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const campaign = updateBattle(get(activeCampaign), battleId, status);
|
||||
pouchdb.put(campaign).catch((e) => console.error(e));
|
||||
};
|
||||
|
||||
|
27
src/lib/store/updateBattle.test.js
Normal file
27
src/lib/store/updateBattle.test.js
Normal file
@ -0,0 +1,27 @@
|
||||
import { test, expect } from 'vitest';
|
||||
import { updateBattle } from './api.js';
|
||||
|
||||
test('lost, wave 1', () => {
|
||||
const result = updateBattle(
|
||||
{
|
||||
battles: [{ id: 1, wave: 1, status: 'ongoing' }],
|
||||
},
|
||||
1,
|
||||
'lost',
|
||||
);
|
||||
|
||||
expect(result).toHaveProperty('battles.0.wave', 2);
|
||||
expect(result).toHaveProperty('battles.0.status', 'ongoing');
|
||||
});
|
||||
|
||||
test('lost, wave 2', () => {
|
||||
const result = updateBattle(
|
||||
{
|
||||
battles: [{ id: 1, wave: 2, status: 'ongoing' }],
|
||||
},
|
||||
1,
|
||||
'lost',
|
||||
);
|
||||
|
||||
expect(result).toHaveProperty('battles.0.status', 'lost');
|
||||
});
|
Loading…
Reference in New Issue
Block a user