* `set_sky(sky_parameters)`
* The presence of the function `set_sun`, `set_moon` or `set_stars` indicates
whether `set_sky` accepts this format. Check the legacy format otherwise.
+ * Passing no arguments resets the sky to its default values.
* `sky_parameters` is a table with the following optional fields:
* `base_color`: ColorSpec, changes fog in "skybox" and "plain".
+ (default: `#ffffff`)
* `type`: Available types:
* `"regular"`: Uses 0 textures, `base_color` ignored
* `"skybox"`: Uses 6 textures, `base_color` used as fog.
* `"plain"`: Uses 0 textures, `base_color` used as both fog and sky.
+ (default: `"regular"`)
* `textures`: A table containing up to six textures in the following
order: Y+ (top), Y- (bottom), X- (west), X+ (east), Z+ (north), Z- (south).
* `clouds`: Boolean for whether clouds appear. (default: `true`)
* `indoors`: ColorSpec, for when you're either indoors or underground.
(default: `#646464`)
* `fog_sun_tint`: ColorSpec, changes the fog tinting for the sun
- at sunrise and sunset.
+ at sunrise and sunset. (default: `#f47d1d`)
* `fog_moon_tint`: ColorSpec, changes the fog tinting for the moon
- at sunrise and sunset.
+ at sunrise and sunset. (default: `#7f99cc`)
* `fog_tint_type`: string, changes which mode the directional fog
abides by, `"custom"` uses `sun_tint` and `moon_tint`, while
`"default"` uses the classic Minetest sun and moon tinting.
* `get_sky_color()`: returns a table with the `sky_color` parameters as in
`set_sky`.
* `set_sun(sun_parameters)`:
+ * Passing no arguments resets the sun to its default values.
* `sun_parameters` is a table with the following optional fields:
* `visible`: Boolean for whether the sun is visible.
(default: `true`)
* `get_sun()`: returns a table with the current sun parameters as in
`set_sun`.
* `set_moon(moon_parameters)`:
+ * Passing no arguments resets the moon to its default values.
* `moon_parameters` is a table with the following optional fields:
* `visible`: Boolean for whether the moon is visible.
(default: `true`)
* `get_moon()`: returns a table with the current moon parameters as in
`set_moon`.
* `set_stars(star_parameters)`:
+ * Passing no arguments resets stars to their default values.
* `star_parameters` is a table with the following optional fields:
* `visible`: Boolean for whether the stars are visible.
(default: `true`)
* `get_stars()`: returns a table with the current stars parameters as in
`set_stars`.
* `set_clouds(cloud_parameters)`: set cloud parameters
+ * Passing no arguments resets clouds to their default values.
* `cloud_parameters` is a table with the following optional fields:
* `density`: from `0` (no clouds) to `1` (full clouds) (default `0.4`)
* `color`: basic cloud color with alpha channel, ColorSpec
return 0;
SkyboxParams sky_params = player->getSkyParams();
- bool is_colorspec = is_color_table(L, 2);
- if (lua_istable(L, 2) && !is_colorspec) {
+ // reset if empty
+ if (lua_isnoneornil(L, 2) && lua_isnone(L, 3)) {
+ sky_params = SkyboxDefaults::getSkyDefaults();
+ } else if (lua_istable(L, 2) && !is_color_table(L, 2)) {
lua_getfield(L, 2, "base_color");
if (!lua_isnil(L, -1))
read_color(L, -1, &sky_params.bgcolor);
}
lua_pop(L, 1);
- /*
- We want to avoid crashes, so we're checking even if we're not using them.
- However, we want to ensure that the skybox can be set to nil when
- using "regular" or "plain" skybox modes as textures aren't needed.
- */
-
- if (sky_params.textures.size() != 6 && sky_params.textures.size() > 0)
+ // Validate that we either have six or zero textures
+ if (sky_params.textures.size() != 6 && !sky_params.textures.empty())
throw LuaError("Skybox expects 6 textures!");
- sky_params.clouds = getboolfield_default(L, 2,
- "clouds", sky_params.clouds);
+ sky_params.clouds = getboolfield_default(L, 2, "clouds", sky_params.clouds);
lua_getfield(L, 2, "sky_color");
if (lua_istable(L, -1)) {
sky_params.fog_tint_type = luaL_checkstring(L, -1);
lua_pop(L, 1);
- // Because we need to leave the "sky_color" table.
+ // pop "sky_color" table
lua_pop(L, 1);
}
} else {
if (lua_istable(L, 4)) {
lua_pushnil(L);
while (lua_next(L, 4) != 0) {
- // Key at index -2, and value at index -1
- if (lua_isstring(L, -1))
- sky_params.textures.emplace_back(readParam<std::string>(L, -1));
- else
- sky_params.textures.emplace_back("");
+ // Key at index -2, and value at index -1
+ sky_params.textures.emplace_back(readParam<std::string>(L, -1));
// Remove the value, keep the key for the next iteration
lua_pop(L, 1);
}
getServer(L)->setMoon(player, moon_params);
getServer(L)->setStars(player, star_params);
}
+
getServer(L)->setSky(player, sky_params);
lua_pushboolean(L, true);
return 1;
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
SunParams sun_params = player->getSunParams();
- sun_params.visible = getboolfield_default(L, 2,
- "visible", sun_params.visible);
- sun_params.texture = getstringfield_default(L, 2,
- "texture", sun_params.texture);
- sun_params.tonemap = getstringfield_default(L, 2,
- "tonemap", sun_params.tonemap);
- sun_params.sunrise = getstringfield_default(L, 2,
- "sunrise", sun_params.sunrise);
- sun_params.sunrise_visible = getboolfield_default(L, 2,
- "sunrise_visible", sun_params.sunrise_visible);
- sun_params.scale = getfloatfield_default(L, 2,
- "scale", sun_params.scale);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ sun_params = SkyboxDefaults::getSunDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ sun_params.visible = getboolfield_default(L, 2, "visible", sun_params.visible);
+ sun_params.texture = getstringfield_default(L, 2, "texture", sun_params.texture);
+ sun_params.tonemap = getstringfield_default(L, 2, "tonemap", sun_params.tonemap);
+ sun_params.sunrise = getstringfield_default(L, 2, "sunrise", sun_params.sunrise);
+ sun_params.sunrise_visible = getboolfield_default(L, 2, "sunrise_visible", sun_params.sunrise_visible);
+ sun_params.scale = getfloatfield_default(L, 2, "scale", sun_params.scale);
+ }
getServer(L)->setSun(player, sun_params);
lua_pushboolean(L, true);
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
MoonParams moon_params = player->getMoonParams();
- moon_params.visible = getboolfield_default(L, 2,
- "visible", moon_params.visible);
- moon_params.texture = getstringfield_default(L, 2,
- "texture", moon_params.texture);
- moon_params.tonemap = getstringfield_default(L, 2,
- "tonemap", moon_params.tonemap);
- moon_params.scale = getfloatfield_default(L, 2,
- "scale", moon_params.scale);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ moon_params = SkyboxDefaults::getMoonDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ moon_params.visible = getboolfield_default(L, 2, "visible", moon_params.visible);
+ moon_params.texture = getstringfield_default(L, 2, "texture", moon_params.texture);
+ moon_params.tonemap = getstringfield_default(L, 2, "tonemap", moon_params.tonemap);
+ moon_params.scale = getfloatfield_default(L, 2, "scale", moon_params.scale);
+ }
getServer(L)->setMoon(player, moon_params);
lua_pushboolean(L, true);
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
StarParams star_params = player->getStarParams();
- star_params.visible = getboolfield_default(L, 2,
- "visible", star_params.visible);
- star_params.count = getintfield_default(L, 2,
- "count", star_params.count);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ star_params = SkyboxDefaults::getStarDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ star_params.visible = getboolfield_default(L, 2, "visible", star_params.visible);
+ star_params.count = getintfield_default(L, 2, "count", star_params.count);
- lua_getfield(L, 2, "star_color");
- if (!lua_isnil(L, -1))
- read_color(L, -1, &star_params.starcolor);
- lua_pop(L, 1);
+ lua_getfield(L, 2, "star_color");
+ if (!lua_isnil(L, -1))
+ read_color(L, -1, &star_params.starcolor);
+ lua_pop(L, 1);
- star_params.scale = getfloatfield_default(L, 2,
- "scale", star_params.scale);
+ star_params.scale = getfloatfield_default(L, 2,
+ "scale", star_params.scale);
+ }
getServer(L)->setStars(player, star_params);
lua_pushboolean(L, true);
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
CloudParams cloud_params = player->getCloudParams();
- cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ cloud_params = SkyboxDefaults::getCloudDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
- lua_getfield(L, 2, "color");
- if (!lua_isnil(L, -1))
- read_color(L, -1, &cloud_params.color_bright);
- lua_pop(L, 1);
- lua_getfield(L, 2, "ambient");
- if (!lua_isnil(L, -1))
- read_color(L, -1, &cloud_params.color_ambient);
- lua_pop(L, 1);
+ lua_getfield(L, 2, "color");
+ if (!lua_isnil(L, -1))
+ read_color(L, -1, &cloud_params.color_bright);
+ lua_pop(L, 1);
+ lua_getfield(L, 2, "ambient");
+ if (!lua_isnil(L, -1))
+ read_color(L, -1, &cloud_params.color_ambient);
+ lua_pop(L, 1);
- cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height );
- cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness);
+ cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height);
+ cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness);
- lua_getfield(L, 2, "speed");
- if (lua_istable(L, -1)) {
- v2f new_speed;
- new_speed.X = getfloatfield_default(L, -1, "x", 0);
- new_speed.Y = getfloatfield_default(L, -1, "z", 0);
- cloud_params.speed = new_speed;
+ lua_getfield(L, 2, "speed");
+ if (lua_istable(L, -1)) {
+ v2f new_speed;
+ new_speed.X = getfloatfield_default(L, -1, "x", 0);
+ new_speed.Y = getfloatfield_default(L, -1, "z", 0);
+ cloud_params.speed = new_speed;
+ }
+ lua_pop(L, 1);
}
- lua_pop(L, 1);
getServer(L)->setClouds(player, cloud_params);
lua_pushboolean(L, true);