navigation

This commit is contained in:
Yanick Champoux 2023-01-16 13:53:22 -05:00
parent 48292a0ca5
commit 365610184a
4 changed files with 82 additions and 28 deletions

View File

@ -48,10 +48,10 @@
{:else} {:else}
<AdditionalCharacter <AdditionalCharacter
on:change={changeCity} on:change={changeCity}
selection={city.selection} selection={city?.selection}
choices={status !== 'ongoing' choices={status !== 'ongoing'
? [] ? []
: city.choices.filter( : city?.choices?.filter(
(c) => c !== city.selection, (c) => c !== city.selection,
)} )}
/> />
@ -120,6 +120,8 @@
</dd> </dd>
</dl> </dl>
<div class="space" />
<div class="actions"> <div class="actions">
{#if status === 'upcoming'} {#if status === 'upcoming'}
<button>Start battle</button> <button>Start battle</button>
@ -133,10 +135,11 @@
> >
{/if} {/if}
</div> </div>
<div class="space" />
</div> </div>
{/key} {/key}
<footer class="fixed"> <footer class="absolute center bottom">
<nav> <nav>
<a <a
on:click={() => on:click={() =>
@ -151,26 +154,32 @@
<i>arrow_backward</i> <i>arrow_backward</i>
</button> </button>
</a> </a>
{#if battles?.length > battle?.id}
<a <a href={`#/campaign/${$activeCampaign?._id}`}>
on:click={() => <button class="circle transparent">
transition.goRight( <i>arrow_upward</i>
`/campaign/${$activeCampaign?._id}/battle/${ </button>
battle?.id + 1 </a>
}`,
)} <button
> on:click={() =>
<button class="circle transparent"> transition.goRight(
<i>arrow_forward</i> `/campaign/${$activeCampaign?._id}/battle/${
</button> battle?.id + 1
</a> }`,
{/if} )}
disabled={battles?.length <= battle?.id}
class="circle transparent"
>
<i>arrow_forward</i>
</button>
</nav> </nav>
</footer> </footer>
</article> </article>
{/if} {/if}
<script> <script>
import { push } from 'svelte-spa-router';
import * as R from 'remeda'; import * as R from 'remeda';
import { getContext } from 'svelte'; import { getContext } from 'svelte';
import AdditionalCharacter from './Battle/AdditionalCharacter.svelte'; import AdditionalCharacter from './Battle/AdditionalCharacter.svelte';
@ -207,9 +216,34 @@
? params.battleId - 6 ? params.battleId - 6
: 1 + ((params.battleId - 1) % 2); : 1 + ((params.battleId - 1) % 2);
const battleVerdict = (verdict) => () => const battleVerdict = (verdict) => () => {
event?.setBattleVerdict(params.battleId, verdict); event?.setBattleVerdict(params.battleId, verdict);
if (verdict === 'lost') {
if (chapter === 4) {
push('/campaign/' + $activeCampaign._id);
} else if (wave === 2) {
push(
'/campaign/' +
$activeCampaign._id +
'/battle/' +
(parseInt(params.battleId) + 1),
);
}
} else {
if (chapter === 4) {
push('/campaign/' + $activeCampaign._id);
} else {
push(
'/campaign/' +
$activeCampaign._id +
'/battle/' +
(parseInt(params.battleId) + 1),
);
}
}
};
// $: event.setBattleDifficulty(params.battleId, difficulty); // $: event.setBattleDifficulty(params.battleId, difficulty);
const changeCharacter = const changeCharacter =
@ -271,6 +305,10 @@
input { input {
width: 5em; width: 5em;
} }
footer {
width: 100%;
padding: 0px 1em;
}
footer nav { footer nav {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;

View File

@ -17,14 +17,23 @@
{#key params.campaignId} {#key params.campaignId}
<div in:fly={flyParams} class="body"> <div in:fly={flyParams} class="body">
{#if $activeCampaign} {#if $activeCampaign}
{#if status !== 'ongoing'} {#if status === 'won'}
<h6>{status}</h6>{/if} <h4 class="blue-text">
{status.toUpperCase()}
<div class="score"> &nbsp; &nbsp;
score {#if status !== 'ongoing'}so far{/if}: {score} {score}
<i>star</i> <i>star</i>
</div> </h4>
{:else if status === 'lost'}
<h4 class="red-text">
{status.toUpperCase()}
</h4>
{:else}
<div class="score">
score {#if status !== 'ongoing'}so far{/if}: {score}
<i>star</i>
</div>
{/if}
<h6>Chapter 1</h6> <h6>Chapter 1</h6>
<Battle <Battle
{...battles[0]} {...battles[0]}
@ -173,4 +182,9 @@
nav h5 { nav h5 {
padding-right: 1em; padding-right: 1em;
} }
h4 {
text-align: center;
width: 100%;
display: inline-block;
}
</style> </style>

View File

@ -74,8 +74,8 @@
const currentChapter = ({ battles }) => const currentChapter = ({ battles }) =>
R.clamp(1 + parseInt(battles?.length / 2), { max: 4 }); R.clamp(1 + parseInt(battles?.length / 2), { max: 4 });
const currentCity = ({ battles }) => { const currentCity = ({ battles }) => {
const c = R.last(battles).city; const c = R.last(battles)?.city;
return typeof c === 'string' ? c : c.selection; return typeof c === 'string' ? c : c?.selection;
}; };
async function deleteCampaign({ name, _id }) { async function deleteCampaign({ name, _id }) {

View File

@ -46,6 +46,7 @@ export function updateBattle(campaign, battleId, status) {
campaign = u.updateIn(campaign, 'score', calculateScore(campaign)); campaign = u.updateIn(campaign, 'score', calculateScore(campaign));
return campaign; return campaign;
} }
campaign = u.updateIn(campaign, `battles.${battleId - 1}`, { campaign = u.updateIn(campaign, `battles.${battleId - 1}`, {
status, status,
}); });
@ -65,6 +66,7 @@ export function updateBattle(campaign, battleId, status) {
}), }),
], ],
}); });
console.log('updated', campaign);
} }
return campaign; return campaign;
} }