1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Reset player lighting when passing no arguments (#13525)

Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com>
This commit is contained in:
Zughy 2023-05-26 13:47:16 +02:00 committed by GitHub
parent b60d38b7f9
commit d6eb6ff973
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 24 deletions

View file

@ -2301,26 +2301,30 @@ int ObjectRef::l_set_lighting(lua_State *L)
if (player == nullptr)
return 0;
luaL_checktype(L, 2, LUA_TTABLE);
Lighting lighting = player->getLighting();
lua_getfield(L, 2, "shadows");
if (lua_istable(L, -1)) {
getfloatfield(L, -1, "intensity", lighting.shadow_intensity);
}
lua_pop(L, 1); // shadows
Lighting lighting;
getfloatfield(L, -1, "saturation", lighting.saturation);
if (!lua_isnoneornil(L, 2)) {
luaL_checktype(L, 2, LUA_TTABLE);
lighting = player->getLighting();
lua_getfield(L, 2, "shadows");
if (lua_istable(L, -1)) {
getfloatfield(L, -1, "intensity", lighting.shadow_intensity);
}
lua_pop(L, 1); // shadows
lua_getfield(L, 2, "exposure");
if (lua_istable(L, -1)) {
lighting.exposure.luminance_min = getfloatfield_default(L, -1, "luminance_min", lighting.exposure.luminance_min);
lighting.exposure.luminance_max = getfloatfield_default(L, -1, "luminance_max", lighting.exposure.luminance_max);
lighting.exposure.exposure_correction = getfloatfield_default(L, -1, "exposure_correction", lighting.exposure.exposure_correction);
lighting.exposure.speed_dark_bright = getfloatfield_default(L, -1, "speed_dark_bright", lighting.exposure.speed_dark_bright);
lighting.exposure.speed_bright_dark = getfloatfield_default(L, -1, "speed_bright_dark", lighting.exposure.speed_bright_dark);
lighting.exposure.center_weight_power = getfloatfield_default(L, -1, "center_weight_power", lighting.exposure.center_weight_power);
getfloatfield(L, -1, "saturation", lighting.saturation);
lua_getfield(L, 2, "exposure");
if (lua_istable(L, -1)) {
lighting.exposure.luminance_min = getfloatfield_default(L, -1, "luminance_min", lighting.exposure.luminance_min);
lighting.exposure.luminance_max = getfloatfield_default(L, -1, "luminance_max", lighting.exposure.luminance_max);
lighting.exposure.exposure_correction = getfloatfield_default(L, -1, "exposure_correction", lighting.exposure.exposure_correction);
lighting.exposure.speed_dark_bright = getfloatfield_default(L, -1, "speed_dark_bright", lighting.exposure.speed_dark_bright);
lighting.exposure.speed_bright_dark = getfloatfield_default(L, -1, "speed_bright_dark", lighting.exposure.speed_bright_dark);
lighting.exposure.center_weight_power = getfloatfield_default(L, -1, "center_weight_power", lighting.exposure.center_weight_power);
}
lua_pop(L, 1); // exposure
}
lua_pop(L, 1); // exposure
getServer(L)->setLighting(player, lighting);
return 0;