Update StarRenderingLuaBindings.cpp

This commit is contained in:
Bottinator22 2024-12-28 20:07:34 -08:00 committed by GitHub
parent 1a0bf768f0
commit f7dc97965d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,8 @@
#include "StarRenderingLuaBindings.hpp"
#include "StarJsonExtra.hpp"
#include "StarLuaConverters.hpp"
#include "StarClientApplication.hpp"
#include "StarRenderer.hpp"
namespace Star {
@ -11,8 +13,30 @@ LuaCallbacks LuaBindings::makeRenderingCallbacks(ClientApplication* app) {
callbacks.registerCallbackWithSignature<void, String, bool, Maybe<bool>>("setPostProcessGroupEnabled", bind(mem_fn(&ClientApplication::setPostProcessGroupEnabled), app, _1, _2, _3));
callbacks.registerCallbackWithSignature<bool, String>("postProcessGroupEnabled", bind(mem_fn(&ClientApplication::postProcessGroupEnabled), app, _1));
// not entirely necessary (root.assetJson can achieve the same purpose) but may as well
callbacks.registerCallbackWithSignature<Json>("postProcessGroups", bind(mem_fn(&ClientApplication::postProcessGroups), app));
// typedef Variant<float, int, Vec2F, Vec3F, Vec4F, bool> RenderEffectParameter;
// feel free to change this if there's a better way to do this
// specifically checks if the effect parameter is an int since Lua prefers converting the values to floats
callbacks.registerCallback("setEffectParameter", [app](String const& effectName, String const& effectParameter, RenderEffectParameter const& value) {
auto renderer = app->renderer();
auto mtype = renderer->getEffectScriptableParameterType(effectName, effectParameter);
if (mtype) {
auto type = mtype.value();
if (type == 1 && value.is<float>()) {
renderer->setEffectScriptableParameter(effectName, effectParameter, (int)value.get<float>());
} else {
renderer->setEffectScriptableParameter(effectName, effectParameter, value);
}
}
});
callbacks.registerCallback("getEffectParameter", [app](String const& effectName, String const& effectParameter) {
auto renderer = app->renderer();
return renderer->getEffectScriptableParameter(effectName, effectParameter);
});
return callbacks;
}