Move effect name init to Lua

This commit is contained in:
Evil Eye
2026-04-02 20:08:11 +02:00
committed by Alexei Kotov
parent b409c6701f
commit 973386d939
5 changed files with 28 additions and 16 deletions
+12
View File
@@ -303,6 +303,18 @@ namespace MWLua
addMutableMagicEffectType(lua);
sol::table api(lua, sol::create);
api["records"] = MutableStore<ESM::MagicEffect>{ store };
// We can't get rid of the GMST table engine side because mwscript needs it, so intead of copying it into a
// Lua file we've got this hidden function to generate it
api["_getGMSTs"] = [](sol::this_state state) {
sol::table gmsts(state, sol::create);
for (int i = 0; i < ESM::MagicEffect::Length; ++i)
{
const ESM::RefId effect = ESM::MagicEffect::indexToRefId(i);
const std::string_view gmst = ESM::MagicEffect::refIdToGmstString(effect);
gmsts[effect] = gmst;
}
return gmsts;
};
return LuaUtil::makeReadOnly(api);
}
-1
View File
@@ -525,7 +525,6 @@ namespace MWWorld
store->setUp();
getWritable<ESM::Skill>().setUp(get<ESM::GameSetting>());
getWritable<ESM::MagicEffect>().setUp(get<ESM::GameSetting>());
getWritable<ESM::Attribute>().setUp(get<ESM::GameSetting>());
getWritable<ESM4::Land>().updateLandPositions(get<ESM4::Cell>());
getWritable<ESM4::Reference>().preprocessReferences(get<ESM4::Cell>());
-13
View File
@@ -999,19 +999,6 @@ namespace MWWorld
.mWerewolfValue = getGMSTFloat(settings, "fWerewolfLuck") });
}
// Magic Effect
//=========================================================================
void Store<ESM::MagicEffect>::setUp(const MWWorld::Store<ESM::GameSetting>& settings)
{
for (ESM::MagicEffect* mgef : mShared)
{
std::string_view gmst = ESM::MagicEffect::refIdToGmstString(mgef->mId);
if (!gmst.empty())
mgef->mName = getGMSTString(settings, gmst);
}
}
// Dialogue
//=========================================================================
-2
View File
@@ -466,8 +466,6 @@ namespace MWWorld
public:
Store() = default;
void setUp(const MWWorld::Store<ESM::GameSetting>& settings);
};
template <>
@@ -82,12 +82,28 @@ local function generateDefaultDoors()
end
end
local function setMagicEffectNames()
local gmsts = content.gameSettings.records
local effects = content.magicEffects.records
for id, gmst in pairs(content.magicEffects._getGMSTs()) do
local effect = effects[id]
if effect ~= nil then
local name = gmsts[gmst]
if type(name) ~= 'string' or name == '' then
name = gmst
end
effect.name = name
end
end
end
return {
engineHandlers = {
onContentFilesLoaded = function()
generateDefaultDoors()
generateDefaultGMSTs()
generateDefaultStatics()
setMagicEffectNames()
end
}
}