Skip to content

Commit

Permalink
Merge pull request #920 from maximegmd/revert-912-master
Browse files Browse the repository at this point in the history
Revert "Expose mod input handlers for better integration between mods"
  • Loading branch information
maximegmd committed Jan 31, 2024
2 parents e7ecc73 + ed0e3ec commit 2edfe6d
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 61 deletions.
1 change: 0 additions & 1 deletion src/VKBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct VKBind
std::string DisplayName{};
std::variant<std::string, std::function<void()>> Description{};
std::variant<std::function<TVKBindHotkeyCallback>, std::function<TVKBindInputCallback>> Handler{};
sol::function VmHandler{};

[[nodiscard]] std::function<void()> DelayedCall(const bool acIsDown) const;
void Call(const bool acIsDown) const;
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/LuaSandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static constexpr const char* s_cPostInitializeTweakDBProtectedList[] = {

static constexpr const char* s_cPostInitializeModsProtectedList[] = {
// initialized by Scripting
"NewObject", "GetSingleton", "GetMods", "GetMod", "GameDump", "Dump", "DumpType", "DumpAllTypeNames", "DumpVtables", "DumpReflection", "Game",
"NewObject", "GetSingleton", "GetMod", "GameDump", "Dump", "DumpType", "DumpAllTypeNames", "DumpVtables", "DumpReflection", "Game",

// initialized by RTTIMapper
"Vector3", "ToVector3", "Vector4", "ToVector4", "EulerAngles", "ToEulerAngles", "Quaternion", "ToQuaternion", "ItemID", "ToItemID"};
Expand Down
34 changes: 1 addition & 33 deletions src/scripting/ScriptContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ScriptContext::ScriptContext(LuaSandbox& aLuaSandbox, const std::filesystem::pat
return;
}

m_vkBinds.emplace_back(acID, acDisplayName, wrapDescription(acDescription), wrapHandler(aCallback, acIsHotkey), aCallback);
m_vkBinds.emplace_back(acID, acDisplayName, wrapDescription(acDescription), wrapHandler(aCallback, acIsHotkey));
};

env["registerHotkey"] = sol::overload(
Expand Down Expand Up @@ -294,38 +294,6 @@ sol::object ScriptContext::GetRootObject() const
return m_object;
}

sol::object ScriptContext::GetInputHandlers() const
{
auto lockedState = m_sandbox.GetLockedState();
const auto& bindings = CET::Get().GetBindings();
sol::table res(lockedState.Get(), sol::create);
for (const auto& bind : m_vkBinds)
{
sol::table info(lockedState.Get(), sol::create);
info["id"] = bind.ID;
info["displayName"] = bind.DisplayName;
info["callback"] = bind.VmHandler;
info["isHotkey"] = bind.IsHotkey();
info["isBound"] = bindings.IsBound({m_name, bind.ID});
if (std::holds_alternative<std::string>(bind.Description))
{
info["description"] = std::get<std::string>(bind.Description);
}
res[bind.ID] = info;
}
return res;
}

sol::object ScriptContext::GetMod() const
{
auto lockedState = m_sandbox.GetLockedState();
sol::table modInfo(lockedState.Get(), sol::create);
modInfo["name"] = m_name;
modInfo["rootObject"] = GetRootObject();
modInfo["inputHandlers"] = GetInputHandlers();
return modInfo;
}

void ScriptContext::TriggerOnShutdown() const
{
auto lockedState = m_sandbox.GetLockedState();
Expand Down
2 changes: 0 additions & 2 deletions src/scripting/ScriptContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ struct ScriptContext
void TriggerOnOverlayClose() const;

[[nodiscard]] sol::object GetRootObject() const;
[[nodiscard]] sol::object GetInputHandlers() const;
[[nodiscard]] sol::object GetMod() const;

private:
void TriggerOnShutdown() const;
Expand Down
13 changes: 1 addition & 12 deletions src/scripting/ScriptStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,11 @@ void ScriptStore::TriggerOnOverlayClose() const
mod.TriggerOnOverlayClose();
}

sol::object ScriptStore::GetMods() const
{
auto lockedState = m_sandbox.GetLockedState();
sol::table res(lockedState.Get(), sol::create);
for (const auto& [name, context] : m_contexts)
{
res[name] = context.GetMod();
}
return res;
}

sol::object ScriptStore::GetMod(const std::string& acName) const
{
const auto it = m_contexts.find(acName);
if (it != m_contexts.cend())
return it->second.GetMod();
return it->second.GetRootObject();

return sol::nil;
}
1 change: 0 additions & 1 deletion src/scripting/ScriptStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct ScriptStore
void TriggerOnOverlayOpen() const;
void TriggerOnOverlayClose() const;

[[nodiscard]] sol::object GetMods() const;
[[nodiscard]] sol::object GetMod(const std::string& acName) const;

private:
Expand Down
10 changes: 0 additions & 10 deletions src/scripting/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,6 @@ void Scripting::PostInitializeScripting()
return this->GetSingletonHandle(acName, aThisEnv);
};

globals["GetMods"] = [this]() -> sol::object
{
return GetMods();
};

globals["GetMod"] = [this](const std::string& acName) -> sol::object
{
return GetMod(acName);
Expand Down Expand Up @@ -604,11 +599,6 @@ void Scripting::TriggerOnOverlayClose() const
m_store.TriggerOnOverlayClose();
}

sol::object Scripting::GetMods() const
{
return m_store.GetMods();
}

sol::object Scripting::GetMod(const std::string& acName) const
{
return m_store.GetMod(acName);
Expand Down
1 change: 0 additions & 1 deletion src/scripting/Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct Scripting
void TriggerOnOverlayOpen() const;
void TriggerOnOverlayClose() const;

sol::object GetMods() const;
sol::object GetMod(const std::string& acName) const;
void UnloadAllMods();
void ReloadAllMods();
Expand Down

0 comments on commit 2edfe6d

Please sign in to comment.