【发布时间】:2012-01-06 00:09:03
【问题描述】:
我一般是snakeyaml 和yaml 的新手。我需要它来为MUD 存储有关“房间”的信息。
房间的条目将如下所示:
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!"
基本上,每个房间都有一个id 和一些文本,当玩家进入/搜索它时会显示给他们。它还有一个“对象”数组,它们本身在同一个 yaml 文件中声明。
是否可以在我的 yaml 文件中进行此配置?另外,我需要将每个房间和每个对象提取到数组中,所以它看起来像这样:
[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 缺乏了解,这让我很难获得好的结果。
【问题讨论】:
标签: arrays parsing yaml snakeyaml mud