Jump to content

Automapper/zh: Difference between revisions

From DDraceNetwork
Darkh (talk | contribs)
Created page with "如何注释:"
Darkh (talk | contribs)
No edit summary
Line 50: Line 50:
</div>
</div>


如何注释:
'''如何注释'''


<div lang="en" dir="ltr" class="mw-content-ltr">
请使用#号开头,例如:
<code>#this is a comment</code>
<code>#这是一条注释。</code>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Revision as of 14:09, 8 February 2025

自动贴图是一个方便作者制作地图的工具。只需在贴图层简单地制定一些贴图规则编纂成组运用,就能省去诸如手动在冻结区域边角放置圆角贴图此类的麻烦。每组贴图规则需要指定一个贴图资源文件,但是单个贴图资源文件可以预设多种规则以备选用。所有规则文件位于游戏路径下data/editor/automap/[1][2]


贴图规则文件

作为贴图资源的图片文件,其自动贴图规则通常会写在另一个文本文件中,后缀固定为.rules,规则文件名必须和资源文件名相同;每个贴图规则文件内可以写入多组自动贴图规则。此规则文件大致遵循 INI 文件格式,文件中每组贴图规则以方括号括住规则组的名字为首行,并附带多行具体规则于其后,首行语法为[规则组名]。例如,在文件grass_main.rules中,有一组名为Grass 的贴图规则,它在文件中以 [Grass] 开头。要使用这组规则,您需要在地图编辑器中创建一个使用grass_main文件作为贴图资源的贴图层:首先要新建一个贴图层(tile layer),然后右键单击此贴图层并选择资源图片(Image)为grass_main,在此图层画好主体部分后,再次打开刚才的右键菜单并点击Auto Rule,然后在下拉选项中选择Grass规则组,最后点击Auto map自动贴图。

强调:贴图规则的文件名必须和贴图资源的文件名保持一致。

示例的 Grass 自动贴图规则如下[3]:

[Grass]
Index 1

#top
Index 16
Pos 0 -1 EMPTY
...

贴图规则执行过程

贴图按照如下方式自动进行:在规则组中从上往下读取规则,按照规则所描述的坐标或者位置分布关系,在图层已有的贴图中查找符合描述的图块,然后将该图块替换为规则指定的贴图;注意贴图过程中先前规则贴好的贴图可能会被后来的规则替换,当多个规则查找的图块相同时,最终表现为只执行了最后一个规则。除非禁用,否则自动贴图会先将更改放入缓存再替换贴图层。

资源文件分块编号一览

方块索引

每个资源文件导入后会被分割成16行16列,以左上角为0号方块,之后从左往右由0到15依次给第一行方块编号,每行编号完毕再到下一行,第二行左边开头为16号方块,依此类推。容易看出方块每次向右一格+1,向下一格+16,对应计算公式为编号 = 16 * 行数 + 列数(注意第一行和第一列在计算机中默认为第0行和第0列)。资源文件中0号方块的位置通常留空,贴图规则会将它称为EMPTY(空);其余位置的方块无论置空与否都会被当作FULL(满)。

在规则文件中,编号的关键字是INDEX

语法

将您的规则组命名:

与INI文件类似,您可以创建多段贴图规则:

[您的规则组名]

Multiple index selections followed by rules can be part of a section.

如何注释

请使用#号开头,例如: #这是一条注释。

Selecting a tile you want to place:

INDEX 42

This selects tile 42 (meaning the 3rd row and 11th column. Multiple indices can be selected by adding an OR between each index:

INDEX 42 OR 43

Modifying the tile:

Index 42 XFLIP YFLIP ROTATE

XFLIP mirrors the tile vertically and YFLIP mirrors the tile horizontally. ROTATE rotates the tile a single time by 90°.

IF you want to rotate a tile by 180°, you only need to set XFLIP and YFLIP but not ROTATE.

If you want to rotate by 270°, you need to set XFLIP, YFLIP and ROTATE.

Tile modifications are always in the same line as the selection.

Rule for placing the tile:

The selected tile gets placed if all following rules apply. A rule for placing the tile always starts with coordinates followed by a rule:

POS 0 -1 FULL

This rule selects the tile with X coordinate 0 and Y coordinate -1 relative to the scanning position of the automapper. If the tile above the scanning position is FULL, the selected tile will be placed (if all following rules apply). If it's EMPTY, it won't be placed.

Instead of using FULL or EMPTY, you can select another tile with the INDEX keyword:

POS 0 -1 INDEX 12

If the tile above the scanning position has index 12, it will be placed. Multiple indices can be selected by adding an OR between each index:

POS 0 -1 INDEX 12 OR 13

Similarly NOTINDEX can be used to exclude a tile.

Random rule:

You can make a selected tile randomly apply to rules by adding a random rule:

RANDOM 20%

The random rule expects a value between 0% and 100%. This value represents the probability, that a tile is placed[4].

If you put a value into it without a % symbol, the probability will not be parsed in terms of percentages, but with this formula:

percentage = 1.0 / value

This allows for rarer tile placements with probabilities between 0% and 1% and a value > 100.

For example RANDOM 150 will have a probability of 1.0 / 150 ≈ 0.67 (percent).

Default condition rule:

By default the game assumes, that you want to apply each rule to a full tile, meaning that the following rule is always implied:

POS 0 0 FULL

You can deactivate this by adding the following line under the tile selection:

NoDefaultRule

NewRun:

Adding NewRun in a section will make the section run an additional time for each time this keyword gets added to the section. This can be used to set some basic tiles in the first run, and more complex ones in the second.

NoLayerCopy:

Adding NoLayerCopy in a section will cause it to run in-place. This can drastically improve performance, because the automapper doesn't copy it's changes into buffer memory before applying it. But it can cause unintended side effects!

工具

Some tools in order to create automapper rules exist:

  • SimpleDDNetAutomapper - a small UI application, which tries a more user friendly approach for very basic rules and tilesets. It does not support randomness, or POS INDEX rules, but EMPTY and FULL.
  • Teeworlds Web Editor - Automapper edit and live-preview[5].
  • rpp - rules++ is a small experiment, aiming to make mappers utterly lazy, by unlocking the full potential of DDNet's rules. It is meant to be simple, readable and most importantly correct, everything else is irrelevant[6].

参考资料