mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Merge branch 'revert-456ac2a8' into 'master'
Revert "Merge branch 'were_engineers_not_salt_miners' into 'master'" See merge request OpenMW/openmw!4207
This commit is contained in:
commit
daada262d7
13 changed files with 55 additions and 123 deletions
|
@ -246,7 +246,6 @@
|
||||||
Feature #7964: Add Lua read access to MW Dialogue records
|
Feature #7964: Add Lua read access to MW Dialogue records
|
||||||
Feature #7971: Make save's Time Played value display hours instead of days
|
Feature #7971: Make save's Time Played value display hours instead of days
|
||||||
Feature #7985: Support dark mode on Windows
|
Feature #7985: Support dark mode on Windows
|
||||||
Feature #8028: Lua Engine Handler for MWScript `startscript` functionality.
|
|
||||||
Task #5896: Do not use deprecated MyGUI properties
|
Task #5896: Do not use deprecated MyGUI properties
|
||||||
Task #6085: Replace boost::filesystem with std::filesystem
|
Task #6085: Replace boost::filesystem with std::filesystem
|
||||||
Task #6149: Dehardcode Lua API_REVISION
|
Task #6149: Dehardcode Lua API_REVISION
|
||||||
|
|
|
@ -150,9 +150,6 @@ namespace MWBase
|
||||||
= 0;
|
= 0;
|
||||||
|
|
||||||
virtual std::string formatResourceUsageStats() const = 0;
|
virtual std::string formatResourceUsageStats() const = 0;
|
||||||
|
|
||||||
virtual void globalMWScriptCalled(const ESM::RefId& scriptName, const MWWorld::Ptr& target, const bool started)
|
|
||||||
= 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,14 +113,6 @@ namespace MWLua
|
||||||
scripts->onSkillLevelUp(event.mSkill, event.mSource);
|
scripts->onSkillLevelUp(event.mSkill, event.mSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(const OnGlobalScriptRequested& event) const
|
|
||||||
{
|
|
||||||
sol::optional<GObject> target;
|
|
||||||
if (event.mTarget.isSet())
|
|
||||||
target = GObject(event.mTarget);
|
|
||||||
mGlobalScripts.onGlobalScriptRequested(MWScriptRef{ event.mScript, {} }, event.mStarted, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MWWorld::Ptr getPtr(ESM::RefNum id) const
|
MWWorld::Ptr getPtr(ESM::RefNum id) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,14 +70,8 @@ namespace MWLua
|
||||||
std::string mSkill;
|
std::string mSkill;
|
||||||
std::string mSource;
|
std::string mSource;
|
||||||
};
|
};
|
||||||
struct OnGlobalScriptRequested
|
|
||||||
{
|
|
||||||
ESM::RefId mScript;
|
|
||||||
ESM::RefNum mTarget;
|
|
||||||
bool mStarted;
|
|
||||||
};
|
|
||||||
using Event = std::variant<OnActive, OnInactive, OnConsume, OnActivate, OnUseItem, OnNewExterior, OnTeleported,
|
using Event = std::variant<OnActive, OnInactive, OnConsume, OnActivate, OnUseItem, OnNewExterior, OnTeleported,
|
||||||
OnAnimationTextKey, OnSkillUse, OnSkillLevelUp, OnGlobalScriptRequested>;
|
OnAnimationTextKey, OnSkillUse, OnSkillLevelUp>;
|
||||||
|
|
||||||
void clear() { mQueue.clear(); }
|
void clear() { mQueue.clear(); }
|
||||||
void addToQueue(Event e) { mQueue.push_back(std::move(e)); }
|
void addToQueue(Event e) { mQueue.push_back(std::move(e)); }
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <components/lua/luastate.hpp>
|
#include <components/lua/luastate.hpp>
|
||||||
#include <components/lua/scriptscontainer.hpp>
|
#include <components/lua/scriptscontainer.hpp>
|
||||||
|
|
||||||
#include "mwscriptref.hpp"
|
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
|
@ -25,7 +24,6 @@ namespace MWLua
|
||||||
&mOnActivateHandlers,
|
&mOnActivateHandlers,
|
||||||
&mOnUseItemHandlers,
|
&mOnUseItemHandlers,
|
||||||
&mOnNewExteriorHandlers,
|
&mOnNewExteriorHandlers,
|
||||||
&mOnGlobalScriptRequestedHandlers,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +41,6 @@ namespace MWLua
|
||||||
callEngineHandlers(mOnUseItemHandlers, obj, actor, force);
|
callEngineHandlers(mOnUseItemHandlers, obj, actor, force);
|
||||||
}
|
}
|
||||||
void onNewExterior(const GCell& cell) { callEngineHandlers(mOnNewExteriorHandlers, cell); }
|
void onNewExterior(const GCell& cell) { callEngineHandlers(mOnNewExteriorHandlers, cell); }
|
||||||
void onGlobalScriptRequested(const MWScriptRef& scriptRef, const bool started, sol::optional<GObject> target)
|
|
||||||
{
|
|
||||||
callEngineHandlers(mOnGlobalScriptRequestedHandlers, scriptRef, started, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EngineHandlerList mObjectActiveHandlers{ "onObjectActive" };
|
EngineHandlerList mObjectActiveHandlers{ "onObjectActive" };
|
||||||
|
@ -57,7 +51,6 @@ namespace MWLua
|
||||||
EngineHandlerList mOnActivateHandlers{ "onActivate" };
|
EngineHandlerList mOnActivateHandlers{ "onActivate" };
|
||||||
EngineHandlerList mOnUseItemHandlers{ "_onUseItem" };
|
EngineHandlerList mOnUseItemHandlers{ "_onUseItem" };
|
||||||
EngineHandlerList mOnNewExteriorHandlers{ "onNewExterior" };
|
EngineHandlerList mOnNewExteriorHandlers{ "onNewExterior" };
|
||||||
EngineHandlerList mOnGlobalScriptRequestedHandlers{ "onGlobalScriptRequested" };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#include "luamanagerimp.hpp"
|
#include "luamanagerimp.hpp"
|
||||||
|
|
||||||
#include <apps/openmw/mwlua/mwscriptref.hpp>
|
|
||||||
#include <apps/openmw/mwlua/object.hpp>
|
|
||||||
#include <components/misc/strings/lower.hpp>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include <MyGUI_InputManager.h>
|
#include <MyGUI_InputManager.h>
|
||||||
|
@ -604,14 +601,6 @@ namespace MWLua
|
||||||
mGlobalScriptsStarted = true;
|
mGlobalScriptsStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::globalMWScriptCalled(const ESM::RefId& scriptName, const MWWorld::Ptr& target, const bool started)
|
|
||||||
{
|
|
||||||
ESM::RefNum targetId;
|
|
||||||
if (!target.isEmpty())
|
|
||||||
targetId = getId(target);
|
|
||||||
mEngineEvents.addToQueue(EngineEvents::OnGlobalScriptRequested{ scriptName, targetId, started });
|
|
||||||
}
|
|
||||||
|
|
||||||
void LuaManager::saveLocalScripts(const MWWorld::Ptr& ptr, ESM::LuaScripts& data)
|
void LuaManager::saveLocalScripts(const MWWorld::Ptr& ptr, ESM::LuaScripts& data)
|
||||||
{
|
{
|
||||||
if (ptr.getRefData().getLuaScripts())
|
if (ptr.getRefData().getLuaScripts())
|
||||||
|
|
|
@ -156,9 +156,6 @@ namespace MWLua
|
||||||
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
|
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
|
||||||
std::string formatResourceUsageStats() const override;
|
std::string formatResourceUsageStats() const override;
|
||||||
|
|
||||||
void globalMWScriptCalled(
|
|
||||||
const ESM::RefId& scriptName, const MWWorld::Ptr& target, const bool started) override;
|
|
||||||
|
|
||||||
LuaUtil::InputAction::Registry& inputActions() { return mInputActions; }
|
LuaUtil::InputAction::Registry& inputActions() { return mInputActions; }
|
||||||
LuaUtil::InputTrigger::Registry& inputTriggers() { return mInputTriggers; }
|
LuaUtil::InputTrigger::Registry& inputTriggers() { return mInputTriggers; }
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,64 @@
|
||||||
#include <components/lua/util.hpp>
|
#include <components/lua/util.hpp>
|
||||||
#include <components/misc/strings/lower.hpp>
|
#include <components/misc/strings/lower.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwscript/globalscripts.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
#include "../mwworld/worldimp.hpp"
|
#include "../mwworld/worldimp.hpp"
|
||||||
|
|
||||||
#include "mwscriptref.hpp"
|
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
struct MWScriptRef
|
||||||
|
{
|
||||||
|
ESM::RefId mId;
|
||||||
|
sol::optional<GObject> mObj;
|
||||||
|
|
||||||
|
MWScript::Locals& getLocals()
|
||||||
|
{
|
||||||
|
if (mObj)
|
||||||
|
return mObj->ptr().getRefData().getLocals();
|
||||||
|
else
|
||||||
|
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocals(mId);
|
||||||
|
}
|
||||||
|
bool isRunning() const
|
||||||
|
{
|
||||||
|
if (mObj.has_value()) // local script
|
||||||
|
{
|
||||||
|
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
||||||
|
return localScripts.isRunning(mId, mObj->ptr());
|
||||||
|
}
|
||||||
|
|
||||||
|
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning(mId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct MWScriptVariables
|
||||||
|
{
|
||||||
|
MWScriptRef mRef;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace sol
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct is_automagical<MWLua::MWScriptRef> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_automagical<MWLua::MWScriptVariables> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_automagical<ESM::Global> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
#ifndef MWSCRIPTREF_H_
|
|
||||||
#define MWSCRIPTREF_H_
|
|
||||||
|
|
||||||
#include <sol/sol.hpp>
|
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
|
||||||
#include "../mwbase/scriptmanager.hpp"
|
|
||||||
#include "../mwbase/world.hpp"
|
|
||||||
#include "../mwscript/globalscripts.hpp"
|
|
||||||
#include "../mwworld/localscripts.hpp"
|
|
||||||
|
|
||||||
#include "object.hpp"
|
|
||||||
|
|
||||||
namespace MWLua
|
|
||||||
{
|
|
||||||
struct MWScriptRef
|
|
||||||
{
|
|
||||||
ESM::RefId mId;
|
|
||||||
sol::optional<GObject> mObj;
|
|
||||||
|
|
||||||
MWScript::Locals& getLocals()
|
|
||||||
{
|
|
||||||
if (mObj)
|
|
||||||
return mObj->ptr().getRefData().getLocals();
|
|
||||||
else
|
|
||||||
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocals(mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isRunning() const
|
|
||||||
{
|
|
||||||
if (mObj.has_value()) // local script
|
|
||||||
{
|
|
||||||
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
|
||||||
return localScripts.isRunning(mId, mObj->ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning(mId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct MWScriptVariables
|
|
||||||
{
|
|
||||||
MWScriptRef mRef;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace sol
|
|
||||||
{
|
|
||||||
template <>
|
|
||||||
struct is_automagical<MWLua::MWScriptRef> : std::false_type
|
|
||||||
{
|
|
||||||
};
|
|
||||||
template <>
|
|
||||||
struct is_automagical<MWLua::MWScriptVariables> : std::false_type
|
|
||||||
{
|
|
||||||
};
|
|
||||||
template <>
|
|
||||||
struct is_automagical<ESM::Global> : std::false_type
|
|
||||||
{
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MWSCRIPTREF_H_
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <sol/sol.hpp>
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
#include <components/esm3/cellref.hpp>
|
#include <components/esm3/cellref.hpp>
|
||||||
#include <components/esm3/loadglob.hpp>
|
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwworld/worldmodel.hpp"
|
#include "../mwworld/worldmodel.hpp"
|
||||||
|
|
||||||
#include "../mwbase/luamanager.hpp"
|
|
||||||
|
|
||||||
#include "interpretercontext.hpp"
|
#include "interpretercontext.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -130,7 +128,6 @@ namespace MWScript
|
||||||
void GlobalScripts::addScript(const ESM::RefId& name, const MWWorld::Ptr& target)
|
void GlobalScripts::addScript(const ESM::RefId& name, const MWWorld::Ptr& target)
|
||||||
{
|
{
|
||||||
const auto iter = mScripts.find(name);
|
const auto iter = mScripts.find(name);
|
||||||
bool started = false;
|
|
||||||
|
|
||||||
if (iter == mScripts.end())
|
if (iter == mScripts.end())
|
||||||
{
|
{
|
||||||
|
@ -139,24 +136,21 @@ namespace MWScript
|
||||||
auto desc = std::make_shared<GlobalScriptDesc>();
|
auto desc = std::make_shared<GlobalScriptDesc>();
|
||||||
MWWorld::Ptr ptr = target;
|
MWWorld::Ptr ptr = target;
|
||||||
desc->mTarget = ptr;
|
desc->mTarget = ptr;
|
||||||
started = desc->mRunning = true;
|
desc->mRunning = true;
|
||||||
desc->mLocals.configure(*script);
|
desc->mLocals.configure(*script);
|
||||||
mScripts.insert(std::make_pair(name, desc));
|
mScripts.insert(std::make_pair(name, desc));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(Debug::Error) << "Failed to add global script " << name << ": script record not found";
|
Log(Debug::Error) << "Failed to add global script " << name << ": script record not found";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!iter->second->mRunning)
|
else if (!iter->second->mRunning)
|
||||||
{
|
{
|
||||||
started = iter->second->mRunning = true;
|
iter->second->mRunning = true;
|
||||||
MWWorld::Ptr ptr = target;
|
MWWorld::Ptr ptr = target;
|
||||||
iter->second->mTarget = ptr;
|
iter->second->mTarget = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWBase::Environment::get().getLuaManager()->globalMWScriptCalled(name, target, started);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalScripts::removeScript(const ESM::RefId& name)
|
void GlobalScripts::removeScript(const ESM::RefId& name)
|
||||||
|
|
|
@ -178,7 +178,7 @@ namespace LuaUtil
|
||||||
|
|
||||||
// Calls given handlers in direct order.
|
// Calls given handlers in direct order.
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void callEngineHandlers(EngineHandlerList& handlers, Args&&... args)
|
void callEngineHandlers(EngineHandlerList& handlers, const Args&... args)
|
||||||
{
|
{
|
||||||
for (Handler& handler : handlers.mList)
|
for (Handler& handler : handlers.mList)
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,16 +58,6 @@ Engine handler is a function defined by a script, that can be called by the engi
|
||||||
- Object is activated by an actor.
|
- Object is activated by an actor.
|
||||||
* - onNewExterior(cell)
|
* - onNewExterior(cell)
|
||||||
- A new exterior cell not defined by a content file has been generated.
|
- A new exterior cell not defined by a content file has been generated.
|
||||||
* - onGlobalScriptRequested(script, started, target)
|
|
||||||
- | A `StartScript` was called.
|
|
||||||
| Note that this affects `Start Scripts` defined by content files, as well as calls to the MWScript function `StartScript`.
|
|
||||||
| This does not necessarily indicate the script in question is actually being started, as there may (presently)
|
|
||||||
| only be a single instance of a global script at a time.
|
|
||||||
| This can potentially be used to override vanilla functionality, such as:
|
|
||||||
| ``if script.recordId == 'dbattackscript' then script.variables.sleeponce = 1 end``
|
|
||||||
| The `target` and `script.object` fields may be different.
|
|
||||||
| If `started` is true then refer to `script.object`, otherwise the `target`, if present, represents what the `startscript` call is actually targeted at. For example:
|
|
||||||
| ``if started and script.object then print(script.object.recordId) elseif target then print(target.recordId) end``
|
|
||||||
|
|
||||||
**Only for local scripts**
|
**Only for local scripts**
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue