esthetic work

This commit is contained in:
Yanick Champoux 2023-01-15 16:27:49 -05:00
parent 3e9ceddb48
commit bd5ba3ff7a
5 changed files with 132 additions and 41 deletions

View File

@ -1,12 +1,12 @@
<article class="scroll"> <article class="scroll">
<header class="fixed"> <header class="fixed fill">
<nav> <nav>
<a href="#/"> <a href="#/">
<button class="circle transparent"> <button class="circle transparent">
<i>menu</i> <i>menu</i>
</button></a </button></a
> >
<h5 class="max center-align"> <h5 class="max right-align">
{#if $activeCampaign} {#if $activeCampaign}
<a href={`#/campaign/${$activeCampaign._id}`}> <a href={`#/campaign/${$activeCampaign._id}`}>
{$activeCampaign.name} {$activeCampaign.name}
@ -16,9 +16,11 @@
</nav> </nav>
</header> </header>
<h6> <h6>
Chapter {chapter}, <span
<span class="battleNbr">battle {chapterBattle}</span> >Chapter {chapter},
-- {status} <span class="battleNbr">battle {chapterBattle}</span></span
>
<span class="status">{status}</span>
</h6> </h6>
<dl> <dl>
{#if status === 'ongoing' && chapter !== 4} {#if status === 'ongoing' && chapter !== 4}
@ -174,7 +176,7 @@
const changeCharacter = const changeCharacter =
(index) => (index) =>
({ target: { value } }) => { ({ target: { value } }) => {
event?.setCharacter(params.battleId, index, value); event?.setCharacter(params?.battleId, index, value);
}; };
const changeCity = ({ target: { value } }) => { const changeCity = ({ target: { value } }) => {
@ -184,18 +186,19 @@
<style> <style>
article { article {
width: 500px; height: 100vh;
}
header {
display: flex;
align-items: baseline;
} }
h5 { h5 {
flex: 1; flex: 1;
} }
h6 { h6 {
font-style: italic; display: flex;
font-size: 1.25rem; margin-bottom: 1em;
}
h6 .status {
flex: 1;
text-align: right;
padding-right: 1em;
} }
dl { dl {
width: 100%; width: 100%;
@ -222,4 +225,10 @@
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
nav h5 {
padding-right: 1em;
}
header nav {
max-width: 100%;
}
</style> </style>

View File

@ -1,12 +1,12 @@
<article class="scroll"> <article class="scroll">
<header class="fixed"> <header class="fixed fill">
<nav> <nav>
<a href="#/"> <a href="#/">
<button class="circle transparent"> <button class="circle transparent">
<i>menu</i> <i>menu</i>
</button></a </button></a
> >
<h5 class="max center-align"> <h5 class="max right-align">
{#if $activeCampaign} {#if $activeCampaign}
{$activeCampaign.name} {$activeCampaign.name}
{/if} {/if}
@ -15,6 +15,14 @@
</header> </header>
{#if $activeCampaign} {#if $activeCampaign}
{#if status !== 'ongoing'}
<h6>{status}</h6>{/if}
<div class="score">
score {#if status !== 'ongoing'}so far{/if}: {score}
<i>star</i>
</div>
<h6>Chapter 1</h6> <h6>Chapter 1</h6>
<Battle {...battles[0]} {campaignId} chapter={1} chapterBattle={1} /> <Battle {...battles[0]} {campaignId} chapter={1} chapterBattle={1} />
<div class="medium-divider" /> <div class="medium-divider" />
@ -101,7 +109,7 @@
{/if} {/if}
<footer class="fixed"> <footer class="fixed">
<nav> <nav>
<a href={`#/campaign/${$activeCampaign._id}/battle/1`}> <a href={`#/campaign/${$activeCampaign?._id}/battle/1`}>
<button class="circle transparent"> <button class="circle transparent">
<i>arrow_forward</i> <i>arrow_forward</i>
</button> </button>
@ -128,6 +136,9 @@
const campaignId = params.campaignId; const campaignId = params.campaignId;
$: score = $activeCampaign?.score;
$: status = $activeCampaign?.status;
$: byChapter = R.pipe( $: byChapter = R.pipe(
$activeCampaign?.battles ?? [], $activeCampaign?.battles ?? [],
R.groupBy(({ id }) => R.clamp(1 + parseInt(id / 2), { max: 4 })), R.groupBy(({ id }) => R.clamp(1 + parseInt(id / 2), { max: 4 })),
@ -137,6 +148,9 @@
</script> </script>
<style> <style>
.score {
text-align: right;
}
article { article {
height: 100vh; height: 100vh;
} }
@ -147,4 +161,7 @@
footer nav { footer nav {
text-align: right; text-align: right;
} }
nav h5 {
padding-right: 1em;
}
</style> </style>

View File

@ -5,7 +5,19 @@
{:else} {:else}
<a href={`#/campaign/${campaignId}/battle/${id}`}> <a href={`#/campaign/${campaignId}/battle/${id}`}>
Battle of {typeof city === 'string' ? city : city.selection}</a Battle of {typeof city === 'string' ? city : city.selection}</a
><span>, {status}</span> >
<div>
{#if status === 'ongoing' && wave == 2}
<i style="color: yellow">mood_bad</i>
{:else if status === 'ongoing' && wave == 1}
<i style="color: blue">sentiment_neutral</i>
{:else if status === 'lost'}
<i style="color: red">sentiment_very_dissatisfied</i>
{:else if status === 'won'}
<i style="color: green">mood</i>
{/if}
</div>
<div class="difficulty">{difficulty} <i>star</i></div>
{/if} {/if}
</p> </p>
</div> </div>
@ -14,10 +26,23 @@
export let city = ''; export let city = '';
export let status = ''; export let status = '';
export let id = 0; export let id = 0;
export let wave = 1;
export let campaignId; export let campaignId;
export let chapter; export let chapter;
export let chapterBattle; export let chapterBattle;
export let difficulty = 0;
</script> </script>
<style> <style>
.row p {
display: flex;
width: 100%;
}
.row p a {
display: inline-block;
flex: 1;
}
.difficulty {
margin-left: 1em;
}
</style> </style>

View File

@ -1,4 +1,4 @@
<header> <header class="fixed fill">
<nav> <nav>
<h5 class="max center-align">Campaigns</h5> <h5 class="max center-align">Campaigns</h5>
<button class="circle small" on:click={newCampaign}> <button class="circle small" on:click={newCampaign}>
@ -32,11 +32,13 @@
{/each} {/each}
</article> </article>
<div class="modal" class:active={showNewCampaign}> {#if showNewCampaign}
<div class="modal active">
<h5>New campaign</h5> <h5>New campaign</h5>
<div> <div>
<div class="field border"> <div class="field border">
<input <input
autofocus
type="text" type="text"
bind:value={newCampaignName} bind:value={newCampaignName}
placeholder="Campaign name" placeholder="Campaign name"
@ -47,9 +49,10 @@
<button class="border" on:click={() => (showNewCampaign = false)} <button class="border" on:click={() => (showNewCampaign = false)}
>Cancel</button >Cancel</button
> >
<button on:click={saveNewCampaign}>Create</button> <button type="submit" on:click={saveNewCampaign}>Create</button>
</nav> </nav>
</div> </div>
{/if}
<script> <script>
import * as R from 'remeda'; import * as R from 'remeda';
@ -65,7 +68,10 @@
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 }) => R.last(battles).city; const currentCity = ({ battles }) => {
const c = R.last(battles).city;
return typeof c === 'string' ? c : c.selection;
};
async function deleteCampaign({ name, _id }) { async function deleteCampaign({ name, _id }) {
if (!window.confirm(`delete campaign ${name}?`)) return; if (!window.confirm(`delete campaign ${name}?`)) return;

View File

@ -4,9 +4,34 @@ import { genNextBattle } from './genNextBattle.js';
import u from '@yanick/updeep-remeda'; import u from '@yanick/updeep-remeda';
const seedCampaign = { const seedCampaign = {
status: 'ongoing', // win, lost
score: 0,
battles: [], battles: [],
}; };
function campaignStatus(campaign) {
if (campaign.battles.length <= 6) return 'ongoing';
if (R.last(campaign.battles).status === 'won') return 'won';
if (
campaign.battles.length - 6 >=
campaign.battles.slice(0, 6).filter(({ status }) => status === 'won')
)
return 'lost';
return 'ongoing';
}
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);
}
export function updateBattle(campaign, battleId, status) { export function updateBattle(campaign, battleId, status) {
const battle = campaign.battles[battleId - 1]; const battle = campaign.battles[battleId - 1];
if (status === 'lost' && (battle.wave == 1 || battle.id < 7)) { if (status === 'lost' && (battle.wave == 1 || battle.id < 7)) {
@ -17,6 +42,14 @@ export function updateBattle(campaign, battleId, status) {
campaign = u.updateIn(campaign, `battles.${battleId - 1}`, { campaign = u.updateIn(campaign, `battles.${battleId - 1}`, {
status, status,
}); });
campaign = u.updateIn(campaign, 'score', calculateScore(campaign));
console.log(campaign);
campaign = u(campaign, {
status: campaignStatus(campaign),
});
if (campaign.status === 'ongoing') {
campaign = u(campaign, { campaign = u(campaign, {
battles: (battles) => [ battles: (battles) => [
...battles, ...battles,
@ -25,6 +58,7 @@ export function updateBattle(campaign, battleId, status) {
}), }),
], ],
}); });
}
return campaign; return campaign;
} }