Skip to content

Commit

Permalink
Fix the implementations of the deprecated get|set_terrain functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 19, 2021
1 parent d09cf99 commit c88f9b7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions data/lua/core.lua
Expand Up @@ -819,11 +819,25 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
wesnoth.terrain_mask = wesnoth.deprecate_api('wesnoth.terrain_mask', 'wesnoth.map.get():terrain_mask', 1, nil, function(...)
get_map().terrain_mask(...)
end)
wesnoth.get_terrain = wesnoth.deprecate_api('wesnoth.get_terrain', 'wesnoth.map.get():get_terrain', 1, nil, function(...)
get_map().get_terrain(...)
wesnoth.get_terrain = wesnoth.deprecate_api('wesnoth.get_terrain', 'wesnoth.map.get():get_terrain', 1, nil, function(x, y)
local loc = wesnoth.read_location(x, y)
if loc == nil then error('get_terrain: expected location') end
return get_map()[loc]
end)
wesnoth.set_terrain = wesnoth.deprecate_api('wesnoth.set_terrain', 'wesnoth.map.get():set_terrain', 1, nil, function(...)
get_map().set_terrain(...)
local loc, n = wesnoth.read_location(...)
if n == 0 then error('set_terrain: expected location') end
local new_ter, mode, replace_if_failed = select(n + 1, ...)
if new_ter == '' or type(new_ter) ~= 'string' then error('set_terrain: expected terrain string') end
if replace_if_failed then
mode = mode or 'both'
new_ter = wesnoth.map.replace_if_failed(new_ter, mode, true)
elseif mode == 'both' or mode == 'base' or mode == 'overlay' then
new_ter = wesnoth.map['replace_' .. mode](new_ter)
else
error('set_terrain: invalid mode')
end
get_map()[loc] = new_ter
end)
wesnoth.get_map_size = wesnoth.deprecate_api('wesnoth.get_map_size', 'wesnoth.map.get().width,height,border_size', 1, nil, function()
local m = get_map()
Expand Down

0 comments on commit c88f9b7

Please sign in to comment.