1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00

Merge branch 'lua_controls' into 'master'

Remove Lua command "self:setDirectControl"

See merge request OpenMW/openmw!1084
This commit is contained in:
psi29a 2021-08-03 12:34:35 +00:00
commit 09705260e8
5 changed files with 14 additions and 19 deletions

View File

@ -43,7 +43,7 @@ namespace MWBase
struct ActorControls struct ActorControls
{ {
bool mDisableAI = false; bool mDisableAI = false;
bool mControlledFromLua = false; bool mChanged = false;
bool mJump = false; bool mJump = false;
bool mRun = false; bool mRun = false;

View File

@ -22,11 +22,15 @@ namespace MWLua
{ {
using ActorControls = MWBase::LuaManager::ActorControls; using ActorControls = MWBase::LuaManager::ActorControls;
sol::usertype<ActorControls> controls = context.mLua->sol().new_usertype<ActorControls>("ActorControls"); sol::usertype<ActorControls> controls = context.mLua->sol().new_usertype<ActorControls>("ActorControls");
controls["movement"] = &ActorControls::mMovement;
controls["sideMovement"] = &ActorControls::mSideMovement; #define CONTROL(TYPE, FIELD) sol::property([](const ActorControls& c) { return c.FIELD; },\
controls["turn"] = &ActorControls::mTurn; [](ActorControls& c, const TYPE& v) { c.FIELD = v; c.mChanged = true; })
controls["run"] = &ActorControls::mRun; controls["movement"] = CONTROL(float, mMovement);
controls["jump"] = &ActorControls::mJump; controls["sideMovement"] = CONTROL(float, mSideMovement);
controls["turn"] = CONTROL(float, mTurn);
controls["run"] = CONTROL(bool, mRun);
controls["jump"] = CONTROL(bool, mJump);
#undef CONTROL
sol::usertype<SelfObject> selfAPI = sol::usertype<SelfObject> selfAPI =
context.mLua->sol().new_usertype<SelfObject>("SelfObject", sol::base_classes, sol::bases<LObject>()); context.mLua->sol().new_usertype<SelfObject>("SelfObject", sol::base_classes, sol::bases<LObject>());
@ -34,7 +38,6 @@ namespace MWLua
selfAPI["object"] = sol::readonly_property([](SelfObject& self) -> LObject { return LObject(self); }); selfAPI["object"] = sol::readonly_property([](SelfObject& self) -> LObject { return LObject(self); });
selfAPI["controls"] = sol::readonly_property([](SelfObject& self) { return &self.mControls; }); selfAPI["controls"] = sol::readonly_property([](SelfObject& self) { return &self.mControls; });
selfAPI["isActive"] = [](SelfObject& self) { return &self.mIsActive; }; selfAPI["isActive"] = [](SelfObject& self) { return &self.mIsActive; };
selfAPI["setDirectControl"] = [](SelfObject& self, bool v) { self.mControls.mControlledFromLua = v; };
selfAPI["enableAI"] = [](SelfObject& self, bool v) { self.mControls.mDisableAI = !v; }; selfAPI["enableAI"] = [](SelfObject& self, bool v) { self.mControls.mDisableAI = !v; };
selfAPI["setEquipment"] = [manager=context.mLuaManager](const SelfObject& obj, sol::table equipment) selfAPI["setEquipment"] = [manager=context.mLuaManager](const SelfObject& obj, sol::table equipment)
{ {
@ -82,8 +85,6 @@ namespace MWLua
LocalScripts::LocalScripts(LuaUtil::LuaState* lua, const LObject& obj) LocalScripts::LocalScripts(LuaUtil::LuaState* lua, const LObject& obj)
: LuaUtil::ScriptsContainer(lua, "L" + idToString(obj.id())), mData(obj) : LuaUtil::ScriptsContainer(lua, "L" + idToString(obj.id())), mData(obj)
{ {
mData.mControls.mControlledFromLua = false;
mData.mControls.mDisableAI = false;
this->addPackage("openmw.self", sol::make_object(lua->sol(), &mData)); this->addPackage("openmw.self", sol::make_object(lua->sol(), &mData));
registerEngineHandlers({&mOnActiveHandlers, &mOnInactiveHandlers, &mOnConsumeHandlers}); registerEngineHandlers({&mOnActiveHandlers, &mOnInactiveHandlers, &mOnConsumeHandlers});
} }

View File

@ -31,7 +31,7 @@ namespace MWLua
{ {
auto* lua = context.mLua; auto* lua = context.mLua;
sol::table api(lua->sol(), sol::create); sol::table api(lua->sol(), sol::create);
api["API_REVISION"] = 1; api["API_REVISION"] = 2;
api["sendGlobalEvent"] = [context](std::string eventName, const sol::object& eventData) api["sendGlobalEvent"] = [context](std::string eventName, const sol::object& eventData)
{ {
context.mGlobalEventQueue->push_back({std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer)}); context.mGlobalEventQueue->push_back({std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer)});

View File

@ -2095,7 +2095,7 @@ namespace MWMechanics
float rotationZ = mov.mRotation[2]; float rotationZ = mov.mRotation[2];
bool jump = mov.mPosition[2] == 1; bool jump = mov.mPosition[2] == 1;
bool runFlag = stats.getMovementFlag(MWMechanics::CreatureStats::Flag_Run); bool runFlag = stats.getMovementFlag(MWMechanics::CreatureStats::Flag_Run);
if (luaControls->mControlledFromLua) if (luaControls->mChanged)
{ {
mov.mPosition[0] = luaControls->mSideMovement; mov.mPosition[0] = luaControls->mSideMovement;
mov.mPosition[1] = luaControls->mMovement; mov.mPosition[1] = luaControls->mMovement;
@ -2104,6 +2104,7 @@ namespace MWMechanics
mov.mRotation[2] = luaControls->mTurn; mov.mRotation[2] = luaControls->mTurn;
mov.mSpeedFactor = osg::Vec2(luaControls->mMovement, luaControls->mSideMovement).length(); mov.mSpeedFactor = osg::Vec2(luaControls->mMovement, luaControls->mSideMovement).length();
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, luaControls->mRun); stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, luaControls->mRun);
luaControls->mChanged = false;
} }
luaControls->mSideMovement = movement.x(); luaControls->mSideMovement = movement.x();
luaControls->mMovement = movement.y(); luaControls->mMovement = movement.y();

View File

@ -26,8 +26,7 @@
-- @field [parent=#self] #ActorControls controls -- @field [parent=#self] #ActorControls controls
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Allows to view and/or modify controls of an actor. Makes an effect only if -- Allows to view and/or modify controls of an actor. All fields are mutable.
-- `setDirectControl(true)` was called. All fields are mutable.
-- @type ActorControls -- @type ActorControls
-- @field [parent=#ActorControls] #number movement +1 - move forward, -1 - move backward -- @field [parent=#ActorControls] #number movement +1 - move forward, -1 - move backward
-- @field [parent=#ActorControls] #number sideMovement +1 - move right, -1 - move left -- @field [parent=#ActorControls] #number sideMovement +1 - move right, -1 - move left
@ -35,12 +34,6 @@
-- @field [parent=#ActorControls] #boolean run true - run, false - walk -- @field [parent=#ActorControls] #boolean run true - run, false - walk
-- @field [parent=#ActorControls] #boolean jump If true - initiate a jump -- @field [parent=#ActorControls] #boolean jump If true - initiate a jump
-------------------------------------------------------------------------------
-- Enables or disables direct movement control (disabled by default).
-- @function [parent=#self] setDirectControl
-- @param self
-- @param #boolean control
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Enables or disables standart AI (enabled by default). -- Enables or disables standart AI (enabled by default).
-- @function [parent=#self] enableAI -- @function [parent=#self] enableAI