Move Fallback->GMST to Lua

This commit is contained in:
Evil Eye
2026-04-02 00:32:41 +03:00
committed by Alexei Kotov
parent 8c7946b945
commit bbee64cfe5
5 changed files with 20 additions and 24 deletions
+11
View File
@@ -8,6 +8,7 @@
#include <components/esm3/loadsoun.hpp>
#include <components/esm3/loadspel.hpp>
#include <components/esm3/loadstat.hpp>
#include <components/fallback/fallback.hpp>
#include <components/lua/util.hpp>
#include "context.hpp"
@@ -153,6 +154,16 @@ namespace MWLua
});
sol::table api(lua, sol::create);
api["records"] = MutableStore<ESM::GameSetting>{ 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);
}
-22
View File
@@ -10,7 +10,6 @@
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/fallback/fallback.hpp>
#include <components/loadinglistener/loadinglistener.hpp>
#include <components/misc/rng.hpp>
@@ -952,27 +951,6 @@ namespace MWWorld
return TypedDynamicStore::search(ESM::RefId::stringRefId(id));
}
void Store<ESM::GameSetting>::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<ESM::GameSetting>::setUp();
}
// Attribute
//=========================================================================
-2
View File
@@ -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 <>
@@ -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()
+5
View File
@@ -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