Skip to content

Commit

Permalink
Make [*time_area] Lua API functions take a single time area id
Browse files Browse the repository at this point in the history
This means the Lua code implementing the WML tags are now solely
responsible for parsing the comma-separated id list. It just so happens
that I added code for that without realizing that I was duplicating
existing functionality on the C++ side.

As a result:
 * wesnoth.add_time_area and wesnoth.remove_time_area can operate on
   time area ids that contain commas (if someone feels this is needed
   for some weird reason)
 * [time_area] no longer warns about adding time areas with commas in
   their ids (actually adding the first id of the list instead)
 * [time_area] remove=yes and [remove_time_area] still handle
   comma-separated lists of ids, in the Lua side instead of C++.

This makes the Lua API for this consistent with [event]/[remove_event].

Since the Lua API functions in question are undocumented at this moment,
it's unlikely this impacts anyone, really.
  • Loading branch information
irydacea committed Nov 27, 2015
1 parent 9d85887 commit de44790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
7 changes: 5 additions & 2 deletions changelog
Expand Up @@ -64,6 +64,9 @@ Version 1.13.1+dev:
* Add helper.get_nth_child
* Add helper.child_count
* Add helper.child_array
* wesnoth.remove_time_area no longer takes a comma-separated list of time
area ids.
* wesnoth.add_time_area no longer warns about commas in time area ids
* Music and sound effects:
* New sounds: dwarf hit and die, ink, mud fist and glob.
* Terrains:
Expand Down Expand Up @@ -154,8 +157,8 @@ Version 1.13.1+dev:
* Add new syntax for [option], similar to the new difficulty syntax
* Add [test_condition] ActionWML that tells why a conditional failed (for debugging)
* Add [remove_time_area] WML tag which takes a comma-separated list of time
area ids, and make [time_area] id= accept a comma-separated list when
using remove=yes as well.
area ids.
* [time_area] no longer warns about commas in ids when not using remove=yes.
* Editor:
* Added Category field and color sliders to the Edit Label panel.
* Miscellaneous and bug fixes:
Expand Down
21 changes: 6 additions & 15 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -4073,35 +4073,26 @@ int game_lua_kernel::intf_add_time_area(lua_State * L)
log_scope("time_area");

vconfig cfg(luaW_checkvconfig(L, 1));
std::string id = cfg["id"];

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

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";
LOG_LUA << "Lua 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");
log_scope("remove_time_area");

const char * ids = luaL_checkstring(L, 1);
const char * id = luaL_checkstring(L, 1);
tod_man().remove_time_area(id);
LOG_LUA << "Lua removed time_area '" << id << "'\n";

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;
}

Expand Down

0 comments on commit de44790

Please sign in to comment.