Arrays 这是使用YAML的有效方法吗?
一般来说,我对snakeyaml和yaml都是新手。我需要它来存储有关“房间”的信息 房间的条目将如下所示:Arrays 这是使用YAML的有效方法吗?,arrays,parsing,yaml,snakeyaml,mud,Arrays,Parsing,Yaml,Snakeyaml,Mud,一般来说,我对snakeyaml和yaml都是新手。我需要它来存储有关“房间”的信息 房间的条目将如下所示: room: id: 12 entry: "Long string" description: "Longer more precise string" objects: ids: 1,23 object: id: 1 name: "chest" description: "looks pretty damn old" on-text: "the
room:
id: 12
entry: "Long string"
description: "Longer more precise string"
objects:
ids: 1,23
object:
id: 1
name: "chest"
description: "looks pretty damn old"
on-text: "the chest has been opened!"
off-text: "the chest has been closed!"
[12, "long string", "Longer more precise string", [1, "chest", "looks pretty damn old", "the chest has been opened!", "the chest has been closed!"], [ ... item 23 ... ]]
基本上,每个房间都有一个id
和一些文本,当玩家进入/搜索房间时,这些文本将显示给玩家。它还有一个“对象”数组,这些对象本身在同一个yaml文件中声明
在我的yaml文件中是否可以进行此配置?此外,我还需要将每个房间和每个对象提取到数组中,因此看起来如下所示:
room:
id: 12
entry: "Long string"
description: "Longer more precise string"
objects:
ids: 1,23
object:
id: 1
name: "chest"
description: "looks pretty damn old"
on-text: "the chest has been opened!"
off-text: "the chest has been closed!"
[12, "long string", "Longer more precise string", [1, "chest", "looks pretty damn old", "the chest has been opened!", "the chest has been closed!"], [ ... item 23 ... ]]
这种配置使我能够轻松地解析文件并创建GenericRoom和GenericObject类,方法是生成一个循环并按数组位置引用每个值。这是SnakeYAML能为我做的吗?我一直在玩弄一些例子,但我缺乏实际YAML方面的知识,这使得我很难获得好的结果。因此,您必须自己将对象连接到房间:
room:
id: 12
entry: "Long string"
objects: [1, 23]
objects:
- { id: 1, text: bla bla }
- { id: 2, text: bla bla 2 }
- { id: 23, text: bla bla 23}
或者SnakeYAML可以从锚和别名中获益:
(必须在使用别名之前定义定位)
(您可以在此处查看您的文档:)