A cleaner interface for wesnoth.map.place_area
This commit is contained in:
parent
0ef4a86b7e
commit
3bcc18ad96
2 changed files with 41 additions and 9 deletions
|
@ -686,7 +686,17 @@ function wml_actions.time_area(cfg)
|
|||
if cfg.remove then
|
||||
wml_actions.remove_time_area(cfg)
|
||||
else
|
||||
wesnoth.map.place_area(cfg)
|
||||
local times = wml.child_array(cfg, 'time')
|
||||
if #times == 0 then
|
||||
times = nil
|
||||
else
|
||||
-- current_time, if present, is part of the times, not the filters
|
||||
times.current_time = cfg.current_time
|
||||
end
|
||||
local filter = wml.shallow_parsed(cfg)
|
||||
filter.current_time = nil
|
||||
wml.remove_children(cfg, 'time')
|
||||
wesnoth.map.place_area(cfg.id, filter, times)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3794,19 +3794,41 @@ int game_lua_kernel::intf_cancel_action(lua_State*)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Adding new time_areas dynamically with Standard Location Filters. */
|
||||
/** Adding new time_areas dynamically with Standard Location Filters.
|
||||
* Arg 1: Area ID
|
||||
* Arg 2: Area locations (either a filter or a list of locations)
|
||||
* Arg 3: (optional) Area schedule - WML table with [time] tags and optional current_time=
|
||||
*/
|
||||
int game_lua_kernel::intf_add_time_area(lua_State * L)
|
||||
{
|
||||
log_scope("time_area");
|
||||
|
||||
vconfig cfg(luaW_checkvconfig(L, 1));
|
||||
const std::string id = cfg["id"];
|
||||
|
||||
std::string id;
|
||||
std::set<map_location> locs;
|
||||
const terrain_filter filter(cfg, &game_state_, false);
|
||||
filter.get_locations(locs, true);
|
||||
config parsed_cfg = cfg.get_parsed_config();
|
||||
tod_man().add_time_area(id, locs, parsed_cfg);
|
||||
vconfig cfg{config()};
|
||||
config times;
|
||||
|
||||
if(luaW_tovconfig(L, 1, cfg)) {
|
||||
deprecated_message("Single-argument wesnoth.map.place_area is deprecated. Instead, pass ID, filter, and schedule as three separate arguments.", DEP_LEVEL::INDEFINITE, {1, 17, 0});
|
||||
id = cfg["id"].str();
|
||||
const terrain_filter filter(cfg, &game_state_, false);
|
||||
filter.get_locations(locs, true);
|
||||
times = cfg.get_parsed_config();
|
||||
} else {
|
||||
id = luaL_checkstring(L, 1);
|
||||
if(!lua_isnoneornil(L, 3))
|
||||
times = luaW_checkconfig(L, 3);
|
||||
if(luaW_tovconfig(L, 2, cfg)) {
|
||||
// Second argument is a location filter
|
||||
const terrain_filter filter(cfg, &game_state_, false);
|
||||
filter.get_locations(locs, true);
|
||||
} else {
|
||||
// Second argument is an array of locations
|
||||
luaW_check_locationset(L, 2);
|
||||
}
|
||||
}
|
||||
|
||||
tod_man().add_time_area(id, locs, times);
|
||||
LOG_LUA << "Lua inserted time_area '" << id << "'\n";
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue