#ink #scripting-language #gamedev #narrative

bladeink

这是inkle的ink的Rust版本,ink是一种用于编写交互式叙事的脚本语言。

10 个版本 (5 个稳定版)

1.0.4 2024年7月17日
1.0.3 2024年1月4日
1.0.2 2023年12月29日
1.0.1 2023年11月24日
0.9.4 2023年10月28日

#158 in 游戏开发

Download history 5/week @ 2024-05-21 1/week @ 2024-05-28 5/week @ 2024-06-04 1/week @ 2024-06-11 9/week @ 2024-06-18 2/week @ 2024-06-25 117/week @ 2024-07-16 3/week @ 2024-07-23 5/week @ 2024-07-30

每月下载量 125次
2 crates 中使用

Apache-2.0

365KB
8K SLoC

Blade Ink

这是Inkle的Ink的Rust版本,Ink是一种用于编写交互式叙事的脚本语言。

bladeink与参考版本完全兼容,支持所有其语言特性。

要了解更多关于Ink语言的信息,您可以查看官方文档

使用Blade Ink库crate

以下是一个快速示例,它使用基本功能通过bladeink crate来播放Ink故事。

// story is the entry point of the `bladeink` lib.
// json_string is a string with all the contents of the .ink.json file.
let mut story = Story::new(json_string)?;

loop {
    while story.can_continue() {
        let line = story.cont()?;

        println!("{}", line);
    }

    let choices = story.get_current_choices();
    if !choices.is_empty() {
        // read_input is a method that you should implement
        // to get the choice selected by the user.
        let choice_idx = read_input(&choices)?;
        // set the option selected by the user
        story.choose_choice_index(choice_idx)?;
    } else {
        break;
    }
}

bladeink库支持所有Ink语言特性,包括线程、多流程、从代码中设置/获取变量、变量观察、外部函数、选择标签等。所有这些特性的使用示例可以在lib/tests文件夹中找到。

使用binkplayer运行Ink故事

Blade Ink项目包含一个程序,可以在您的终端中运行Ink故事。

您可以从crates.io安装它

$ cargo install binkplayer
$ binkplayer <your_story.ink.json>

或者,如果您下载了源代码仓库,可以在工作区根目录下运行cargo buildbinkplayer二进制文件将被编译并位于target/debug。您可以播放任何.ink.json(Ink编译文件)。

inkfiles文件夹中您可以找到许多用于测试Ink语言功能的测试故事。同时,我们也包含了Inkle创建的完整功能故事《Intercept》,也包含在inkfiles文件夹中。您可以通过在控制台运行以下命令来运行《Intercept》。

$ target/debug/binkplayer inkfiles/TheIntercept.ink.json

在C中使用Blade Ink

Blade Ink提供了C绑定,可以在C项目中使用Blade Ink。您可以在这里查看这里

依赖关系

~1–3.5MB
~67K SLoC