Skip to content

Commit

Permalink
add time_area registration impl to lua
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Dec 24, 2014
1 parent 09ce8b5 commit fa32be5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
9 changes: 9 additions & 0 deletions data/lua/wml-tags.lua
Expand Up @@ -1337,3 +1337,12 @@ end
function wml_actions.remove_shroud(cfg)
wesnoth.remove_shroud(cfg)
end

function wml_actions.time_area(cfg)
local remove = cfg.remove
if remove then
wesnoth.remove_time_area(cfg.id)
else
wesnoth.add_time_area(cfg.id, cfg)
end
end
33 changes: 0 additions & 33 deletions src/game_events/action_wml.cpp
Expand Up @@ -2283,39 +2283,6 @@ WML_HANDLER_FUNCTION(terrain_mask, /*event_info*/, cfg)
resources::screen->needs_rebuild(true);
}

/// Adding/removing new time_areas dynamically with Standard Location Filters.
WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg)
{
log_scope("time_area");

bool remove = cfg["remove"].to_bool();
std::string ids = cfg["id"];

if(remove) {
const std::vector<std::string> id_list =
utils::split(ids, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
BOOST_FOREACH(const std::string& id, id_list) {
resources::tod_manager->remove_time_area(id);
LOG_NG << "event WML removed time_area '" << id << "'\n";
}
}
else {
std::string id;
if(ids.find(',') != std::string::npos) {
id = utils::split(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front();
ERR_NG << "multiple ids for inserting a new time_area; will use only the first" << std::endl;
} else {
id = ids;
}
std::set<map_location> locs;
const terrain_filter filter(cfg, resources::filter_con);
filter.get_locations(locs, true);
config parsed_cfg = cfg.get_parsed_config();
resources::tod_manager->add_time_area(id, locs, parsed_cfg);
LOG_NG << "event WML inserted time_area '" << id << "'\n";
}
}

WML_HANDLER_FUNCTION(tunnel, /*event_info*/, cfg)
{
const bool remove = cfg["remove"].to_bool(false);
Expand Down
42 changes: 42 additions & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -2948,6 +2948,48 @@ int game_lua_kernel::intf_allow_undo(lua_State *)
return 0;
}

/// Adding new time_areas dynamically with Standard Location Filters.
int game_lua_kernel::intf_add_time_area(lua_State * L)
{
log_scope("time_area");

std::string ids = luaL_checkstring(L, 1);
vconfig cfg(luaW_checkvconfig(L, 2));

std::string id;
if(ids.find(',') != std::string::npos) {
id = utils::split(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front();
ERR_LUA << "multiple ids for inserting a new time_area; will use only the first" << std::endl;
} else {
id = ids;
}

std::set<map_location> locs;
const terrain_filter filter(cfg, &game_state_);
filter.get_locations(locs, true);
config parsed_cfg = cfg.get_parsed_config();
tod_man().add_time_area(id, locs, parsed_cfg);
LOG_LUA << "event WML inserted time_area '" << id << "'\n";
return 0;
}

/// Removing new time_areas dynamically with Standard Location Filters.
int game_lua_kernel::intf_remove_time_area(lua_State * L)
{
log_scope("time_area");

const char * ids = luaL_checkstring(L, 1);

const std::vector<std::string> id_list =
utils::split(ids, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
BOOST_FOREACH(const std::string& id, id_list) {
tod_man().remove_time_area(id);
LOG_LUA << "event WML removed time_area '" << id << "'\n";
}
return 0;
}


namespace {
struct lua_report_generator : reports::generator
{
Expand Down
2 changes: 2 additions & 0 deletions src/scripting/game_lua_kernel.hpp
Expand Up @@ -72,6 +72,8 @@ class game_lua_kernel : public lua_kernel_base
// Private lua callbacks
int intf_allow_end_turn(lua_State *);
int intf_allow_undo(lua_State *);
int intf_add_time_area(lua_State *);
int intf_remove_time_area(lua_State *);
int intf_get_unit(lua_State *);
int intf_get_units(lua_State *);
int intf_get_displayed_unit(lua_State*);
Expand Down

0 comments on commit fa32be5

Please sign in to comment.