From c1e3708b878b675eae021a5a6cee06241973ea90 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Mon, 16 Jan 2023 11:55:30 -0500 Subject: [PATCH] change yellow for orange --- src/lib/components/Campaign.svelte | 2 +- src/lib/components/Campaign/Battle.svelte | 2 +- src/lib/store/api.js | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/lib/components/Campaign.svelte b/src/lib/components/Campaign.svelte index b6c2147..83c3534 100644 --- a/src/lib/components/Campaign.svelte +++ b/src/lib/components/Campaign.svelte @@ -64,7 +64,7 @@ />
{#if status === 'ongoing' && wave == 2} - mood_bad + mood_bad {:else if status === 'ongoing' && wave == 1} sentiment_neutral {:else if status === 'lost'} diff --git a/src/lib/store/api.js b/src/lib/store/api.js index 4938a29..6d863ee 100644 --- a/src/lib/store/api.js +++ b/src/lib/store/api.js @@ -25,20 +25,26 @@ function campaignStatus(campaign) { } function calculateScore(campaign) { - return [ - // -campaign.battles.slice(0, 6).filter(({ wave }) => wave === 2).length, - // -campaign.battles.slice(6).filter(({ status }) => status === 'lost') - // .length, - ...campaign.battles.map(({ difficulty }) => parseInt(difficulty)), - ].reduce((a, b) => a + b, 0); + const values = [ + -campaign.battles.slice(0, 6).filter(({ wave }) => wave === 2).length, + -campaign.battles.slice(6).filter(({ status }) => status === 'lost') + .length, + ...campaign.battles + .map(({ difficulty }) => parseInt(difficulty)) + .map((x) => (Number.isNaN(x) ? 0 : x)), + ]; + console.log(values); + return values.reduce((a, b) => a + b, 0); } export function updateBattle(campaign, battleId, status) { const battle = campaign.battles[battleId - 1]; - if (status === 'lost' && (battle.wave == 1 || battle.id < 7)) { - return u.updateIn(campaign, `battles.${battleId - 1}`, { + if (status === 'lost' && battle.wave == 1 && battle.id < 7) { + campaign = u.updateIn(campaign, `battles.${battleId - 1}`, { wave: 2, }); + campaign = u.updateIn(campaign, 'score', calculateScore(campaign)); + return campaign; } campaign = u.updateIn(campaign, `battles.${battleId - 1}`, { status,