Latest Posts

Topic: Tool in editor to fill whole one texture with new texture

wojtek
Avatar
Topic Opener
Joined: 2019-02-20, 12:10
Posts: 5
Ranking
Just found this site
Location: Poland
Posted at: 2022-12-20, 17:52

When I create a map, sometimes I want to replace a texture of terrain with other. So I would like to have a tool that works like "fill with color" in paint.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2377
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2022-12-20, 17:56

As the terrains are not only texture but define the values that determine the growth probability of trees it is not possible to change the terrains texture. If you need a differrent texture for eye candy you need to specifiy a new terrain and provide this terrain with an addon. the map should be published via addon in this case too to reflect the dependency from the "custom" terrain.


Top Quote
wojtek
Avatar
Topic Opener
Joined: 2019-02-20, 12:10
Posts: 5
Ranking
Just found this site
Location: Poland
Posted at: 2022-12-20, 18:04

hessenfarmer wrote:

As the terrains are not only texture but define the values that determine the growth probability of trees it is not possible to change the terrains texture. If you need a differrent texture for eye candy you need to specifiy a new terrain and provide this terrain with an addon. the map should be published via addon in this case too to reflect the dependency from the "custom" terrain.

I mean just changing a terrain. When I have some connected fields covered with some terrain, I would like to replace all these fields with other terrain by single click.


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2226
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2022-12-21, 18:16

Such a tool isn't implemented yet. There is a bug report open to add such functionality as an addon: https://github.com/widelands/widelands/issues/4801

If you have a debug build running you can start a script console and run a file containing a function for changing terrains. The file should have this content:

map = wl.Editor().map

function change_terrain(from, to)
   local ter_descr = wl.Descriptions().terrain_descriptions
   for i, descr in ipairs(ter_descr) do
      if descr.descname == from then
         from = descr.name
      end
      if descr.descname == to then
         to = descr.name
      end
   end

   for x=0, map.width -1 do
      for y=0, map.height-1 do
         local f = map:get_field(x,y)
         if f.terr == from then
            f.terr = to
         end
         if f.terd == from then
            f.terd = to
         end
      end
   end
end

Save the file as e.g. "editor_functions.lua"

To start the script console hit SHIFT+STRG+SPACE and write

dofile("/full/path/to/editor_functions.lua")   # make the function(s) of this file available in the editor
change_terrain('Meadow 1', 'Barren Steppe')    # run the function with needed values

Note that this will replace all terrains of 'Meadow 1' to 'Barren Steppe' in the whole map. The values ('Meadow 1', 'Barren Steppe') needs to be in English, otherwise the function will not work.

Be aware that trees may need to be adjusted, because what hessenfarmer said: The growing of trees is terrain specific. So if you change the terrain it's likely that already placed trees do not grow well anymore.

Edited: 2022-12-21, 18:17

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote