mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-30 12:32:36 +00:00
Use sol::optional for optional table instead of function overloading.
This commit is contained in:
parent
09f6daf155
commit
7f0f2373ea
@ -256,26 +256,31 @@ namespace MWLua
|
|||||||
return anim->getNode(bonename) != nullptr;
|
return anim->getNode(bonename) != nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
api["addVfx"] = sol::overload(
|
api["addVfx"] = [context](
|
||||||
[context](const sol::object& object, const std::string& model) {
|
const sol::object& object, const std::string& model, sol::optional<sol::table> options) {
|
||||||
|
if (options)
|
||||||
|
{
|
||||||
|
context.mLuaManager->addAction(
|
||||||
|
[object = ObjectVariant(object), model = model,
|
||||||
|
effectId = options->get_or<std::string>("vfxId", ""), loop = options->get_or("loop", false),
|
||||||
|
boneName = options->get_or<std::string>("boneName", ""),
|
||||||
|
particleTexture = options->get_or<std::string>("particleTextureOverride", "")] {
|
||||||
|
MWRender::Animation* anim = getMutableAnimationOrThrow(ObjectVariant(object));
|
||||||
|
|
||||||
|
anim->addEffect(model, effectId, loop, boneName, particleTexture);
|
||||||
|
},
|
||||||
|
"addVfxAction");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
context.mLuaManager->addAction(
|
context.mLuaManager->addAction(
|
||||||
[object = ObjectVariant(object), model = model] {
|
[object = ObjectVariant(object), model = model] {
|
||||||
MWRender::Animation* anim = getMutableAnimationOrThrow(object);
|
MWRender::Animation* anim = getMutableAnimationOrThrow(object);
|
||||||
anim->addEffect(model, "");
|
anim->addEffect(model, "");
|
||||||
},
|
},
|
||||||
"addVfxAction");
|
"addVfxAction");
|
||||||
},
|
}
|
||||||
[context](const sol::object& object, const std::string& model, const sol::table& options) {
|
};
|
||||||
context.mLuaManager->addAction(
|
|
||||||
[object = ObjectVariant(object), model = model, effectId = options.get_or<std::string>("vfxId", ""),
|
|
||||||
loop = options.get_or("loop", false), boneName = options.get_or<std::string>("boneName", ""),
|
|
||||||
particleTexture = options.get_or<std::string>("particleTextureOverride", "")] {
|
|
||||||
MWRender::Animation* anim = getMutableAnimationOrThrow(ObjectVariant(object));
|
|
||||||
|
|
||||||
anim->addEffect(model, effectId, loop, boneName, particleTexture);
|
|
||||||
},
|
|
||||||
"addVfxAction");
|
|
||||||
});
|
|
||||||
|
|
||||||
api["removeVfx"] = [context](const sol::object& object, std::string_view effectId) {
|
api["removeVfx"] = [context](const sol::object& object, std::string_view effectId) {
|
||||||
context.mLuaManager->addAction(
|
context.mLuaManager->addAction(
|
||||||
@ -304,23 +309,26 @@ namespace MWLua
|
|||||||
sol::table api(lua, sol::create);
|
sol::table api(lua, sol::create);
|
||||||
auto world = MWBase::Environment::get().getWorld();
|
auto world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
api["spawn"] = sol::overload(
|
api["spawn"]
|
||||||
[world, context](const std::string model, const osg::Vec3f& worldPos) {
|
= [world, context](const std::string model, const osg::Vec3f& worldPos, sol::optional<sol::table> options) {
|
||||||
context.mLuaManager->addAction(
|
if (options)
|
||||||
[world, model = model, worldPos]() { world->spawnEffect(model, "", worldPos); },
|
{
|
||||||
"openmw.vfx.spawn");
|
bool magicVfx = options->get_or("mwMagicVfx", true);
|
||||||
},
|
std::string texture = options->get_or<std::string>("particleTextureOverride", "");
|
||||||
[world, context](const std::string& model, const osg::Vec3f& worldPos, const sol::table& options) {
|
float scale = options->get_or("scale", 1.f);
|
||||||
bool magicVfx = options.get_or("mwMagicVfx", true);
|
context.mLuaManager->addAction(
|
||||||
std::string texture = options.get_or<std::string>("particleTextureOverride", "");
|
[world, model = model, texture = std::move(texture), worldPos, scale, magicVfx]() {
|
||||||
float scale = options.get_or("scale", 1.f);
|
world->spawnEffect(model, texture, worldPos, scale, magicVfx);
|
||||||
|
},
|
||||||
context.mLuaManager->addAction(
|
"openmw.vfx.spawn");
|
||||||
[world, model = model, texture = std::move(texture), worldPos, scale, magicVfx]() {
|
}
|
||||||
world->spawnEffect(model, texture, worldPos, scale, magicVfx);
|
else
|
||||||
},
|
{
|
||||||
"openmw.vfx.spawn");
|
context.mLuaManager->addAction(
|
||||||
});
|
[world, model = model, worldPos]() { world->spawnEffect(model, "", worldPos); },
|
||||||
|
"openmw.vfx.spawn");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,6 @@ return {
|
|||||||
Unpause = function(tag) world.unpause(tag) end,
|
Unpause = function(tag) world.unpause(tag) end,
|
||||||
SetGameTimeScale = function(scale) world.setGameTimeScale(scale) end,
|
SetGameTimeScale = function(scale) world.setGameTimeScale(scale) end,
|
||||||
SetSimulationTimeScale = function(scale) world.setSimulationTimeScale(scale) end,
|
SetSimulationTimeScale = function(scale) world.setSimulationTimeScale(scale) end,
|
||||||
SpawnVfx = function(data)
|
SpawnVfx = function(data) world.vfx.spawn(data.model, data.position, data.options) end,
|
||||||
if data.options then
|
|
||||||
world.vfx.spawn(data.model, data.position, data.options)
|
|
||||||
else
|
|
||||||
world.vfx.spawn(data.model, data.position)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user