Merge pull request #100 from cbeck88/eras

get list of all era ids and allow request for config of era by id
This commit is contained in:
cbeck88 2014-02-20 14:36:41 -05:00
commit b511dd95dc
2 changed files with 26 additions and 1 deletions

View file

@ -27,6 +27,7 @@ Version 1.11.9+dev:
* Updated translations: Scottish Gaelic
* Lua API:
* Config of current era is now available in a Lua table in MP games
* Config of any era can be requested by id, also a list valid era ids
* User interface:
* New UI for displaying errors detected during the core and add-on WML
loading process (parser and preprocessor errors), including the

View file

@ -1491,6 +1491,19 @@ static int intf_get_starting_location(lua_State* L)
return 1;
}
/**
* Gets a table for an era tag.
* - Arg 1: userdata (ignored).
* - Arg 2: string containing id of the desired era
* - Ret 1: config for the era
*/
static int intf_get_era(lua_State *L)
{
char const *m = luaL_checkstring(L, 1);
luaW_pushconfig(L, resources::config_manager->game_config().find_child("era","id",m));
return 1;
}
/**
* Gets some game_config data (__index metamethod).
* - Arg 1: userdata (ignored).
@ -1520,7 +1533,17 @@ static int impl_game_config_get(lua_State *L)
if(game_state_.classification().campaign_type=="multiplayer") {
return_cfgref_attrib("mp_settings", game_state_.mp_settings().to_config());
return_cfgref_attrib("era", resources::config_manager->game_config().find_child("era","id",game_state_.mp_settings().mp_era));
} //^ finds the era with name matching mp_era, and creates a lua reference from the config of that era.
//^ finds the era with name matching mp_era, and creates a lua reference from the config of that era.
//This code for SigurdFD, not the cleanest implementation but seems to work just fine.
config::const_child_itors its = resources::config_manager->game_config().child_range("era");
std::string eras_list((*(its.first))["id"]);
++its.first;
for(; its.first != its.second; ++its.first) {
eras_list = eras_list + "," + (*(its.first))["id"];
}
return_string_attrib("eras", eras_list);
}
return 0;
}
@ -3587,6 +3610,7 @@ LuaKernel::LuaKernel(const config &cfg)
{ "float_label", &intf_float_label },
{ "get_dialog_value", &intf_get_dialog_value },
{ "get_displayed_unit", &intf_get_displayed_unit },
{ "get_era", &intf_get_era },
{ "get_image_size", &intf_get_image_size },
{ "get_locations", &intf_get_locations },
{ "get_map_size", &intf_get_map_size },