aboutsummaryrefslogtreecommitdiff
path: root/routes/+page.svelte
blob: debc06842b3d92db5772888e8e6ba77fc7f6330c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<script lang="ts">
  import { onMount } from 'svelte'
  import { goto } from '$app/navigation'
  import { assets, resolve } from '$app/paths'
  import BeginScreen from '@hollowdark/lib/screens/BeginScreen.svelte'
  import InitialLoadScreen from '@hollowdark/lib/screens/InitialLoadScreen.svelte'
  import { runInitialLoad } from '@hollowdark/loading/content'
  import { detectBeginState, type BeginState } from '@hollowdark/loading/session'
  import {
    hasCompletedInitialLoad,
    markInitialLoadComplete
  } from '@hollowdark/loading/lifecycle'

  type View = 'loading' | 'begin'

  let view: View = $state(hasCompletedInitialLoad() ? 'begin' : 'loading')
  let beginState: BeginState = $state({ kind: 'first-ever' })

  onMount(async () => {
    if (!hasCompletedInitialLoad()) {
      await runInitialLoad(assets)
      markInitialLoadComplete()
    }
    beginState = await detectBeginState()
    view = 'begin'
  })

  function handleBegin(): void {}
  function handleContinue(): void {}
  function handleSettings(): void {
    goto(resolve('/settings'))
  }
  function handleCredits(): void {
    goto(resolve('/credits'))
  }
</script>

{#if view === 'loading'}
  <InitialLoadScreen />
{:else}
  <BeginScreen
    state={beginState}
    onBegin={handleBegin}
    onContinue={handleContinue}
    onSettings={handleSettings}
    onCredits={handleCredits}
  />
{/if}