Skip to content

Commit

Permalink
add lua api to read [resource]
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jun 16, 2020
1 parent d9c534e commit 39f44fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/play_controller.cpp
Expand Up @@ -97,7 +97,9 @@ static void copy_persistent(const config& src, config& dst)
"remove_from_carryover_on_defeat",
"disallow_recall",
"experience_modifier",
"require_scenario"};
"require_scenario",
"loaded_resources"
};

static const std::set<std::string> tags {
"terrain_graphics",
Expand Down
5 changes: 5 additions & 0 deletions src/play_controller.hpp
Expand Up @@ -241,6 +241,11 @@ class play_controller : public controller_base, public events::observer, public
return level_["disallow_recall"].to_bool();
}

std::string get_loaded_resources() const
{
return level_["loaded_resources"].str();
}

std::string theme() const
{
return gamestate_->get_game_data()->get_theme();
Expand Down
1 change: 1 addition & 0 deletions src/saved_game.cpp
Expand Up @@ -398,6 +398,7 @@ void saved_game::expand_mp_events()
}
}
this->starting_point_["has_mod_events"] = true;
this->starting_point_["loaded_resources"] = utils::join(loaded_resources);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -1314,6 +1314,25 @@ int game_lua_kernel::intf_get_selected_tile(lua_State *L)
return 2;
}


/**
* Gets a table for an resource tag.
* - Arg 1: userdata (ignored).
* - Arg 2: string containing id of the desired resource
* - Ret 1: config for the era
*/
static int intf_get_resource(lua_State *L)
{
std::string m = luaL_checkstring(L, 1);
if(const config& res = game_config_manager::get()->game_config().find_child("resource","id",m)) {
luaW_pushconfig(L, res);
return 1;
}
else {
return luaL_argerror(L, 1, ("Cannot find ressource with id '" + m + "'").c_str());
}
}

/**
* Gets a table for an era tag.
* - Arg 1: userdata (ignored).
Expand Down Expand Up @@ -1346,6 +1365,7 @@ int game_lua_kernel::impl_game_config_get(lua_State *L)
return_string_attrib("scenario_id", gamedata().get_id());
return_vector_string_attrib("defeat_music", gamedata().get_defeat_music());
return_vector_string_attrib("victory_music", gamedata().get_victory_music());
return_vector_string_attrib("active_resources", utils::split(play_controller_.get_loaded_resources()) );

const mp_game_settings& mp_settings = play_controller_.get_mp_settings();
const game_classification & classification = play_controller_.get_classification();
Expand Down Expand Up @@ -4179,6 +4199,7 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
{ "create_animator", &dispatch<&game_lua_kernel::intf_create_animator> },
{ "eval_conditional", &intf_eval_conditional },
{ "get_era", &intf_get_era },
{ "get_resource", &intf_get_resource },
{ "get_traits", &intf_get_traits },
{ "get_viewing_side", &intf_get_viewing_side },
{ "invoke_synced_command", &intf_invoke_synced_command },
Expand Down

0 comments on commit 39f44fa

Please sign in to comment.