From bbee64cfe5dcaeb2663997ab577ee19b7d563f1e Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 30 Mar 2026 21:47:32 +0200 Subject: [PATCH] Move Fallback->GMST to Lua --- apps/openmw/mwlua/contentbindings.cpp | 11 +++++++++++ apps/openmw/mwworld/store.cpp | 22 ---------------------- apps/openmw/mwworld/store.hpp | 2 -- files/data-mw/scripts/omw/esmfallbacks.lua | 4 ++++ files/lua_api/openmw/content.lua | 5 +++++ 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwlua/contentbindings.cpp b/apps/openmw/mwlua/contentbindings.cpp index 5f03eee1c6..31bdc6ea30 100644 --- a/apps/openmw/mwlua/contentbindings.cpp +++ b/apps/openmw/mwlua/contentbindings.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "context.hpp" @@ -153,6 +154,16 @@ namespace MWLua }); sol::table api(lua, sol::create); api["records"] = MutableStore{ store }; + api["getFallbacks"] = [](sol::this_state state) { + sol::table out(state, sol::create); + for (auto& [key, value] : Fallback::Map::getIntFallbackMap()) + out[key] = sol::make_object(state, value); + for (auto& [key, value] : Fallback::Map::getFloatFallbackMap()) + out[key] = sol::make_object(state, value); + for (auto& [key, value] : Fallback::Map::getNonNumericFallbackMap()) + out[key] = sol::make_object(state, value); + return out; + }; return LuaUtil::makeReadOnly(api); } diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 1e1cf625db..3c05e0fd93 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -952,27 +951,6 @@ namespace MWWorld return TypedDynamicStore::search(ESM::RefId::stringRefId(id)); } - void Store::setUp() - { - auto addSetting = [&](const std::string& key, ESM::Variant value) { - auto id = ESM::RefId::stringRefId(key); - ESM::GameSetting setting; - setting.blank(); - setting.mId = id; - setting.mValue = std::move(value); - auto [iter, inserted] = mStatic.insert_or_assign(id, std::move(setting)); - if (inserted) - mShared.push_back(&iter->second); - }; - for (auto& [key, value] : Fallback::Map::getIntFallbackMap()) - addSetting(key, ESM::Variant(value)); - for (auto& [key, value] : Fallback::Map::getFloatFallbackMap()) - addSetting(key, ESM::Variant(value)); - for (auto& [key, value] : Fallback::Map::getNonNumericFallbackMap()) - addSetting(key, ESM::Variant(value)); - TypedDynamicStore::setUp(); - } - // Attribute //========================================================================= diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 80a52846ba..9d4f100f24 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -278,8 +278,6 @@ namespace MWWorld const ESM::GameSetting* find(const std::string_view id) const; const ESM::GameSetting* search(const std::string_view id) const; - - void setUp() override; }; template <> diff --git a/files/data-mw/scripts/omw/esmfallbacks.lua b/files/data-mw/scripts/omw/esmfallbacks.lua index fd8394508e..0c895f19c7 100644 --- a/files/data-mw/scripts/omw/esmfallbacks.lua +++ b/files/data-mw/scripts/omw/esmfallbacks.lua @@ -65,6 +65,10 @@ local function generateDefaultGMSTs() store[id] = value end end + local fallbacks = content.gameSettings.getFallbacks() + for id, value in pairs(fallbacks) do + store[id] = value + end end local function generateDefaultDoors() diff --git a/files/lua_api/openmw/content.lua b/files/lua_api/openmw/content.lua index 422edcc00d..5b8194d784 100644 --- a/files/lua_api/openmw/content.lua +++ b/files/lua_api/openmw/content.lua @@ -43,6 +43,11 @@ --- @{#GMSTContent}: GMST manipulation. -- @field [parent=#content] #GMSTContent gameSettings +--- +-- Returns a table containing all fallback values defined in `openmw.cfg`. +-- @function [parent=#GMSTContent] getFallbacks +-- @return #table + --- -- A mutable list of all game settings. -- @field [parent=#GMSTContent] #map<#string, #any> records