这是使用 YAML 的有效方法吗?
总的来说,我对 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 缺乏了解,这使我很难获得好的结果。
I am new to snakeyaml and yaml in general. I need it to store information about "rooms" for a MUD.
The entries for the rooms will look something like this:
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!"
Basically, each room has an id
and some text to be displayed to the player when they enter/search it. It also has an array of "objects" which are themselves declared in the same yaml file.
Is this configuration within my yaml file possible? Also, I would need to extract into arrays each room and each object, so it looks like this:
[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 ... ]]
This configuration makes it easy for me to parse the file and create GenericRoom and GenericObject classes by making one single loop and referencing every value by array position. Is this something SnakeYAML can do for me? I've been playing around with some examples but my lack of knowledge in actual YAML is making it hard for me to get good results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样,您必须自己将对象连接到房间:
或者 SnakeYAML 可以从锚点和别名中受益:
(必须在使用别名之前定义锚点)
(您可以在此处检查您的文档:http ://www.yaml.org/spec/1.2/spec.html#id2765878)
With this you have to connect objects to rooms yourself:
or SnakeYAML can benefit from anchors and aliases:
(anchors must be defined before aliases are used)
(You can check your documents here: http://www.yaml.org/spec/1.2/spec.html#id2765878)