1 个不稳定版本
使用旧的 Rust 2015
0.1.0 | 2018年2月4日 |
---|
#66 in #dialog
15KB
303 行
dtree
对话树解析器和执行器
dtree 是一个对话树的文件格式、库和命令行工具。
摘要
对话树在视频游戏中很常见,为这些创建一个简单的文件格式规范感觉像是一个有趣的项目。
术语
部分:对话树可能处于的状态。在上图中由一个框指定。
映射:从一个部分到另一个部分所需的文本输入
语法
定义部分
[ start ] Welcome to the game! What would you like to do?
^ Text in brackets ^ The name of the ^ The text to show along with it
define what's being Section to describe
described
定义映射
[ start (to the house) ->house ] Go to the house
^ The section ^ In parenthesis ^ The section ^ The description for the mapping
that the mapping is the text that the to travel to if
starts at player has to input the text in
to get to the next section parenthesis is inputted
示例
例如,以下 dtree 文件 test/example.dtree
[start] Welcome to this dtree file
[start (gym)->gym] Go to the gym
[start (videogames)->games] Play videogames
[gym] You made it to the gym! What a loser lol. Game over.
[games] Which game would you like to play?
[games (cs)->cs] Counter Strike
[games (cod)->cod] Call of Duty
[cs] Lmao what a shitty game. You got rekt. Game over.
[cod] You have 12 year old noobs scream at you because of the size of your mother. Wonderful.
这个可能的游玩过程可能如下所示
$ dtree test/example.dtree
Welcome to this dtree file
(videogames) Play videogames
(gym) Go to the gym
> videogames
Which game would you like to play?
(cod) Call of Duty
(cs) Counter Strike
> cod
You have 12 year old noobs scream at you because of the size of your mother. Wonderful.
依赖项
~1MB
~22K SLoC