johnsquibb / adventure-game-markup-language
该软件包已废弃且不再维护。未建议替代软件包。
一套用于处理冒险游戏标记语言(AGML)的实用工具,用于构建冒险游戏框架的游戏。
0.1.1-alpha
2021-07-10 02:18 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9
This package is not auto-updated.
Last update: 2023-12-09 15:52:30 UTC
README
一套用于处理冒险游戏标记语言(AGML)的实用工具,用于构建冒险游戏框架的游戏。
主要功能
- 定义并记录AGML语法。
- 提供将AGML转换成可用于框架的hydrator对象的示例代码。
AGML语法
以下片段是有效的AGML,展示了以下用法:类型、注释、字面量、标识符、赋值、列表赋值和多行文本赋值。
# Type Declaration.
# Types must be UPPERCASE.
[ITEM]
# Any line beginning with '#' will be ignored.
# This is a comment
# An assignment.
# Format is variable=value
id=flashlight
# Booleans assignments
# 'yes' yields true.
acquirable=yes
# Any other value yields false.
deactivatable=no
# CSV list assignment produces array of values.
# Format is variable=value,value,..
tags=flashlight,light,magic torch stick
# Multiline assignment. Variable name in brackets must be lowercase.
# Any number of lines may follow, and the parser will continue until reaching a new instruction.
[description]
Description #1
Description #2
Description #3
# ...
# Another multi-line assignment
[text]
Text #1
Text #2
Text #3
# ...
# To use reserved symbols in assignments, escape them with Backslash.
# Examples:
# \,
# \\
# \=
# \[
# \]
使用转换器
以下PHP代码片段演示了转换器的使用。
$markup = <<<END [ITEM] # Attributes id=flashlight size =2 readable = yes name = Small Flashlight # Interactions acquirable=yes activatable=yes deactivatable=no # Tags tags=flashlight,light,magic torch stick [description] A black metal flashlight that runs on rechargeable batteries. There is a round gray button for activating it. There is some small text printed on a label on the side of the flashlight. [text] Information written on the side: Model: Illuminated Devices Inc Year: 1983 Serial Number: 8301IDI001256703 Batt. Type: (4) AA END; // Transpile AGML into Hydrator objects. $lexer = new Lexer(); $parser = new Parser(); $transpiler = new Transpiler($lexer, $parser); $hydrators = $transpiler->transpile($markup);