From 931cb9d2373e13496ba0123c769681d19f111dad Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 15 Jan 2023 14:22:14 -0500 Subject: [PATCH 1/5] genChapter4 --- src/lib/store/genNextBattle.js | 28 ++++++++++++++++++++++++++++ src/lib/store/genNextBattle.test.js | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/lib/store/genNextBattle.js b/src/lib/store/genNextBattle.js index 34acce8..4f599a5 100644 --- a/src/lib/store/genNextBattle.js +++ b/src/lib/store/genNextBattle.js @@ -102,6 +102,32 @@ export function genChapter3Battle(battles) { }; } +export function genChapter4Battle(battles) { + const chapter = 4; + + const scenario = 'The Last Battle'; + + const cities = R.difference( + battles + .slice(0, 6) + .filter(({ status }) => status !== 'lost') + .map(R.prop('city')), + battles.slice(6).map((b) => b.city.selection), + ); + + const characters = battles.slice(0, 6).map(R.prop('character')); + + return { + scenario, + city: { choices: cities, selection: R.first(cities) }, + status: 'ongoing', + additionalCharacters: R.range(0, 3).map((i) => ({ + choices: characters, + selection: characters[i], + })), + }; +} + export function genNextBattle(battles = []) { let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 }); @@ -110,4 +136,6 @@ export function genNextBattle(battles = []) { if (chapter === 2) return genChapter2Battle(battles); if (chapter === 3) return genChapter3Battle(battles); + + return genChapter4Battle(battles); } diff --git a/src/lib/store/genNextBattle.test.js b/src/lib/store/genNextBattle.test.js index b184b9c..3369994 100644 --- a/src/lib/store/genNextBattle.test.js +++ b/src/lib/store/genNextBattle.test.js @@ -4,6 +4,7 @@ import { genNextBattle, genChapter2Battle, genChapter3Battle, + genChapter4Battle, } from './genNextBattle.js'; test('generate for the first chapter', () => { @@ -66,3 +67,20 @@ test('chapter 3, second battle', () => { expect(result.additionalCharacters[0].selection).toEqual('two'); expect(result.additionalCharacters[1].selection).toEqual('four'); }); + +test.only('chapter 4, first battle', () => { + const result = genChapter4Battle([ + { character: 'one', city: 'a' }, + { character: 'two', city: 'b', status: 'lost' }, + { character: 'three', city: 'c' }, + { character: 'four', city: 'd' }, + { character: 'five', city: 'e' }, + { character: 'six', city: 'f' }, + ]); + + expect(result.additionalCharacters[0].selection).toEqual('one'); + expect(result.additionalCharacters[1].selection).toEqual('two'); + expect(result.additionalCharacters[2].selection).toEqual('three'); + + expect(result.city.choices).not.toContain('b'); +}); From bf23443f3aac2043fe741a432223dd99863edd05 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 15 Jan 2023 14:40:32 -0500 Subject: [PATCH 2/5] chapter 4 groundwork --- src/lib/components/Battle.svelte | 25 ++++++-- .../components/Battle/Chapter4.story.svelte | 59 +++++++++++++++++++ src/lib/store/api.js | 9 +++ src/lib/store/genNextBattle.js | 1 + 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 src/lib/components/Battle/Chapter4.story.svelte diff --git a/src/lib/components/Battle.svelte b/src/lib/components/Battle.svelte index 2aa87dd..c1e6cbb 100644 --- a/src/lib/components/Battle.svelte +++ b/src/lib/components/Battle.svelte @@ -21,16 +21,29 @@ -- {status}
- {#if status === 'ongoing'} + {#if status === 'ongoing' && chapter !== 4}
wave
{wave === 2 ? 'second' : 'first'}
{/if}
city
-
{city}
+
+ {#if typeof city === 'string'} + {city} + {:else} + + {/if} +
scenario
{scenario}
-
character
-
{character}
+ + {#if character} +
character
+
{character}
+ {/if} {#if additionalCharacters} {#each additionalCharacters as c, i (c.selection)} @@ -161,6 +174,10 @@ ({ target: { value } }) => { event?.setCharacter(params.battleId, index, value); }; + + const changeCity = ({ target: { value } }) => { + event?.setCity(params.battleId, value); + }; diff --git a/src/lib/components/Campaign.svelte b/src/lib/components/Campaign.svelte index 4006d09..29528d6 100644 --- a/src/lib/components/Campaign.svelte +++ b/src/lib/components/Campaign.svelte @@ -1,12 +1,12 @@
-
+
{#if $activeCampaign} + {#if status !== 'ongoing'} +
{status}
{/if} + +
+ score {#if status !== 'ongoing'}so far{/if}: {score} + star +
+
Chapter 1
@@ -14,10 +26,23 @@ export let city = ''; export let status = ''; export let id = 0; + export let wave = 1; export let campaignId; export let chapter; export let chapterBattle; + export let difficulty = 0; diff --git a/src/lib/components/Campaigns.svelte b/src/lib/components/Campaigns.svelte index 4a08e2f..99e1c32 100644 --- a/src/lib/components/Campaigns.svelte +++ b/src/lib/components/Campaigns.svelte @@ -1,4 +1,4 @@ -
+
-