Skip to content
Permalink
Browse files

ObjectRef: Re-add legacy code for set_physics_override (#10585)

These arguments are used at least by MTG beds and homedecor_common. A deprecation warning is shown to safely remove it in a future release.
  • Loading branch information
SmallJoker committed Nov 10, 2020
1 parent 97aefe9 commit fca4db4184ac054c53446c0960ec578ebc6b5857
Showing with 28 additions and 14 deletions.
  1. +28 −14 src/script/lua_api/l_object.cpp
@@ -1413,20 +1413,34 @@ int ObjectRef::l_set_physics_override(lua_State *L)
if (playersao == nullptr)
return 0;

luaL_checktype(L, 2, LUA_TTABLE);
playersao->m_physics_override_speed = getfloatfield_default(
L, 2, "speed", playersao->m_physics_override_speed);
playersao->m_physics_override_jump = getfloatfield_default(
L, 2, "jump", playersao->m_physics_override_jump);
playersao->m_physics_override_gravity = getfloatfield_default(
L, 2, "gravity", playersao->m_physics_override_gravity);
playersao->m_physics_override_sneak = getboolfield_default(
L, 2, "sneak", playersao->m_physics_override_sneak);
playersao->m_physics_override_sneak_glitch = getboolfield_default(
L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch);
playersao->m_physics_override_new_move = getboolfield_default(
L, 2, "new_move", playersao->m_physics_override_new_move);
playersao->m_physics_override_sent = false;
if (lua_istable(L, 2)) {
bool modified = false;
modified |= getfloatfield(L, 2, "speed", playersao->m_physics_override_speed);
modified |= getfloatfield(L, 2, "jump", playersao->m_physics_override_jump);
modified |= getfloatfield(L, 2, "gravity", playersao->m_physics_override_gravity);
modified |= getboolfield(L, 2, "sneak", playersao->m_physics_override_sneak);
modified |= getboolfield(L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch);
modified |= getboolfield(L, 2, "new_move", playersao->m_physics_override_new_move);
if (modified)
playersao->m_physics_override_sent = false;
} else {
// old, non-table format
// TODO: Remove this code after version 5.4.0
log_deprecated(L, "Deprecated use of set_physics_override(num, num, num)");

if (!lua_isnil(L, 2)) {
playersao->m_physics_override_speed = lua_tonumber(L, 2);
playersao->m_physics_override_sent = false;
}
if (!lua_isnil(L, 3)) {
playersao->m_physics_override_jump = lua_tonumber(L, 3);
playersao->m_physics_override_sent = false;
}
if (!lua_isnil(L, 4)) {
playersao->m_physics_override_gravity = lua_tonumber(L, 4);
playersao->m_physics_override_sent = false;
}
}
return 0;
}

0 comments on commit fca4db4

Please sign in to comment.
You can’t perform that action at this time.