checkPoints

This commit is contained in:
Ota Prokopec 2023-02-19 20:59:30 +01:00
parent 4067ec2fa9
commit 5e2481754f
9 changed files with 103 additions and 62 deletions

View File

@ -0,0 +1,31 @@
export type checkPoint = {
$id: string
CPAfter: string
CPAnswerID: string
CPHint: string
CPImage?: string
CPLocation: number[]
CPMoveHelp?: string
CPName: string
CPOptions?: string[]
CPText: string
CPType: 'CHECKBOX' | 'TEXT' | 'INFO' | 'RADIO' | 'NUMBER'
}
export type expirience = {
ExpApproved: boolean
ExpCpsID: string[]
ExpCategory?: string
ExpEnd0: string
ExpEnd60: string
ExpEnd100: string
ExpImage?: string
ExpIntroduction: string
ExpLocation: number[]
ExpName: string
ExpStart: string
ExpTestingCode: string
ExpURL: string
UserID: string
checkPoint: Array<checkPoint>
}

View File

@ -2,7 +2,7 @@
import { idGenerator } from '../../utils/IdGenerator' import { idGenerator } from '../../utils/IdGenerator'
const id = idGenerator() const id = idGenerator()
export let group = false export let group = ''
export let value export let value
</script> </script>

View File

@ -5,6 +5,7 @@ import database from 'svelte-appwrite-client/src/lib/database'
export const load = async (pathName: string) => { export const load = async (pathName: string) => {
const checkPoints = [] const checkPoints = []
const game = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0] const game = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0]
const checkPointsIds = game.ExpCPsID const checkPointsIds = game.ExpCPsID
for (const checkPointId of checkPointsIds) { for (const checkPointId of checkPointsIds) {
@ -13,3 +14,13 @@ export const load = async (pathName: string) => {
game['checkPoints'] = checkPoints game['checkPoints'] = checkPoints
return game return game
} }
export const answer = async (checkPointId: string, answer: any) => {
const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)
console.log({ checkPoint })
const { CPType, CPAnswerID } = checkPoint
const correctAnswer = (await databases.getDocument('63cef30d6da945dd4250', '63dd5c2b764061e40025', CPAnswerID)).CPAnswer
if (CPType === 'CHECKBOX') return JSON.stringify(answer) === JSON.stringify(correctAnswer)
if (CPType === 'RADIO' || CPType === 'NUMBER' || CPType === 'TEXT') return answer === correctAnswer[0]
}

View File

@ -1,43 +1,37 @@
<script> <script lang="ts">
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import CheckBox from '../../../lib/Components/Inputs/Checkbox.svelte' import CheckBox from '../../../lib/Components/Inputs/Checkbox.svelte'
import parseQuestion from '$lib/utils/parseQuestion' import { checkPoint } from '$lib/TStypes/expiriences'
import { answer } from '$lib/utils/game'
export let gameData export let data: { name: string; checkPoint: checkPoint }
let answers = parseQuestion(gameData.question.answer, gameData.question.type) const { checkPoint, name } = data
let myAnswers = new Array(answers.length).fill(false) let myAnswers = new Array(checkPoint.CPOptions.length).fill(false)
export let control = null export let control = null
export let nextQuestion export let nextQuestion
const controlMultiForm = () => { const answerCheckBox = async () => {
for (let i = 0; i < myAnswers.length; i++) { const arr = checkPoint.CPOptions.filter((item, i) => {
const answer = myAnswers[i] if (myAnswers[i] === true) return item
const option = answers[i].label })
const rightValue = answers[i].value control = await answer(checkPoint.$id, arr)
if (rightValue !== answer) {
control = false
return ''
}
}
if (control === null) control = true
} }
</script> </script>
<Layout <Layout
imgSrc={gameData.question.thumbnail} imgSrc={'gameData.question.thumbnail'}
nextQuestion={() => { nextQuestion={() => {
nextQuestion() nextQuestion()
myAnswers = new Array(answers.length).fill(false) myAnswers = new Array(checkPoint.CPOptions.length).fill(false)
}} }}
{control} {control}
on:submit={controlMultiForm} on:submit={async () => answerCheckBox()}
> >
<span slot="title">{gameData.name}</span> <span slot="title">{name}</span>
<span slot="about">{@html gameData.question.question}</span> <span slot="about">{@html checkPoint.CPText}</span>
<div slot="answers"> <div slot="answers">
{#each answers as { label }, i} {#each checkPoint.CPOptions as label, i}
<span class="self-baseline"> <span class="self-baseline">
<CheckBox bind:checked={myAnswers[i]}>{label}</CheckBox> <CheckBox bind:checked={myAnswers[i]}>{label}</CheckBox>
</span> </span>

View File

@ -1,27 +1,32 @@
<script> <script lang="ts">
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import Input from '../../../lib/Components/Inputs/Input.svelte' import Input from '../../../lib/Components/Inputs/Input.svelte'
import parseQuestion from '$lib/utils/parseQuestion' import { checkPoint } from '$lib/TStypes/expiriences'
import { answer } from '$lib/utils/game'
export let gameData export let data: { name: string; checkPoint: checkPoint }
let answer = parseQuestion(gameData.question.answer, gameData.question.type) const { checkPoint, name } = data
let myAnswer = '' let myAnswer = ''
export let nextQuestion
export let control = null export let control = null
export let nextQuestion
const answer_ = async () => {
control = await answer(checkPoint.$id, myAnswer)
}
</script> </script>
<Layout <Layout
imgSrc={gameData.question.thumbnail} imgSrc={'gameData.question.thumbnail'}
nextQuestion={() => { nextQuestion={() => {
nextQuestion() nextQuestion()
myAnswer = '' myAnswer = ''
}} }}
{control} {control}
on:submit={() => (control = myAnswer !== '' ? myAnswer == answer : null)} on:submit={() => (myAnswer !== '' ? answer_() : null)}
> >
<span slot="title">{gameData.name}</span> <span slot="title">{name}</span>
<span slot="about">{@html gameData.question.question}</span> <span slot="about">{@html checkPoint.CPText}</span>
<div slot="answers"> <div slot="answers">
<span class="self-baseline"> <span class="self-baseline">
<Input type="number" bind:value={myAnswer} class="w-full min-w-[400px] max-w-[500px] h-12" /> <Input type="number" bind:value={myAnswer} class="w-full min-w-[400px] max-w-[500px] h-12" />

View File

@ -21,14 +21,14 @@
} }
let control = null // if true => spravne if false spatne let control = null // if true => spravne if false spatne
let view: 'question' | 'map' = 'map' let view: 'question' | 'map' = 'question'
export let gameData: any = {} //data export let gameData: any = {} //data
$: console.log(gameData) $: console.log(gameData)
let clientAnswers = { let clientAnswers = {
//user data about game //user data about game
pos: 1, pos: 0,
end: gameData.checkPoints.length, //kolik otázek end: gameData.checkPoints.length, //kolik otázek
points: 0, //body points: 0, //body
} }
@ -80,7 +80,7 @@
{#if view === 'question'} {#if view === 'question'}
{#if clientAnswers.pos !== clientAnswers.end} {#if clientAnswers.pos !== clientAnswers.end}
<svelte:component this={page} gameData={{ question: gameData.checkPoints[clientAnswers.pos], name: gameData.ExpName }} {nextQuestion} bind:control /> <svelte:component this={page} data={{ checkPoint: gameData.checkPoints[clientAnswers.pos], name: gameData.ExpName }} {nextQuestion} bind:control />
{:else} {:else}
<Finish img={gameData.thumbnail}> <Finish img={gameData.thumbnail}>
<span> Získali jste {clientAnswers.points} / {clientAnswers.end * 2} bodů</span> <span> Získali jste {clientAnswers.points} / {clientAnswers.end * 2} bodů</span>

View File

@ -1,35 +1,36 @@
<script> <script lang="ts">
import Radio from '../../../lib/Components/Inputs/Radio.svelte' import Radio from '../../../lib/Components/Inputs/Radio.svelte'
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import parseQuestion from '$lib/utils/parseQuestion' import { checkPoint } from '$lib/TStypes/expiriences'
import { answer } from '$lib/utils/game'
export let gameData export let data: { name: string; checkPoint: checkPoint }
let answers = parseQuestion(gameData.question.answer, gameData.question.type) const { checkPoint, name } = data
let myAnswer = '' let myAnswer = ''
$: console.log(data)
export let control = null export let control = null
export let nextQuestion export let nextQuestion
const rightAnswer = () => { const answer_ = async () => {
return answers.filter((item) => { control = await answer(checkPoint.$id, myAnswer)
if (item.value) return item.label
})[0].label
} }
</script> </script>
<Layout <Layout
imgSrc={gameData.question.thumbnail} imgSrc={'gameData.question.thumbnail'}
{control} {control}
nextQuestion={() => { nextQuestion={() => {
nextQuestion() nextQuestion()
myAnswer = '' myAnswer = ''
}} }}
on:submit={() => (control = typeof myAnswer === 'string' && myAnswer !== '' ? myAnswer === rightAnswer() : null)} on:submit={() => (control = myAnswer !== '' ? answer_() : null)}
> >
<span slot="title">{gameData.name}</span> <span slot="title">{name}</span>
<span slot="about">{@html gameData.question.question}</span> <span slot="about">{@html checkPoint.CPText}</span>
<div slot="answers"> <div slot="answers">
{#each answers as { label }} {#each checkPoint.CPOptions as label}
<span class="self-baseline"> <span class="self-baseline">
<Radio value={label} bind:group={myAnswer}>{label}</Radio> <Radio value={label} bind:group={myAnswer}>{label}</Radio>
</span> </span>

View File

@ -1,31 +1,32 @@
<script> <script lang="ts">
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import Input from '../../../lib/Components/Inputs/Input.svelte' import Input from '../../../lib/Components/Inputs/Input.svelte'
import parseQuestion from '$lib/utils/parseQuestion' import { checkPoint } from '$lib/TStypes/expiriences'
import { answer } from '$lib/utils/game'
export let gameData export let data: { name: string; checkPoint: checkPoint }
let answer = parseQuestion(gameData.question.answer, gameData.question.type) const { checkPoint, name } = data
let myAnswer = '' let myAnswer = ''
export let control = null export let control = null
export let nextQuestion export let nextQuestion
const compare = (a, b) => {
if (a.localeCompare(b, 'cz', { sensitivity: 'variant' }) === 0) return true const answer_ = async () => {
else return false control = await answer(checkPoint.$id, myAnswer)
} }
</script> </script>
<Layout <Layout
imgSrc={gameData.question.thumbnail} imgSrc={'gameData.question.thumbnail'}
{control} {control}
nextQuestion={() => { nextQuestion={() => {
nextQuestion() nextQuestion()
myAnswer = '' myAnswer = ''
}} }}
on:submit={() => (control = myAnswer !== '' ? compare(myAnswer, answer) : null)} on:submit={() => (myAnswer !== '' ? answer_() : null)}
> >
<span slot="title">{gameData.name}</span> <span slot="title">{name}</span>
<span slot="about">{@html gameData.question.question}</span> <span slot="about">{@html checkPoint.CPText}</span>
<div slot="answers"> <div slot="answers">
<span class="self-baseline"> <span class="self-baseline">
<Input type="text" bind:value={myAnswer} class="w-full min-w-[400px] max-w-[500px] h-12" /> <Input type="text" bind:value={myAnswer} class="w-full min-w-[400px] max-w-[500px] h-12" />

View File

@ -22,8 +22,6 @@
//const [gameData] = collections.expiriences.getDocument([Query.equal('ExpURL', params.gameurl)]) //const [gameData] = collections.expiriences.getDocument([Query.equal('ExpURL', params.gameurl)])
$: console.log($data)
let loading: boolean = true let loading: boolean = true
onMount(async () => { onMount(async () => {