LogoPixi’VN

ink 语言集成

通过与 Pixi’VN 集成的、专为分支故事设计的脚本语言 ink,可以编写交互式叙事内容。

Pixi’VN 允许你使用 ink 编写交互式叙事内容,ink 是一种专为分支故事设计的脚本语言。

什么是 ink ink 是一种用于交互式故事的简洁脚本语言,被应用于 80 Days、Heaven's Vault 和 Sorcery! 等游戏中! 更多信息请参阅 ink 官方网站

ink + Pixi’VN 集成 使用 inkjsPixiVNJson 来解析 ink 代码 并生成 Pixi’VN 可解析的 JSON。 这意味着 JavaScript/TypeScript 与 ink 共享相同的存储和 canvas,你可以从 JavaScript/TypeScript 启动 inkknots(或 labels),反之亦然。你可以同时享受两者的优势。 使用 ink 编写叙事内容,并使用 JavaScript/TypeScript 实现小游戏或高级动画。

file_type_ink
ink/start.ink
=== start ===
We arrived into London at 9.45pm exactly.

* "There is not a moment to lose!"[] I declared.
 -> hurry_outside

* "Monsieur, let us savour this moment!"[] I declared.
 My master clouted me firmly around the head and dragged me out of the door.
 -> dragged_outside

* [We hurried home] -> hurry_outside

=== hurry_outside ===
We hurried home to Savile Row -> as_fast_as_we_could

=== dragged_outside ===
He insisted that we hurried home to Savile Row
-> as_fast_as_we_could

=== as_fast_as_we_could ===
<> as fast as we could.
-> start

为什么?

直接使用 JavaScript/TypeScript 编写叙事内容可能既缓慢又复杂,尤其是对初学者而言。 ink 更容易学习和编写。

新开发者可以从 ink 模板 开始,然后逐步学习 JavaScript/TypeScript 以实现高级功能。

安装

Templates

正在开始一个新的 Pixi’VN 项目? 请使用已包含 ink模板

要在现有的 JavaScript 项目中安装 ink 包,请使用以下任一命令:

npm install @drincs/pixi-vn @drincs/pixi-vn-ink

初始化

安装完成后,使用 importInkText() 来加载 ink 脚本

main.ts
import { importInkText } from '@drincs/pixi-vn-ink'

const inkText = `
=== start ===
Hello
-> END
`

importInkText([inkText, ...])

随后,你可以使用 Pixi’VN 的函数 来运行 ink knot(或 label):

main.ts
import { narration } from '@drincs/pixi-vn'

narration.call(`start`, {})

即将推出的功能

这些功能目前正在开发中。

If you are interested, feel free to write in the chat below!

Pixi’VN 忽略的 ink 语法

部分 ink 语法会被 Pixi’VN 忽略。 你可以在 ink 脚本 中使用它们(例如在 Inky 编辑器中测试),但 Pixi’VN 不会处理这些内容。

INCLUDE

INCLUDE 是用于引入其他 ink 文件的 ink 语句。 在 Pixi’VN 中,应使用 importInkText() 来加载多个 ink 文件,因此 INCLUDE 会被忽略。

knots 之外的叙事内容

位于 knots(或 labels)之外的叙事内容会被忽略,变量除外。

For example:

file_type_ink
ink
VAR my_var = false // ✅ This will be handled (because it is a variable)
Hello // ❌ This will be ignored  [!code warning]
-> start // ❌ This will be ignored [!code warning]
=== start === // ✅ This will be handled
My name is John // ✅ This will be handled
-> DONE // ✅ This will be handled

其他叙事功能

On this page