checkPoints
This commit is contained in:
parent
4067ec2fa9
commit
5e2481754f
|
@ -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>
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
import { idGenerator } from '../../utils/IdGenerator'
|
||||
const id = idGenerator()
|
||||
|
||||
export let group = false
|
||||
export let group = ''
|
||||
export let value
|
||||
</script>
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import database from 'svelte-appwrite-client/src/lib/database'
|
|||
export const load = async (pathName: string) => {
|
||||
const checkPoints = []
|
||||
const game = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0]
|
||||
|
||||
const checkPointsIds = game.ExpCPsID
|
||||
|
||||
for (const checkPointId of checkPointsIds) {
|
||||
|
@ -13,3 +14,13 @@ export const load = async (pathName: string) => {
|
|||
game['checkPoints'] = checkPoints
|
||||
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]
|
||||
}
|
||||
|
|
|
@ -1,43 +1,37 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Layout from '../Components/Layout.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
|
||||
let answers = parseQuestion(gameData.question.answer, gameData.question.type)
|
||||
let myAnswers = new Array(answers.length).fill(false)
|
||||
export let data: { name: string; checkPoint: checkPoint }
|
||||
const { checkPoint, name } = data
|
||||
let myAnswers = new Array(checkPoint.CPOptions.length).fill(false)
|
||||
|
||||
export let control = null
|
||||
export let nextQuestion
|
||||
|
||||
const controlMultiForm = () => {
|
||||
for (let i = 0; i < myAnswers.length; i++) {
|
||||
const answer = myAnswers[i]
|
||||
const option = answers[i].label
|
||||
const rightValue = answers[i].value
|
||||
|
||||
if (rightValue !== answer) {
|
||||
control = false
|
||||
return ''
|
||||
}
|
||||
}
|
||||
if (control === null) control = true
|
||||
const answerCheckBox = async () => {
|
||||
const arr = checkPoint.CPOptions.filter((item, i) => {
|
||||
if (myAnswers[i] === true) return item
|
||||
})
|
||||
control = await answer(checkPoint.$id, arr)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Layout
|
||||
imgSrc={gameData.question.thumbnail}
|
||||
imgSrc={'gameData.question.thumbnail'}
|
||||
nextQuestion={() => {
|
||||
nextQuestion()
|
||||
myAnswers = new Array(answers.length).fill(false)
|
||||
myAnswers = new Array(checkPoint.CPOptions.length).fill(false)
|
||||
}}
|
||||
{control}
|
||||
on:submit={controlMultiForm}
|
||||
on:submit={async () => answerCheckBox()}
|
||||
>
|
||||
<span slot="title">{gameData.name}</span>
|
||||
<span slot="about">{@html gameData.question.question}</span>
|
||||
<span slot="title">{name}</span>
|
||||
<span slot="about">{@html checkPoint.CPText}</span>
|
||||
<div slot="answers">
|
||||
{#each answers as { label }, i}
|
||||
{#each checkPoint.CPOptions as label, i}
|
||||
<span class="self-baseline">
|
||||
<CheckBox bind:checked={myAnswers[i]}>{label}</CheckBox>
|
||||
</span>
|
||||
|
|
|
@ -1,27 +1,32 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Layout from '../Components/Layout.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
|
||||
let answer = parseQuestion(gameData.question.answer, gameData.question.type)
|
||||
export let data: { name: string; checkPoint: checkPoint }
|
||||
const { checkPoint, name } = data
|
||||
let myAnswer = ''
|
||||
|
||||
export let nextQuestion
|
||||
export let control = null
|
||||
export let nextQuestion
|
||||
|
||||
const answer_ = async () => {
|
||||
control = await answer(checkPoint.$id, myAnswer)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Layout
|
||||
imgSrc={gameData.question.thumbnail}
|
||||
imgSrc={'gameData.question.thumbnail'}
|
||||
nextQuestion={() => {
|
||||
nextQuestion()
|
||||
myAnswer = ''
|
||||
}}
|
||||
{control}
|
||||
on:submit={() => (control = myAnswer !== '' ? myAnswer == answer : null)}
|
||||
on:submit={() => (myAnswer !== '' ? answer_() : null)}
|
||||
>
|
||||
<span slot="title">{gameData.name}</span>
|
||||
<span slot="about">{@html gameData.question.question}</span>
|
||||
<span slot="title">{name}</span>
|
||||
<span slot="about">{@html checkPoint.CPText}</span>
|
||||
<div slot="answers">
|
||||
<span class="self-baseline">
|
||||
<Input type="number" bind:value={myAnswer} class="w-full min-w-[400px] max-w-[500px] h-12" />
|
||||
|
|
|
@ -21,14 +21,14 @@
|
|||
}
|
||||
|
||||
let control = null // if true => spravne if false spatne
|
||||
let view: 'question' | 'map' = 'map'
|
||||
let view: 'question' | 'map' = 'question'
|
||||
|
||||
export let gameData: any = {} //data
|
||||
$: console.log(gameData)
|
||||
|
||||
let clientAnswers = {
|
||||
//user data about game
|
||||
pos: 1,
|
||||
pos: 0,
|
||||
end: gameData.checkPoints.length, //kolik otázek
|
||||
points: 0, //body
|
||||
}
|
||||
|
@ -80,7 +80,7 @@
|
|||
|
||||
{#if view === 'question'}
|
||||
{#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}
|
||||
<Finish img={gameData.thumbnail}>
|
||||
<span> Získali jste {clientAnswers.points} / {clientAnswers.end * 2} bodů</span>
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Radio from '../../../lib/Components/Inputs/Radio.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
|
||||
let answers = parseQuestion(gameData.question.answer, gameData.question.type)
|
||||
export let data: { name: string; checkPoint: checkPoint }
|
||||
const { checkPoint, name } = data
|
||||
let myAnswer = ''
|
||||
|
||||
$: console.log(data)
|
||||
|
||||
export let control = null
|
||||
export let nextQuestion
|
||||
|
||||
const rightAnswer = () => {
|
||||
return answers.filter((item) => {
|
||||
if (item.value) return item.label
|
||||
})[0].label
|
||||
const answer_ = async () => {
|
||||
control = await answer(checkPoint.$id, myAnswer)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Layout
|
||||
imgSrc={gameData.question.thumbnail}
|
||||
imgSrc={'gameData.question.thumbnail'}
|
||||
{control}
|
||||
nextQuestion={() => {
|
||||
nextQuestion()
|
||||
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="about">{@html gameData.question.question}</span>
|
||||
<span slot="title">{name}</span>
|
||||
<span slot="about">{@html checkPoint.CPText}</span>
|
||||
<div slot="answers">
|
||||
{#each answers as { label }}
|
||||
{#each checkPoint.CPOptions as label}
|
||||
<span class="self-baseline">
|
||||
<Radio value={label} bind:group={myAnswer}>{label}</Radio>
|
||||
</span>
|
||||
|
|
|
@ -1,31 +1,32 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Layout from '../Components/Layout.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
|
||||
let answer = parseQuestion(gameData.question.answer, gameData.question.type)
|
||||
export let data: { name: string; checkPoint: checkPoint }
|
||||
const { checkPoint, name } = data
|
||||
let myAnswer = ''
|
||||
|
||||
export let control = null
|
||||
export let nextQuestion
|
||||
const compare = (a, b) => {
|
||||
if (a.localeCompare(b, 'cz', { sensitivity: 'variant' }) === 0) return true
|
||||
else return false
|
||||
|
||||
const answer_ = async () => {
|
||||
control = await answer(checkPoint.$id, myAnswer)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Layout
|
||||
imgSrc={gameData.question.thumbnail}
|
||||
imgSrc={'gameData.question.thumbnail'}
|
||||
{control}
|
||||
nextQuestion={() => {
|
||||
nextQuestion()
|
||||
myAnswer = ''
|
||||
}}
|
||||
on:submit={() => (control = myAnswer !== '' ? compare(myAnswer, answer) : null)}
|
||||
on:submit={() => (myAnswer !== '' ? answer_() : null)}
|
||||
>
|
||||
<span slot="title">{gameData.name}</span>
|
||||
<span slot="about">{@html gameData.question.question}</span>
|
||||
<span slot="title">{name}</span>
|
||||
<span slot="about">{@html checkPoint.CPText}</span>
|
||||
<div slot="answers">
|
||||
<span class="self-baseline">
|
||||
<Input type="text" bind:value={myAnswer} class="w-full min-w-[400px] max-w-[500px] h-12" />
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
|
||||
//const [gameData] = collections.expiriences.getDocument([Query.equal('ExpURL', params.gameurl)])
|
||||
|
||||
$: console.log($data)
|
||||
|
||||
let loading: boolean = true
|
||||
|
||||
onMount(async () => {
|
||||
|
|
Loading…
Reference in New Issue