diff --git a/src/routes/game/Components/Layout.svelte b/src/routes/game/Components/Layout.svelte index 01c5731..7226f95 100644 --- a/src/routes/game/Components/Layout.svelte +++ b/src/routes/game/Components/Layout.svelte @@ -2,9 +2,10 @@ import Section from '$lib/components/Common/Section.svelte' import Button from '$lib/components/Buttons/Button.svelte' import Image from '$lib/components/Common/Image.svelte' + import { createEventDispatcher } from 'svelte' + const dispatch = createEventDispatcher() export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null - export let nextQuestion export let imgSrc @@ -40,7 +41,7 @@ {/if} {#if control === 'not-control' || control === 'correct' || control === 'wrong-secondTime'} - + {:else if control === 'wrong-firstTime' || control === null} {/if} diff --git a/src/routes/game/Forms/Info.svelte b/src/routes/game/Forms/Info.svelte index c511581..7914f62 100644 --- a/src/routes/game/Forms/Info.svelte +++ b/src/routes/game/Forms/Info.svelte @@ -1,24 +1,4 @@ - { - nextQuestion() - }} -> - {name} - {@html checkPoint.CPText} - - - \ No newline at end of file +
diff --git a/src/routes/game/Forms/MultiChoiceForm.svelte b/src/routes/game/Forms/MultiChoiceForm.svelte index c0b2263..88600e3 100644 --- a/src/routes/game/Forms/MultiChoiceForm.svelte +++ b/src/routes/game/Forms/MultiChoiceForm.svelte @@ -4,44 +4,20 @@ import { CheckPoint } from '$lib/TStypes/experiences' import { answer } from '$lib/utils/database/game' - export let data: { name: string; checkPoint: CheckPoint } - const { checkPoint, name } = data + export let checkPoint: CheckPoint + export let myAnswer + + export let clear: false | true = false + $: if (clear) myAnswers = new Array(checkPoint.CPOptions.length).fill(false) + let myAnswers = new Array(checkPoint.CPOptions.length).fill(false) - - export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null - export let nextQuestion - - const answerCheckBox = async () => { - const arr = checkPoint.CPOptions.filter((item, i) => { - if (myAnswers[i] === true) return item - }) - const res = await answer(checkPoint.$id, arr) - if (res) control = 'correct' - else if (control === null) { - control = 'wrong-firstTime' - myAnswers = new Array(checkPoint.CPOptions.length).fill(false) //nulling answers - } else control = 'wrong-secondTime' - } + $: myAnswer = checkPoint.CPOptions.filter((item, i) => { + if (myAnswers[i] === true) return item + }) - { - nextQuestion() - myAnswers = new Array(checkPoint.CPOptions.length).fill(false) - }} - {control} - on:submit={async () => answerCheckBox()} -> - {name} - {@html checkPoint.CPText} - {@html checkPoint.CPHint} - {@html checkPoint.CPAfter} -
- {#each checkPoint.CPOptions as label, i} - - {label} - - {/each} -
-
+{#each checkPoint.CPOptions as label, i} + + {label} + +{/each} diff --git a/src/routes/game/Forms/NumberForm.svelte b/src/routes/game/Forms/NumberForm.svelte index e4770bf..75c703a 100644 --- a/src/routes/game/Forms/NumberForm.svelte +++ b/src/routes/game/Forms/NumberForm.svelte @@ -1,49 +1,9 @@ - { - nextQuestion() - myAnswer = '' - }} - {control} - on:submit={() => (myAnswer !== '' ? answer_() : null)} -> - {name} - {@html checkPoint.CPText} - {@html checkPoint.CPHint} - {@html checkPoint.CPAfter} - -
- - - -
-
- - + diff --git a/src/routes/game/Forms/Renderer.svelte b/src/routes/game/Forms/Renderer.svelte index aa6b2aa..8914c2a 100644 --- a/src/routes/game/Forms/Renderer.svelte +++ b/src/routes/game/Forms/Renderer.svelte @@ -1,5 +1,4 @@ - + -{#if view === 'map'} +{#if view === 'map' || view === 'start-map'} - (view = 'question')} {lat} {lng} {user} /> + (view = view === 'start-map' ? 'map' : 'question')} {lat} {lng} {user} /> {/if} {#if view === 'question'} - + checkAnswer()} on:nextQuestion={nextQuestion} {control}> + {checkPoint.CPName} + {@html checkPoint.CPText} + + + {#if checkPoint.CPHint} + {@html checkPoint.CPHint} + {/if} + + + {#if checkPoint.CPAfter} + {@html checkPoint.CPAfter} + {/if} + +
+ + + +
+
{/if} {#if view === 'end'} diff --git a/src/routes/game/Forms/SingleChoiceForm.svelte b/src/routes/game/Forms/SingleChoiceForm.svelte index ba3c2c3..9119ec5 100644 --- a/src/routes/game/Forms/SingleChoiceForm.svelte +++ b/src/routes/game/Forms/SingleChoiceForm.svelte @@ -4,45 +4,15 @@ import { CheckPoint } from '$lib/TStypes/experiences' import { answer } from '$lib/utils/database/game' - export let data: { name: string; checkPoint: CheckPoint } - const { checkPoint, name } = data - let myAnswer = '' + export let checkPoint: CheckPoint + export let myAnswer = '' - export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null - export let nextQuestion - - const answer_ = async () => { - const res = await answer(checkPoint.$id, myAnswer) - if (res) control = 'correct' - else if (control === null) { - control = 'wrong-firstTime' - myAnswer = '' - } else control = 'wrong-secondTime' - } + export let clear: false | true = false + $: if (clear) myAnswer = '' - { - nextQuestion() - myAnswer = '' - }} - on:submit={() => (myAnswer !== '' ? answer_() : null)} -> - {name} - {@html checkPoint.CPText} - {@html checkPoint.CPHint} - {@html checkPoint.CPAfter} - -
- {#each checkPoint.CPOptions as label} - - {label} - - {/each} -
-
- - +{#each checkPoint.CPOptions as label} + + {label} + +{/each} diff --git a/src/routes/game/Forms/TextForm.svelte b/src/routes/game/Forms/TextForm.svelte index db4ef6b..0bb0805 100644 --- a/src/routes/game/Forms/TextForm.svelte +++ b/src/routes/game/Forms/TextForm.svelte @@ -4,40 +4,9 @@ import { CheckPoint } from '$lib/TStypes/experiences' import { answer } from '$lib/utils/database/game' - export let data: { name: string; checkPoint: CheckPoint } - const { checkPoint, name } = data - let myAnswer = '' - - export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null - export let nextQuestion - - const answer_ = async () => { - const res = await answer(checkPoint.$id, myAnswer) - if (res) control = 'correct' - else if (control === null) control = 'wrong-firstTime' - else control = 'wrong-secondTime' - } + export let myAnswer = '' + export let clear: false | true = false + $: if (clear) myAnswer = '' - { - nextQuestion() - myAnswer = '' - }} - on:submit={() => (myAnswer !== '' ? answer_() : null)} -> - {name} - {@html checkPoint.CPText} - {@html checkPoint.CPHint} - {@html checkPoint.CPAfter} -
- - - -
-
- - + diff --git a/src/routes/game/game.svelte b/src/routes/game/game.svelte index 05b4064..fcca3df 100644 --- a/src/routes/game/game.svelte +++ b/src/routes/game/game.svelte @@ -19,10 +19,10 @@ onMount(async () => { try { - $data = await load(params.gameurl, 5, (preview) => { + $data = await load(params.gameurl, 10, (preview) => { $data = preview + view = 'game-preview' }) - view = 'game-preview' } catch (error) { navigate('/error') }