Lua Cave Mapgen: Support flip_xy transform

This commit is contained in:
Celtic Minstrel 2016-10-27 02:43:54 -04:00
parent 495a5c681f
commit 0166235d99
2 changed files with 16 additions and 2 deletions

View file

@ -151,8 +151,7 @@ function callbacks.generate_map(params)
if random(100) <= chance then
local transforms = {}
for t in params.transform:gmatch("[^%s,][^,]*") do
-- TODO: Possibly support other transformations, such as transpose, rotate_cw, rotate_ccw, etc
if t == 'flip_x' or t == 'flip_y' then
if MG.is_valid_transform(t) then
table.insert(transforms, t)
else
error("Unknown transformation '" .. t .. "'")

View file

@ -10,6 +10,16 @@ function mapgen_helper.create_map(width,height,default_terrain)
return map
end
local valid_transforms = {
flip_x = true,
flip_y = true,
flip_xy = true,
}
function mapgen_helper.is_valid_transform(t)
return valid_transforms[t]
end
local function loc_to_index(map,x,y)
return x + 1 + y * map.w
end
@ -65,6 +75,11 @@ function map_mt.__index.flip_y(map)
end
end
function map_mt.__index.flip_xy(map)
map:flip_x()
map:flip_y()
end
function map_mt.__tostring(map)
local map_builder = {}
-- The coordinates are 0-based to match the in-game coordinates