Merge branch 'to_lua'

This commit is contained in:
Chris Beck 2014-12-24 16:12:52 -05:00
commit 36f57ff03a
4 changed files with 39 additions and 16 deletions

View file

@ -1355,6 +1355,10 @@ function wml_actions.scroll(cfg)
wesnoth.scroll(cfg)
end
function wml_actions.animate_unit(cfg)
wesnoth.animate_unit(cfg)
end
function wml_actions.color_adjust(cfg)
wesnoth.color_adjust(cfg)
end
@ -1388,6 +1392,10 @@ function wml_actions.modify_side(cfg)
wesnoth.modify_side(cfg)
end
function wml_actions.open_help(cfg)
wesnoth.open_help(cfg.topic)
end
function wml_actions.redraw(cfg)
local clear_shroud = cfg.clear_shroud

View file

@ -487,12 +487,6 @@ wml_action::wml_action(const std::string & tag, handler function)
static void wml_func_##pname(const queued_event& pei, const vconfig& pcfg)
WML_HANDLER_FUNCTION(animate_unit, event_info, cfg)
{
const events::command_disabler disable_commands;
unit_display::wml_animation(cfg, event_info.loc1);
}
/// Experimental data persistence
/// @todo Finish experimenting.
WML_HANDLER_FUNCTION(clear_global_variable,/**/,pcfg)
@ -1041,13 +1035,6 @@ WML_HANDLER_FUNCTION(object, event_info, cfg)
}
}
WML_HANDLER_FUNCTION(open_help, /*event_info*/, cfg)
{
game_display &screen = *resources::screen;
t_string topic_id = cfg["topic"];
help::show_help(screen, topic_id.to_serialized());
}
WML_HANDLER_FUNCTION(print, /*event_info*/, cfg)
{
// Remove any old message.

View file

@ -55,6 +55,7 @@
#include "game_events/manager.hpp" // for add_event_handler
#include "game_events/pump.hpp" // for queued_event
#include "game_preferences.hpp" // for encountered_units
#include "help/help.hpp"
#include "image.hpp" // for get_image, locator
#include "log.hpp" // for LOG_STREAM, logger, etc
#include "lua/lauxlib.h" // for luaL_checkinteger, etc
@ -493,6 +494,16 @@ static int impl_unit_variables_set(lua_State *L)
return 0;
}
int game_lua_kernel::intf_animate_unit(lua_State *L)
{
// if (game_display_)
{
events::command_disabler disable_commands;
unit_display::wml_animation(luaW_checkvconfig(L, 1), get_event_info().loc1);
}
return 0;
}
int game_lua_kernel::intf_gamestate_inspector(lua_State *L)
{
if (game_display_) {
@ -1400,7 +1411,7 @@ int game_lua_kernel::impl_current_get(lua_State *L)
if (strcmp(m, "event_context") == 0)
{
const game_events::queued_event &ev = *queued_events_.top();
const game_events::queued_event &ev = get_event_info();
config cfg;
cfg["name"] = ev.name;
if (const config &weapon = ev.data.child("first")) {
@ -1443,6 +1454,14 @@ int game_lua_kernel::intf_message(lua_State *L)
return 0;
}
int game_lua_kernel::intf_open_help(lua_State *L)
{
if (game_display_) {
help::show_help(*game_display_, luaL_checkstring(L, 1));
}
return 0;
}
/**
* Dumps a wml table or userdata wml object into a pretty string.
* - Arg 1: wml table or vconfig userdata
@ -3001,7 +3020,7 @@ int game_lua_kernel::intf_kill(lua_State *L)
{
vconfig cfg(luaW_checkvconfig(L, 1));
const game_events::queued_event &event_info = *queued_events_.top();
const game_events::queued_event &event_info = get_event_info();
size_t number_killed = 0;
@ -3544,6 +3563,10 @@ tod_manager & game_lua_kernel::tod_man() {
return game_state_.tod_manager_;
}
const game_events::queued_event & game_lua_kernel::get_event_info() {
return *queued_events_.top();
}
game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state & gs, play_controller & pc, reports & reports_object)
: lua_kernel_base(video)
, game_display_(NULL)
@ -3626,6 +3649,7 @@ game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state &
{ "match_unit", boost::bind(&game_lua_kernel::intf_match_unit, this, _1) },
{ "message", boost::bind(&game_lua_kernel::intf_message, this, _1) },
{ "modify_side", boost::bind(&game_lua_kernel::intf_modify_side, this, _1) },
{ "open_help", boost::bind(&game_lua_kernel::intf_open_help, this, _1) },
{ "play_sound", boost::bind(&game_lua_kernel::intf_play_sound, this, _1) },
{ "place_shroud", boost::bind(&game_lua_kernel::intf_shroud_op, this, _1, true) },
{ "put_recall_unit", boost::bind(&game_lua_kernel::intf_put_recall_unit, this, _1) },
@ -4026,7 +4050,7 @@ int game_lua_kernel::cfun_wml_action(lua_State *L)
(lua_touserdata(L, lua_upvalueindex(2))); // refer to lua_cpp_function.hpp for the reason that this is upvalueindex(2) and not (1)
vconfig vcfg = luaW_checkvconfig(L, 1);
h(*queued_events_.top(), vcfg);
h(get_event_info(), vcfg);
return 0;
}

View file

@ -63,6 +63,8 @@ class game_lua_kernel : public lua_kernel_base
std::stack<game_events::queued_event const * > queued_events_;
const game_events::queued_event & get_event_info();
static void extract_preload_scripts(config const & game_config);
static std::vector<config> preload_scripts;
static config preload_config;
@ -74,6 +76,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_allow_undo(lua_State *);
int intf_add_time_area(lua_State *);
int intf_remove_time_area(lua_State *);
int intf_animate_unit(lua_State *);
int intf_gamestate_inspector(lua_State *);
int intf_get_unit(lua_State *);
int intf_get_units(lua_State *);
@ -105,6 +108,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_find_reach(lua_State *L);
int intf_find_cost_map(lua_State *L);
int intf_message(lua_State *L);
int intf_open_help(lua_State *L);
int intf_play_sound(lua_State *L);
int intf_put_unit(lua_State *L);
int intf_put_recall_unit(lua_State *L);