Jump to content

自動貼圖

From DDraceNetwork
Revision as of 14:09, 8 February 2025 by Darkh (talk | contribs)

自動貼圖是一個方便作者製作地圖的工具。只需在貼圖層簡單地制定一些貼圖規則編纂成組運用,就能省去諸如手動在凍結區域邊角放置圓角貼圖此類的麻煩。每組貼圖規則需要指定一個貼圖資源文件,但是單個貼圖資源文件可以預設多種規則以備選用。所有規則文件位於遊戲路徑下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].

參考資料