Improve quest exceptions (#84)

This commit is contained in:
Lin, Hung-Shin authored and GitHub committed 2023-11-27 00:08:03 +08:00
commit 617bb56f5f
7 files changed
+159 -24

No files matched your search

+139 -3
View File
@@ -1,6 +1,142 @@
exceptions: exceptions:
- condition: - condition:
command: command:
- '`' - '[\uff21-\uff3a\uff41-\uff5a]'
hints: responses:
- '!! 不需要輸入上下引號 !!' - type: narrative
content:
- '!! 請使用半形英文字母 !!'
- condition:
command:
- ' '
responses:
- type: narrative
content:
- '!! 請使用半形空格 !!'
- condition:
or:
- command:
- '`'
- command:
- \'
responses:
- type: narrative
content:
- '!! 不需要輸入上下引號 !!'
- condition:
command:
- ^echo\S$
responses:
- type: narrative
content:
- '!! `echo` 後面要加空格 !!'
- condition:
command:
- ^cd\S$
responses:
- type: narrative
content:
- '!! `cd` 後面要加空格 !!'
- condition:
command:
- ^ls\S$
responses:
- type: narrative
content:
- '!! `ls` 後面要加空格 !!'
- condition:
command:
- ^cat\S$
responses:
- type: narrative
content:
- '!! `cat` 後面要加空格 !!'
- condition:
command:
- ^touch\S$
responses:
- type: narrative
content:
- '!! `touch` 後面要加空格 !!'
- condition:
not:
command:
- ^rmdir$
command:
- ^rm\S$
responses:
- type: narrative
content:
- '!! `rm` 後面要加空格 !!'
- condition:
command:
- ^mv\S$
responses:
- type: narrative
content:
- '!! `mv` 後面要加空格 !!'
- condition:
command:
- ^mkdir\S$
responses:
- type: narrative
content:
- '!! `mkdir` 後面要加空格 !!'
- condition:
command:
- ^rmdir\S$
responses:
- type: narrative
content:
- '!! `rmdir` 後面要加空格 !!'
- condition:
command:
- ^cp\S$
responses:
- type: narrative
content:
- '!! `cp` 後面要加空格 !!'
- condition:
command:
- ^[Ii1]s$
responses:
- type: narrative
content:
- '!! `ls` 的首字母是小寫的 `L` !!'
- condition:
command:
- 嗨
responses:
- type: narrative
content:
- '嗨~'
- condition:
command:
- folderl
responses:
- type: narrative
content:
- '`folder1` 的 `1` 是數字 `1`,不是小寫的 `L` !!'
- condition:
command:
- filel
responses:
- type: narrative
content:
- '`file1` 的 `1` 是數字 `1`,不是小寫的 `L` !!'
-7
View File
@@ -42,13 +42,6 @@ stages:
content: content:
- 請先回到 `/home/commander/` 資料夾 - 請先回到 `/home/commander/` 資料夾
- 輸入 `cd ~` 來返回 `/home/commander/` 資料夾 - 輸入 `cd ~` 來返回 `/home/commander/` 資料夾
- condition:
command:
- ^[Ii]s$
responses:
- type: narrative
content:
- '!! `ls` 的首字母是小寫的 `L`,不是 `I` !!'
responses: responses:
- content: - content:
- 你應該能看到資料夾中的內容了。 - 你應該能看到資料夾中的內容了。
+2
View File
@@ -7,6 +7,7 @@ instruction: |
在畫面的中間可以看到終端機和提示兩個區塊。 在畫面的中間可以看到終端機和提示兩個區塊。
請你在終端機中的 `commander:~ $` 後面輸入 `echo start` 並按下 Enter 來開始教程。 請你在終端機中的 `commander:~ $` 後面輸入 `echo start` 並按下 Enter 來開始教程。
!! 注意:不需要輸入上下引號 !!
stages: stages:
- id: start - id: start
@@ -65,6 +66,7 @@ stages:
hints: hints:
- ➤ 按下 `Ctrl + C` 能夠中斷指令 - ➤ 按下 `Ctrl + C` 能夠中斷指令
- ➤ 劇情進行時可以按下 `Enter` 來快速跳過 - ➤ 劇情進行時可以按下 `Enter` 來快速跳過
- ➤ 輸入 `echo finish` 來結束這一關
- id: END - id: END
task: 結束關卡 task: 結束關卡
+8 -8
View File
@@ -12,9 +12,9 @@ stages:
task: 輸入 `echo help` 來朗誦咒語 task: 輸入 `echo help` 來朗誦咒語
condition: condition:
pwd: pwd:
- '^/home/commander$' - ^/home/commander$
command: command:
- echo [Hh]elp - ^echo [Hh]elp$
responses: responses:
- type: narrative - type: narrative
content: content:
@@ -39,9 +39,9 @@ stages:
- help - help
condition: condition:
pwd: pwd:
- '^/home/commander$' - ^/home/commander$
command: command:
- ls - ^ls$
responses: responses:
- type: narrative - type: narrative
content: content:
@@ -65,9 +65,9 @@ stages:
- find-scroll - find-scroll
condition: condition:
pwd: pwd:
- '^/home/commander$' - ^/home/commander$
command: command:
- cat forgotten_scroll.txt - ^cat forgotten_scroll.txt$
responses: responses:
- type: dialogue - type: dialogue
speaker: Unix 精靈 speaker: Unix 精靈
@@ -83,9 +83,9 @@ stages:
- read-forgotten-scroll - read-forgotten-scroll
condition: condition:
pwd: pwd:
- '^/home/commander$' - ^/home/commander$
command: command:
- echo [Hh]ello\s*[Ww]orld - ^echo [Hh]ello\s*[Ww]orld$
responses: responses:
- type: narrative - type: narrative
content: content:
+3 -4
View File
@@ -64,13 +64,12 @@ stages:
- ^/home/commander/folder2$ - ^/home/commander/folder2$
exceptions: exceptions:
- condition: - condition:
not: pwd:
pwd: - ^/home/commander$
- ^/home/commander/folder1$
responses: responses:
- type: narrative - type: narrative
content: content:
- 請先回到 `folder1` 資料夾,並用指定的方式進入 `folder2` 資料夾。 - 輸入 `cd folder2` 來進入 `folder2` 資料夾
responses: responses:
- content: - content:
- 你成功的用相對路徑進入了 `folder2` 資料夾。 - 你成功的用相對路徑進入了 `folder2` 資料夾。
+1 -1
View File
@@ -122,7 +122,7 @@ export default class CommandHandler extends SessionHandler {
async run() { async run() {
try { try {
this.quest = await Quest.findById(this.session.quest) this.quest = await Quest.findById(this.session.quest)
const stages = this.getUnlockedComponents(this.quest.stages) const stages = this.getStages()
if (stages.length === 0) { if (stages.length === 0) {
logger.warn('stage not found', { session: this.session.id }) logger.warn('stage not found', { session: this.session.id })
return {} return {}
+6 -1
View File
@@ -25,8 +25,13 @@ export default class SessionHandler {
) )
} }
getStages() {
const unlockedStages = this.getUnlockedComponents(this.quest.stages)
return unlockedStages.filter((s) => !this.isCompleted(s))
}
getNewTasks() { getNewTasks() {
const stages = this.getUnlockedComponents(this.quest.stages) const stages = this.getStages()
return stages return stages
.filter((s) => s.task) .filter((s) => s.task)
.filter((s) => !this.session.tasks.some((t) => t.id === s.id)) .filter((s) => !this.session.tasks.some((t) => t.id === s.id))