mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: load user progress and check before click
* not display completed and unlocked status yet
This commit is contained in:
1 parent
34e9b20f2e
commit
08e28f7725
1 file changed
+27
-15
@@ -1,20 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-text-primary text-xl">Quest Map</h1>
|
<h1 class="text-text-primary text-xl">Quest Map</h1>
|
||||||
<!-- <div class="flex flex-col items-center">
|
<div ref="chartContainer" style="width: 600px; height: 600px"></div>
|
||||||
<div v-for="layer in layers" :key="layer" class="flex flex-row">
|
|
||||||
<div v-for="node in layer" :key="node.name">
|
|
||||||
<div class="text-text m-5">{{ node.name }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
<div ref="chartContainer" style="width: 410px; height: 450px"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useToast } from 'vue-toastification'
|
||||||
import { use, init } from 'echarts/core'
|
import { use, init } from 'echarts/core'
|
||||||
import { GraphChart } from 'echarts/charts'
|
import { GraphChart } from 'echarts/charts'
|
||||||
import { SVGRenderer } from 'echarts/renderers'
|
import { SVGRenderer } from 'echarts/renderers'
|
||||||
@@ -40,10 +34,17 @@ async function getQuests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getProgress() {
|
||||||
|
try {
|
||||||
|
const res = await api.get('/users/me')
|
||||||
|
return res.data.progress
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const genOption = (nodes, edges) => ({
|
const genOption = (nodes, edges) => ({
|
||||||
title: {
|
|
||||||
text: 'Quest Map',
|
|
||||||
},
|
|
||||||
rendener: 'svg',
|
rendener: 'svg',
|
||||||
tooltip: {},
|
tooltip: {},
|
||||||
animationDurationUpdate: 1500,
|
animationDurationUpdate: 1500,
|
||||||
@@ -74,16 +75,21 @@ const genOption = (nodes, edges) => ({
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
function getOption(quests) {
|
function getOption(quests, progress) {
|
||||||
const dag = new DAG(quests)
|
const dag = new DAG(quests)
|
||||||
|
console.log(progress)
|
||||||
|
|
||||||
const nodes = dag.getNodes().map((node) => ({
|
const nodes = dag.getNodes().map((node) => ({
|
||||||
id: node._id,
|
id: node._id,
|
||||||
name: node.title,
|
name: node.title,
|
||||||
x: marginX * node.index - (marginX * dag.getLayer(node._id)) / 2,
|
x: marginX * node.index - (marginX * dag.getLayer(node._id)) / 2,
|
||||||
y: marginY * node.layer,
|
y: marginY * node.layer,
|
||||||
|
completed: progress[node._id]?.completed || false,
|
||||||
|
unlocked: node.requirements.every((req) => progress[req]?.completed),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
console.log(nodes)
|
||||||
|
|
||||||
const edges = dag.getEdgesArray().map((edge) => ({
|
const edges = dag.getEdgesArray().map((edge) => ({
|
||||||
source: edge[0],
|
source: edge[0],
|
||||||
target: edge[1],
|
target: edge[1],
|
||||||
@@ -92,6 +98,7 @@ function getOption(quests) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
function initChart(option) {
|
function initChart(option) {
|
||||||
console.log('initChart', chartContainer.value)
|
console.log('initChart', chartContainer.value)
|
||||||
@@ -99,16 +106,21 @@ function initChart(option) {
|
|||||||
chartInstance.setOption(option)
|
chartInstance.setOption(option)
|
||||||
chartInstance.on('click', (params) => {
|
chartInstance.on('click', (params) => {
|
||||||
const {
|
const {
|
||||||
data: { id },
|
data: { id, unlocked },
|
||||||
} = params
|
} = params
|
||||||
|
|
||||||
router.push({ name: 'game', params: { questId: id } })
|
if (unlocked) {
|
||||||
|
router.push({ name: 'game', params: { questId: id } })
|
||||||
|
} else {
|
||||||
|
toast.warning('You have not completed the previous quest yet!')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const quests = await getQuests()
|
const quests = await getQuests()
|
||||||
const option = getOption(quests)
|
const progress = await getProgress()
|
||||||
|
const option = getOption(quests, progress)
|
||||||
initChart(option)
|
initChart(option)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
Reference in new issue
Block a user