replace wesnoth.is_synced() with wesnoth.current.synced_state
making it a proxy field instead of a function makes it easier to use. Also we now return a string so the luadev can distinuish between 'local_choice' and 'unsynced' which might be useful because [do_command] cannot be used from 'local_choice'.
This commit is contained in:
parent
aed6d94820
commit
1fc27bb9e7
1 changed files with 25 additions and 9 deletions
|
@ -1435,14 +1435,6 @@ static int intf_set_village_owner(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* - Ret 1: bool wether is in sycned context.
|
||||
*/
|
||||
static int intf_is_synced(lua_State *L)
|
||||
{
|
||||
lua_pushboolean(L, synced_context::get_synced_state() == synced_context::SYNCED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map size.
|
||||
|
@ -1587,6 +1579,30 @@ static int impl_game_config_set(lua_State *L)
|
|||
return luaL_argerror(L, 2, "unknown modifiable property");
|
||||
}
|
||||
|
||||
/**
|
||||
converts synced_context::get_synced_state() to a string.
|
||||
*/
|
||||
static std::string synced_state()
|
||||
{
|
||||
//maybe return "initial" for game_data::INITIAL?
|
||||
if(resources::gamedata->phase() == game_data::PRELOAD || resources::gamedata->phase() == game_data::INITIAL)
|
||||
{
|
||||
return "preload";
|
||||
}
|
||||
switch(synced_context::get_synced_state())
|
||||
{
|
||||
case synced_context::LOCAL_CHOICE:
|
||||
return "local_choice";
|
||||
case synced_context::SYNCED:
|
||||
return "synced";
|
||||
case synced_context::UNSYNCED:
|
||||
return "unsynced";
|
||||
default:
|
||||
throw game::game_error("Found corrupt synced_context::synced_state");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets some data about current point of game (__index metamethod).
|
||||
* - Arg 1: userdata (ignored).
|
||||
|
@ -1600,6 +1616,7 @@ static int impl_current_get(lua_State *L)
|
|||
// Find the corresponding attribute.
|
||||
return_int_attrib("side", resources::controller->current_side());
|
||||
return_int_attrib("turn", resources::controller->turn());
|
||||
return_string_attrib("synced_state", synced_state());
|
||||
|
||||
if (strcmp(m, "event_context") == 0)
|
||||
{
|
||||
|
@ -3676,7 +3693,6 @@ LuaKernel::LuaKernel(const config &cfg)
|
|||
{ "have_file", &intf_have_file },
|
||||
{ "highlight_hex", &intf_highlight_hex },
|
||||
{ "is_enemy", &intf_is_enemy },
|
||||
{ "is_synced", &intf_is_synced },
|
||||
{ "lock_view", &intf_lock_view },
|
||||
{ "match_location", &intf_match_location },
|
||||
{ "match_side", &intf_match_side },
|
||||
|
|
Loading…
Add table
Reference in a new issue