Automapper/zh: Difference between revisions
No edit summary |
Created page with "<code>XFLIP</code> 水平翻转; <code>YFLIP</code> 竖直翻转; <code>ROTATE</code> 90°旋转。" |
||
Line 65: | Line 65: | ||
将42号方块做水平和竖直翻转:<code>Index 42 XFLIP YFLIP ROTATE</code> | 将42号方块做水平和竖直翻转:<code>Index 42 XFLIP YFLIP ROTATE</code> | ||
<code>XFLIP</code> 水平翻转; | |||
<code>XFLIP</code> | <code>YFLIP</code> 竖直翻转; | ||
<code>ROTATE</code> 90°旋转。 | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> |
Revision as of 14:29, 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文件类似,您可以给贴图规则分段:
[您的规则组名]
对单个方块编号的位置描述可以作为一段。
如何注释
请使用#号开头,例如:
#这是一条注释。
选择要用的贴图编号
INDEX 42
这一行选中了42号方块(第三行第11列)。使用OR
可以同时选中多个编号,例如同时选中42和43号:
INDEX 42 OR 43
对贴图微调
将42号方块做水平和竖直翻转:Index 42 XFLIP YFLIP ROTATE
XFLIP
水平翻转;
YFLIP
竖直翻转;
ROTATE
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, butEMPTY
andFULL
. - 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].