Compare commits

..
7 Commits
Author SHA1 Message Date
Lin, Hung-Shin b41e67ee0b fix: error in quest read (#81) 2023-11-24 12:59:46 +08:00
Chen, Tai-Lin 50a0bbbab1 add warning 2023-11-24 12:59:09 +08:00
Chen, Tai-Lin d712925d0f modify path 2023-11-24 12:56:57 +08:00
Lin, Hung-Shin b78398680d fix: add error handling (#82) 2023-11-24 12:53:00 +08:00
Lin, Hung-Shin c7f52b1003 fix: add error handling 2023-11-24 12:52:01 +08:00
Chen, Tai-Lin f008fb9f60 modify quest map 2023-11-24 12:49:17 +08:00
Chen, Tai-Lin 76a39add29 fix: error in quest read 2023-11-24 11:54:30 +08:00
6 changed files with 70 additions and 47 deletions

No files matched your search

+1 -1
View File
@@ -90,7 +90,7 @@ const handleChange = () => {
class="bg-bg border-8 border-bg-primary flex flex-1 flex-col items-center justify-center rounded-3xl p-10" class="bg-bg border-8 border-bg-primary flex flex-1 flex-col items-center justify-center rounded-3xl p-10"
> >
<h1 class="text-text-primary text-3xl font-black mb-2">{{ title }}</h1> <h1 class="text-text-primary text-3xl font-black mb-2">{{ title }}</h1>
<div class="text-error inline-flex justify-center items-center xl:hidden"> <div class="text-error inline-flex justify-center items-center md:hidden">
<font-awesome-icon <font-awesome-icon
:icon="['fas', 'circle-exclamation']" :icon="['fas', 'circle-exclamation']"
class="px-1 text-sm" class="px-1 text-sm"
+6 -5
View File
@@ -15,8 +15,8 @@ import { DAG } from '@linux-odyssey/utils'
import api from '../utils/api' import api from '../utils/api'
import { NodeImage } from '../img/svg.js' import { NodeImage } from '../img/svg.js'
const marginX = 200 const marginX = 500
const marginY = 65 const marginY = 300
const chartContainer = ref(null) const chartContainer = ref(null)
let chartInstance = null let chartInstance = null
const fullwidth = window.screen.width const fullwidth = window.screen.width
@@ -71,9 +71,10 @@ const genOption = (nodes, edges) => ({
symbol: () => { symbol: () => {
return NodeImage return NodeImage
}, },
symbolSize: [fullwidth / 10, fullwidth / 25], symbolSize: [fullwidth / 13, fullwidth / 30],
roam: 'move', roam: 'move',
zoom: 1, zoom: 1.5,
center: ['150%', '50%'],
label: { label: {
show: true, show: true,
fontSize: fullwidth / 90, fontSize: fullwidth / 90,
@@ -103,7 +104,7 @@ const genOption = (nodes, edges) => ({
if (unlocked) { if (unlocked) {
return '#ADADB5' return '#ADADB5'
} }
return '454552' return '#505050'
}, },
}, },
}, },
+8
View File
@@ -17,6 +17,14 @@ stages:
hints: hints:
- '!! 請勿使用全形空格 !!' - '!! 請勿使用全形空格 !!'
- id: warning-02
repeatable: true
condition:
command:
- '`'
hints:
- '!! 不需要輸入上下引號 !!'
- id: start - id: start
task: 輸入 `echo start` 來開始教程 task: 輸入 `echo start` 來開始教程
condition: condition:
+4 -8
View File
@@ -64,14 +64,12 @@ stages:
- ➤ 請輸入 `cd ../folder2` 來進入 `folder2` 資料夾。 - ➤ 請輸入 `cd ../folder2` 來進入 `folder2` 資料夾。
- id: cd-folder2 - id: cd-folder2
task: 用指定方式進入 `folder2` 資料夾 task: 進入 `folder2` 資料夾
requirements: requirements:
- cd-folder1 - cd-folder1
condition: condition:
pwd: pwd:
- ^/home/commander/folder2$ - ^/home/commander/folder2$
command:
- ^cd \.\./folder2$
exceptions: exceptions:
- condition: - condition:
not: not:
@@ -95,10 +93,8 @@ stages:
requirements: requirements:
- cd-folder2 - cd-folder2
condition: condition:
pwd: output:
- ^/home/commander/folder2$ - file1.txt
command:
- ^ls \.\.\/folder1$
exceptions: exceptions:
- condition: - condition:
not: not:
@@ -107,7 +103,7 @@ stages:
responses: responses:
- type: narrative - type: narrative
content: content:
- 請先回到 `folder2` 資料夾,並用指定的方式查看 `folder1` 資料夾的內容。 - 進到 `folder1` 資料夾並用 `ls` 查看內容。
responses: responses:
- content: - content:
- 很好,你現在知道如何運用相對路徑了。 - 很好,你現在知道如何運用相對路徑了。
+1 -1
View File
@@ -68,7 +68,7 @@ stages:
- id: ls-folder - id: ls-folder
task: 查看 `folder` 資料夾 task: 查看 `folder` 資料夾
requirements: requirements:
- cat-file - cat-file1
condition: condition:
pwd: pwd:
- ^/home/commander$ - ^/home/commander$
+50 -32
View File
@@ -50,9 +50,18 @@ export default class CommandHandler extends SessionHandler {
} }
async discoverHandler() { async discoverHandler() {
const graph = new FileGraph(this.session.graph) try {
graph.discover(this.params.discover) const graph = new FileGraph(this.session.graph)
this.session.graph = graph graph.discover(this.params.discover)
this.session.graph = graph
} catch (e) {
logger.error('Update file graph failed', {
error: e,
session: this.session.id,
graph: this.session.graph,
discover: this.params.discover,
})
}
} }
async isMatch(condition) { async isMatch(condition) {
@@ -111,37 +120,46 @@ export default class CommandHandler extends SessionHandler {
} }
async run() { async run() {
this.quest = await Quest.findById(this.session.quest) try {
const stages = this.getStages() this.quest = await Quest.findById(this.session.quest)
if (stages.length === 0) { const stages = this.getStages()
logger.warn('stage not found', this.session.tasks) if (stages.length === 0) {
return {} logger.warn('stage not found', this.session.tasks)
} return {}
this.handleEvent()
this.handleCommand()
const matches = await Promise.all(
stages.map((stage) => this.isMatch(stage.condition))
)
const stage = stages.find((_, i) => matches[i])
if (!stage) {
for (const s of stages) {
// eslint-disable-next-line no-await-in-loop
const exception = await this.checkException(s)
if (exception) {
return this.executeException(exception)
}
} }
return {}
}
const response = this.execute(stage)
return { this.handleEvent()
stage: stage.id, this.handleCommand()
end: this.session.status === 'finished',
...response, const matches = await Promise.all(
stages.map((stage) => this.isMatch(stage.condition))
)
const stage = stages.find((_, i) => matches[i])
if (!stage) {
for (const s of stages) {
// eslint-disable-next-line no-await-in-loop
const exception = await this.checkException(s)
if (exception) {
return this.executeException(exception)
}
}
return {}
}
const response = this.execute(stage)
return {
stage: stage.id,
end: this.session.status === 'finished',
...response,
}
} catch (err) {
logger.error('CommandHandler error', {
error: err,
session: this.session.id,
command: this.commandInput,
})
return {}
} }
} }
} }