diff --git a/src/lib/components/EndScreen.svelte b/src/lib/components/EndScreen.svelte index 218127b..9a446a3 100644 --- a/src/lib/components/EndScreen.svelte +++ b/src/lib/components/EndScreen.svelte @@ -2,56 +2,48 @@ import { fly, fade } from "svelte/transition" import { backOut as easing, linear } from "svelte/easing" - import { userState, gameState, gameSettings, successMetrics, farm } from "$lib/stores/state" + import { + userState, + gameState, + gameSettings, + successMetrics, + farm, + gameHistory + } from "$lib/stores/state" - import BlockGameState from "$lib/components/BlockGameState.svelte" - import Button from "$lib/components/Button.svelte" import Modal from "$lib/components/Modal.svelte" - import Farm from "$lib/components/Farm.svelte" + import BlockGameState from "$lib/components/BlockGameState.svelte" + import EndScreenFail from "$lib/components/EndScreenFail.svelte" + import EndScreenSuccess from "$lib/components/EndScreenSuccess.svelte" let slideIndex = 0 const flyIn = { y: 8, easing, delay: 600, duration: 1200 } - const restart = () => { + const reset = () => { $farm.reset() - $farm = $farm $gameState.reset() + $farm = $farm + $gameHistory = [] $gameState = $gameState + $gameHistory = $gameHistory } $: $userState.isGameComplete = $successMetrics.hasSucceeded || $successMetrics.hasFailed {#if $userState.isGameComplete} - +
-

- You {$successMetrics.hasSucceeded ? "Won" : "Lost"}! -

+

+ You {$successMetrics.hasSucceeded ? "Won 🎊" : "Lost 😮‍💨"} +

{#if $successMetrics.hasFailed} -

Here's your problem:

-

- Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis aliquam, ratione - eligendi ex fugiat soluta reprehenderit delectus debitis, blanditiis deserunt - perferendis molestias expedita. Vitae, non? Totam illo molestiae vitae, iste non - perspiciatis beatae facilis sapiente odit delectus nihil. -

- + {:else if $successMetrics.hasSucceeded} -

Congratulations, you closed the food gap!

- -
- - -
+ {:else}

An error has occurred.

{/if} @@ -85,6 +77,9 @@ font-size: 1.125rem line-height: 1.3 +.slide-title + font-size: 2rem + .buttons gap: 0.75rem diff --git a/src/lib/components/EndScreenFail.svelte b/src/lib/components/EndScreenFail.svelte new file mode 100644 index 0000000..a37a560 --- /dev/null +++ b/src/lib/components/EndScreenFail.svelte @@ -0,0 +1,132 @@ + + +{#if failedItem} +
+
+

+ Nice try! In {$gameState.year.current - $gameState.year.start} years you managed to increase + food production by {prettyPercent($successMetrics.calorieProductionChange)} and feed an additional + {largeNumber($gameState.population.current - $gameState.population.start)} people. +

+
+ + +
+
+
+ +

+ You failed to keep {failedItem.label} + {failedItem.value > failedItem.limit ? "under" : "over"} + {failedItem.limit}{failedItem.suffix}. +

+ +
+
{failedItem.label}
+
+ +
+
+
+
+

+ {prettyList(foods.slice(0, 3).map((f) => f.name))} + have the highest + {failedItem.label} + per hectare of land, whereas + {prettyList( + foods + .slice(-3) + .map((f) => f.name) + .reverse() + )} + have the lowest. Harness this knowledge and try to close the food gap again! +

+ + + +
+
+{:else} +

An error has occurred.

+{/if} + + diff --git a/src/lib/components/EndScreenSuccess.svelte b/src/lib/components/EndScreenSuccess.svelte new file mode 100644 index 0000000..84e0f02 --- /dev/null +++ b/src/lib/components/EndScreenSuccess.svelte @@ -0,0 +1,19 @@ + + +

Congratulations, you closed the food gap!

+ +
+ + +
diff --git a/src/lib/components/Modal.svelte b/src/lib/components/Modal.svelte index a84e177..45b8d4d 100644 --- a/src/lib/components/Modal.svelte +++ b/src/lib/components/Modal.svelte @@ -8,6 +8,7 @@ export let close = () => {} export let classList = "" export let isError = false + export let fullWidth = false export let fullscreen = false export let durationIn = 200 export let durationOut = 100 @@ -33,6 +34,7 @@ aria-modal="true" class:fullscreen class:error={isError} + class:w-full={fullWidth} on:click={close} on:keydown={handleKeydown} in:fade={{ duration: durationIn }} @@ -111,6 +113,9 @@ $radius: 1rem color: var(--color-secondary-1) background: transparent + .w-full & + width: 100% + .has-title & padding: $radius diff --git a/src/lib/stores/state.ts b/src/lib/stores/state.ts index 6fba0f1..34c2d43 100644 --- a/src/lib/stores/state.ts +++ b/src/lib/stores/state.ts @@ -95,7 +95,10 @@ export const successMetrics = derived( limit: proteinPerPersonPerDayLimit, objective: `Keep above ${proteinPerPersonPerDayLimit}g`, warn: proteinPerPersonPerDayValue < proteinPerPersonPerDayLimit + 3, + fail: proteinPerPersonPerDayValue < proteinPerPersonPerDayLimit, history: $gameHistory.map((o) => o.proteinPerPersonPerDay), + farmMetricKey: "protein", + foodMetricKey: "proteinRatio", chartSettings: { yLimit: proteinPerPersonPerDayLimit, yMin: proteinPerPersonPerDayLimit, @@ -111,7 +114,10 @@ export const successMetrics = derived( limit: emissionsChangeLimit, objective: `Keep below +${100 * emissionsChangeLimit}%`, warn: emissionsChangeValue > emissionsChangeLimit - 0.02, + fail: emissionsChangeValue > emissionsChangeLimit, history: $gameHistory.map((o) => o.emissionsChange), + farmMetricKey: "emissions", + foodMetricKey: "emissionsPerKg", chartSettings: { yDatum: 0, yLimit: emissionsChangeLimit, @@ -128,7 +134,10 @@ export const successMetrics = derived( limit: waterUseChangeLimit, objective: `Keep below +${100 * waterUseChangeLimit}%`, warn: waterUseChangeValue > waterUseChangeLimit - 0.05, + fail: waterUseChangeValue > waterUseChangeLimit, history: $gameHistory.map((o) => o.waterUseChange), + farmMetricKey: "waterUse", + foodMetricKey: "waterUsePerKg", chartSettings: { yDatum: 0, yLimit: waterUseChangeLimit, @@ -144,7 +153,10 @@ export const successMetrics = derived( limit: eutrophyChangeLimit, objective: `Keep below +${100 * eutrophyChangeLimit}%`, warn: eutrophyChangeValue > eutrophyChangeLimit - 0.05, + fail: eutrophyChangeValue > eutrophyChangeLimit, history: $gameHistory.map((o) => o.eutrophyChange), + farmMetricKey: "eutrophy", + foodMetricKey: "eutrophyPerKg", chartSettings: { yDatum: 0, yLimit: eutrophyChangeLimit, diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ed21fa9..7851728 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -63,7 +63,7 @@ - + diff --git a/src/styles/core/typography.sass b/src/styles/core/typography.sass index 9deefb3..b1654ad 100644 --- a/src/styles/core/typography.sass +++ b/src/styles/core/typography.sass @@ -3,7 +3,7 @@ p h1,h2,h3 font-weight: bold - margin-bottom: 0.5em + margin-bottom: 0.4em .title font-size: 3rem