mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: print hints one by one, fix unexpected breakline
This commit is contained in:
1 parent
fc13e9371c
commit
a9a63ea164
2 files changed
+13
-10
No files matched your search
@@ -3,7 +3,7 @@ const fs = require('fs').promises
|
|||||||
const { exit } = require('process')
|
const { exit } = require('process')
|
||||||
const minimist = require('minimist')
|
const minimist = require('minimist')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const { colorize, printResponses } = require('./print.js')
|
const { colorize, printResponses, printHints } = require('./print.js')
|
||||||
const discoverFiles = require('./discover.js')
|
const discoverFiles = require('./discover.js')
|
||||||
|
|
||||||
async function readOrNone(file) {
|
async function readOrNone(file) {
|
||||||
@@ -66,16 +66,14 @@ async function main() {
|
|||||||
const { responses, hints, end } = res.data
|
const { responses, hints, end } = res.data
|
||||||
if (responses) {
|
if (responses) {
|
||||||
await printResponses(responses, 60)
|
await printResponses(responses, 60)
|
||||||
await api.post('/commands/completed')
|
|
||||||
}
|
}
|
||||||
if (hints) {
|
if (hints) {
|
||||||
for (const hint of hints) {
|
await printHints(hints, 60)
|
||||||
console.log(colorize(hint, 'yellow'))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (end) {
|
if (end) {
|
||||||
console.log(colorize('Quest completed!', 'blue'))
|
console.log(colorize('Quest completed!', 'blue'))
|
||||||
}
|
}
|
||||||
|
await api.post('/commands/completed')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.response) {
|
if (err.response) {
|
||||||
console.error(err.response.data)
|
console.error(err.response.data)
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ function printLine(content, delay, color) {
|
|||||||
|
|
||||||
waitForEnter().then(() => {
|
waitForEnter().then(() => {
|
||||||
clearInterval(timer)
|
clearInterval(timer)
|
||||||
|
if (i >= printContent.length) return
|
||||||
process.stdout.write(printContent.slice(i))
|
process.stdout.write(printContent.slice(i))
|
||||||
process.stdout.write('\n')
|
process.stdout.write('\n')
|
||||||
resolve()
|
resolve()
|
||||||
@@ -68,22 +69,26 @@ async function printResponses(responses, delay = 100) {
|
|||||||
for (const line of content) {
|
for (const line of content) {
|
||||||
await printLine(line, delay, color || 'cyan')
|
await printLine(line, delay, color || 'cyan')
|
||||||
}
|
}
|
||||||
console.log(colorize('------------------------------', 'green'))
|
|
||||||
console.log()
|
|
||||||
}
|
}
|
||||||
if (type === 'dialogue') {
|
if (type === 'dialogue') {
|
||||||
console.log(colorize(`${speaker}:`, 'green'))
|
console.log(colorize(`${speaker}:`, 'green'))
|
||||||
for (const line of content) {
|
for (const line of content) {
|
||||||
await printLine(` ${line}`, delay, color || 'cyan')
|
await printLine(` ${line}`, delay, color || 'cyan')
|
||||||
}
|
}
|
||||||
console.log(colorize('------------------------------', 'green'))
|
|
||||||
console.log()
|
|
||||||
}
|
}
|
||||||
|
console.log(colorize('------------------------------', 'green'))
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function printHints(hints, delay = 100) {
|
||||||
|
for (const hint of hints) {
|
||||||
|
await printLine(hint, delay, 'yellow')
|
||||||
}
|
}
|
||||||
rl.close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
printResponses,
|
printResponses,
|
||||||
|
printHints,
|
||||||
colorize,
|
colorize,
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user