Editor: Brushes - Wargus/stratagus GitHub Wiki

Brushes

The editor supports brushes. They are defined in the lua-side and can be flexibly customized.

{
  Name = "Default",
  Type = "SingleTile", 		-- or Decoration
  Shape = "Rectangular", 	-- or Round
  Symmetric = false, 		-- can we change width and heigh independently?
  Align = "UpperLeft",  	-- or Center (relative to the mouse cursor)
  Resizable = true,
  ResizeSteps = {1, 1},
  MinSize = {1, 1},
  MaxSize = {20, 20},
  RandomizeAllowed = true, 		-- Is it possible to change tiles randomly to equivalent tiles (from the same subslot)
  FixNeighborsAllowed = true, 		-- Whether automatic changing of adjoining tiles is allowed
  TileIconsPaletteRequired = true, 	-- Whether to display a palette with icons for tile selection
  ExtendedTilesetRequired = true,
  Generator = { 					   -- decoration generator options
    ["source"] = "scripts/editor/brushes/_generator_.lua", -- path to generator file
    ["option"] = {"value1", "value2" ...} -- [option : {possible values}] pairs, values type is string.
  }
}

Two types of brushes are currently available:

  1. SingleTile Standard brush - select the tile icon you want to place on the map, and depending on the size of the brush, apply it to one or several fields of the map.
  2. Decoration Allows you to place pre-formed (or generated) patches of tiles on the map. It could be ramps for example. You can write any generator that will produce the tile patches you want. You pass to the engine the possible options for a given brush, then when the generator is called, it determines what values are selected by the user in the UI[1] for each of the options and, based on this, generates a set of tiles.

[1] BrushesUI automatically generates drop-down lists for each generator option so that the user can select the right combination of them to get the desired decoration.

There are still plans to implement MultiTile type, which will allow you to select several different tiles at once in a certain sequence and draw in patches at once. Part of the functionality will overlap with Decoration type of brushes, but the decorations/patches themselves can be filled in manually on the fly, rather than through a generator.

Example for a ramp generator brush:

local brush = {
	Name = "Ramp Generator",
	Type = "Decoration",
	Shape =  "Rectangular",
	Symmetric = false,
	Align = "Center",
	Resizable = false,
	RandomizeAllowed = true,
	FixNeighborsAllowed = false,
	TileIconsPaletteRequired = false,
	ExtendedTilesetRequired = true,
	Generator = {
		["source"] = "scripts/editor/brushes/ramp-generator.lua",
		["direction"] = {"North",
				"NorthEast",
				"SouthEast",
				"South",
				"SouthWest",
				"NorthWest"},
		["assembly-part"] = {"complete",
					"side-1",
					"middle",
					"side-2"},
		["highground"] = {"solid-highground", "weak-highground"},
		["lowground"] = {"solid-lowground", "weak-lowground"}
	}
}

EditorAddBrush(brush)

Adding a new brush

Brushes to load are defined in the scripts/editor/brushes.lua:

Load("scripts/editor/brushes/default.lua")
Load("scripts/editor/brushes/round.lua")
Load("scripts/editor/brushes/ramp.lua")

You should add loading of your brush file here. The new brush can then be selected from the brush drop-down list in the editor.

Editing

For single-tile brushes three options are available in addition to the resize controls:

*Manual mode If disabled, you can select any solid terrain tile from the tile icon palette (only they are displayed), and then you apply brush to the map, the editor will automatically fix all tiles adjacent to it. If enabled, two more options open up:

*Randomize If enabled, the tile icon palette allows you to select only the first tiles from each subslot, and any random tile from the subslot will be applied when placed on the map. Which significantly reduces the number of displayed tiles in the tile icon palette, makes it easier to navigate between them, and improves the variety look of the map. If you want to manually select a specific tile, simply disable this option and the tile icon palette will reflect the entire tileset.

*Decoration If enabled, the “do-not-mix” flag will be applied to the map field, and this field will not be automatically changed in a future edit when the auto-fix adjoining tiles feature is enabled.