Allow matching any wall map terrain in lua scripts
When matching a terrain, allow using a "w" placeholder that matches any solid wall: For example: local s = selection.match([[w.w]]); would match all floor locations with a wall to the left and right of it. The walls can be solid stone, horizontal, vertical, etc. This applies to selection.match(), selection.filter_mapchar(), and des.replace_terrain()
This commit is contained in:
@@ -447,6 +447,7 @@ function test_replace_terrain()
|
||||
des.replace_terrain({ region={1,1, 70,19}, fromterrain=".", toterrain="L", chance=25 });
|
||||
des.replace_terrain({ selection=selection.area(2,5, 10,15), fromterrain="L", toterrain="." });
|
||||
des.replace_terrain({ mapfragment=[[...]], toterrain="T" });
|
||||
des.replace_terrain({ mapfragment=[[w.w]], toterrain="L" });
|
||||
end
|
||||
|
||||
function test_corridor()
|
||||
|
||||
@@ -334,6 +334,15 @@ function test_sel_filter_mapchar()
|
||||
sel_has_n_points(selb, 2, __func__);
|
||||
sel_pt_ne(selb, 5,5, 1, __func__);
|
||||
sel_pt_ne(selb, 15,10, 1, __func__);
|
||||
|
||||
des.reset_level();
|
||||
des.level_init({ style = "solidfill", fg = " " });
|
||||
des.replace_terrain({ selection=sela, fromterrain=" ", toterrain="-", chance=50 });
|
||||
des.replace_terrain({ selection=sela, fromterrain=" ", toterrain="|", chance=50 });
|
||||
|
||||
-- test filtering by "w" (match any solid wall)
|
||||
local seld = sela:filter_mapchar("w");
|
||||
sel_has_n_points(seld, 1659, __func__);
|
||||
end -- test_sel_filter_mapchar
|
||||
|
||||
function test_sel_flood()
|
||||
@@ -355,7 +364,41 @@ function test_sel_flood()
|
||||
end -- test_sel_flood
|
||||
|
||||
function test_sel_match()
|
||||
local sel = selection.match([[...]]);
|
||||
local __func__ = "test_sel_match";
|
||||
des.reset_level();
|
||||
des.level_init({ style = "solidfill", fg = " " });
|
||||
|
||||
-- test horizontal map fragment
|
||||
des.terrain(5,5, ".");
|
||||
des.terrain(6,5, ".");
|
||||
des.terrain(7,5, ".");
|
||||
local sela = selection.match([[...]]);
|
||||
sel_has_n_points(sela, 1, __func__);
|
||||
sel_pt_ne(sela, 6,5, 1, __func__);
|
||||
|
||||
-- test vertical map fragment
|
||||
local mapfragv = " \n.\n ";
|
||||
local selb = selection.match(mapfragv);
|
||||
sel_has_n_points(selb, 3, __func__);
|
||||
sel_pt_ne(selb, 5,5, 1, __func__);
|
||||
sel_pt_ne(selb, 6,5, 1, __func__);
|
||||
sel_pt_ne(selb, 7,5, 1, __func__);
|
||||
|
||||
-- test matching with "w" to match any wall
|
||||
des.terrain(5,4, "-");
|
||||
des.terrain(6,6, "|");
|
||||
local mapfragv = "w\n.\nw";
|
||||
local selc = selection.match(mapfragv);
|
||||
sel_has_n_points(selc, 3, __func__);
|
||||
sel_pt_ne(selc, 5,5, 1, __func__);
|
||||
sel_pt_ne(selc, 6,5, 1, __func__);
|
||||
sel_pt_ne(selc, 7,5, 1, __func__);
|
||||
|
||||
-- test a 3x3 map fragment
|
||||
local mapfrag = "www\n...\nwww";
|
||||
local seld = selection.match(mapfrag);
|
||||
sel_has_n_points(seld, 1, __func__);
|
||||
sel_pt_ne(seld, 6,5, 1, __func__);
|
||||
end -- test_sel_match
|
||||
|
||||
test_selection_params();
|
||||
|
||||
Reference in New Issue
Block a user