Skip to content

Commit

Permalink
Move wesnoth.get_traits into wesnoth.game_config as global_traits
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Jun 12, 2021
1 parent 54e4a58 commit 8e34aa6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
1 change: 1 addition & 0 deletions data/lua/core/_initial.lua
Expand Up @@ -120,4 +120,5 @@ if wesnoth.kernel_type() == 'Game Lua Kernel' then

wesnoth.end_level = wesnoth.deprecate_api('wesnoth.end_level', 'wesnoth.scenario.end_level_data assignment', 1, nil, function(cfg) wesnoth.scenario.end_level_data = cfg end)
wesnoth.get_end_level_data = wesnoth.deprecate_api('wesnoth.get_end_level_data', 'wesnoth.scenario.end_level_data', 1, nil, function() return wesnoth.scenario.end_level_data end)
wesnoth.get_traits = wesnoth.deprecate_api('wesnoth.get_traits', 'wesnoth.game_config.global_traits', 1, nil, function() return wesnoth.game_config.global_traits end)
end
36 changes: 15 additions & 21 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -1119,6 +1119,20 @@ int game_lua_kernel::impl_game_config_get(lua_State *L)
gamedata().get_victory_music());
return_vector_string_attrib_deprecated("active_resources", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.resources instead",
utils::split(play_controller_.get_loaded_resources()));

if(strcmp(m, "global_traits") == 0) {
lua_newtable(L);
for(const config& trait : unit_types.traits()) {
const std::string& id = trait["id"];
//It seems the engine never checks the id field for emptiness or duplicates
//However, the worst that could happen is that the trait read later overwrites the older one,
//and this is not the right place for such checks.
lua_pushstring(L, id.c_str());
luaW_pushconfig(L, trait);
lua_rawset(L, -3);
}
return 1;
}

const mp_game_settings& mp_settings = play_controller_.get_mp_settings();
const game_classification & classification = play_controller_.get_classification();
Expand All @@ -1137,6 +1151,7 @@ int game_lua_kernel::impl_game_config_get(lua_State *L)
}
return_string_attrib("eras", utils::join(eras_list));
}

return lua_kernel_base::impl_game_config_get(L);
}

Expand Down Expand Up @@ -3056,26 +3071,6 @@ int game_lua_kernel::intf_get_sides(lua_State* L)
return 1;
}

/**
* .Returns information about the global traits known to the engine.
* - Ret 1: Table with named fields holding wml tables describing the traits.
*/
static int intf_get_traits(lua_State* L)
{
lua_newtable(L);
for(const config& trait : unit_types.traits()) {
const std::string& id = trait["id"];
//It seems the engine does nowhere check the id field for emptyness or duplicates
//(also not later on).
//However, the worst thing to happen is that the trait read later overwrites the older one,
//and this is not the right place for such checks.
lua_pushstring(L, id.c_str());
luaW_pushconfig(L, trait);
lua_rawset(L, -3);
}
return 1;
}

/**
* Adds a modification to a unit.
* - Arg 1: unit.
Expand Down Expand Up @@ -4006,7 +4001,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
{ "add_known_unit", &intf_add_known_unit },
{ "get_era", &intf_get_era },
{ "get_resource", &intf_get_resource },
{ "get_traits", &intf_get_traits },
{ "invoke_synced_command", &intf_invoke_synced_command },
{ "modify_ai", &intf_modify_ai_old },
{ "unsynced", &intf_do_unsynced },
Expand Down

0 comments on commit 8e34aa6

Please sign in to comment.