]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Allow get_sky to return a table (#11963)
authorZughy <63455151+Zughy@users.noreply.github.com>
Sat, 5 Mar 2022 21:15:41 +0000 (22:15 +0100)
committerGitHub <noreply@github.com>
Sat, 5 Mar 2022 21:15:41 +0000 (22:15 +0100)
builtin/game/features.lua
doc/lua_api.txt
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h

index 583ef50926baa70a5b9c935dd4edda32b676181f..0d55bb01f80bcce9b6e0db3675179069bcfe110e 100644 (file)
@@ -22,6 +22,7 @@ core.features = {
        degrotate_240_steps = true,
        abm_min_max_y = true,
        dynamic_add_media_table = true,
+       get_sky_as_table = true,
 }
 
 function core.has_feature(arg)
index 571ddf40e8703b2386f8c58aa19d104fe22599d8..8af261e0c9d5d8e99af1aa7a09857a69aab7f45c 100644 (file)
@@ -4634,6 +4634,8 @@ Utilities
           abm_min_max_y = true,
           -- dynamic_add_media supports passing a table with options (5.5.0)
           dynamic_add_media_table = true,
+          -- allows get_sky to return a table instead of separate values (5.6.0)
+          get_sky_as_table = true,
       }
 
 * `minetest.has_feature(arg)`: returns `boolean, missing_features`
@@ -6869,9 +6871,15 @@ object you are working with still exists.
         * `"plain"`: Uses 0 textures, `bgcolor` used
     * `clouds`: Boolean for whether clouds appear in front of `"skybox"` or
       `"plain"` custom skyboxes (default: `true`)
-* `get_sky()`: returns base_color, type, table of textures, clouds.
-* `get_sky_color()`: returns a table with the `sky_color` parameters as in
-    `set_sky`.
+* `get_sky(as_table)`:
+    * `as_table`: boolean that determines whether the deprecated version of this
+    function is being used.
+        * `true` returns a table containing sky parameters as defined in `set_sky(sky_parameters)`.
+        * Deprecated: `false` or `nil` returns base_color, type, table of textures,
+        clouds.
+* `get_sky_color()`:
+    * Deprecated: Use `get_sky(as_table)` instead.
+    * 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:
index 407b48db0c251b6c56d25e79a02115ede4bb8b93..ba86fbc488d09a324c1931c4ea8ca0e9aaf34b58 100644 (file)
@@ -1874,7 +1874,34 @@ int ObjectRef::l_set_sky(lua_State *L)
        return 1;
 }
 
-// get_sky(self)
+static void push_sky_color(lua_State *L, const SkyboxParams &params)
+{
+       lua_newtable(L);
+       if (params.type == "regular") {
+               push_ARGB8(L, params.sky_color.day_sky);
+               lua_setfield(L, -2, "day_sky");
+               push_ARGB8(L, params.sky_color.day_horizon);
+               lua_setfield(L, -2, "day_horizon");
+               push_ARGB8(L, params.sky_color.dawn_sky);
+               lua_setfield(L, -2, "dawn_sky");
+               push_ARGB8(L, params.sky_color.dawn_horizon);
+               lua_setfield(L, -2, "dawn_horizon");
+               push_ARGB8(L, params.sky_color.night_sky);
+               lua_setfield(L, -2, "night_sky");
+               push_ARGB8(L, params.sky_color.night_horizon);
+               lua_setfield(L, -2, "night_horizon");
+               push_ARGB8(L, params.sky_color.indoors);
+               lua_setfield(L, -2, "indoors");
+       }
+       push_ARGB8(L, params.fog_sun_tint);
+       lua_setfield(L, -2, "fog_sun_tint");
+       push_ARGB8(L, params.fog_moon_tint);
+       lua_setfield(L, -2, "fog_moon_tint");
+       lua_pushstring(L, params.fog_tint_type.c_str());
+       lua_setfield(L, -2, "fog_tint_type");
+}
+
+// get_sky(self, as_table)
 int ObjectRef::l_get_sky(lua_State *L)
 {
        NO_MAP_LOCK_REQUIRED;
@@ -1883,10 +1910,30 @@ int ObjectRef::l_get_sky(lua_State *L)
        if (player == nullptr)
                return 0;
 
-       SkyboxParams skybox_params = player->getSkyParams();
+       const SkyboxParams &skybox_params = player->getSkyParams();
+
+       // handle the deprecated version
+       if (!readParam<bool>(L, 2, false)) {
+               log_deprecated(L, "Deprecated call to get_sky, please check lua_api.txt");
+
+               push_ARGB8(L, skybox_params.bgcolor);
+               lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
+
+               lua_newtable(L);
+               s16 i = 1;
+               for (const std::string &texture : skybox_params.textures) {
+                       lua_pushlstring(L, texture.c_str(), texture.size());
+                       lua_rawseti(L, -2, i++);
+               }
+               lua_pushboolean(L, skybox_params.clouds);
+               return 4;
+       }
 
+       lua_newtable(L);
        push_ARGB8(L, skybox_params.bgcolor);
+       lua_setfield(L, -2, "base_color");
        lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
+       lua_setfield(L, -2, "type");
 
        lua_newtable(L);
        s16 i = 1;
@@ -1894,44 +1941,30 @@ int ObjectRef::l_get_sky(lua_State *L)
                lua_pushlstring(L, texture.c_str(), texture.size());
                lua_rawseti(L, -2, i++);
        }
+       lua_setfield(L, -2, "textures");
        lua_pushboolean(L, skybox_params.clouds);
-       return 4;
+       lua_setfield(L, -2, "clouds");
+
+       push_sky_color(L, skybox_params);
+       lua_setfield(L, -2, "sky_color");
+       return 1;
 }
 
+// DEPRECATED
 // get_sky_color(self)
 int ObjectRef::l_get_sky_color(lua_State *L)
 {
        NO_MAP_LOCK_REQUIRED;
+
+       log_deprecated(L, "Deprecated call to get_sky_color, use get_sky instead");
+
        ObjectRef *ref = checkobject(L, 1);
        RemotePlayer *player = getplayer(ref);
        if (player == nullptr)
                return 0;
 
        const SkyboxParams &skybox_params = player->getSkyParams();
-
-       lua_newtable(L);
-       if (skybox_params.type == "regular") {
-               push_ARGB8(L, skybox_params.sky_color.day_sky);
-               lua_setfield(L, -2, "day_sky");
-               push_ARGB8(L, skybox_params.sky_color.day_horizon);
-               lua_setfield(L, -2, "day_horizon");
-               push_ARGB8(L, skybox_params.sky_color.dawn_sky);
-               lua_setfield(L, -2, "dawn_sky");
-               push_ARGB8(L, skybox_params.sky_color.dawn_horizon);
-               lua_setfield(L, -2, "dawn_horizon");
-               push_ARGB8(L, skybox_params.sky_color.night_sky);
-               lua_setfield(L, -2, "night_sky");
-               push_ARGB8(L, skybox_params.sky_color.night_horizon);
-               lua_setfield(L, -2, "night_horizon");
-               push_ARGB8(L, skybox_params.sky_color.indoors);
-               lua_setfield(L, -2, "indoors");
-       }
-       push_ARGB8(L, skybox_params.fog_sun_tint);
-       lua_setfield(L, -2, "fog_sun_tint");
-       push_ARGB8(L, skybox_params.fog_moon_tint);
-       lua_setfield(L, -2, "fog_moon_tint");
-       lua_pushstring(L, skybox_params.fog_tint_type.c_str());
-       lua_setfield(L, -2, "fog_tint_type");
+       push_sky_color(L, skybox_params);
        return 1;
 }
 
index db3a3a7cfe7c36d0f17bf0ff04be4b0d99ca89bb..084d40c05923aa83d94887bfe88ed5549730e6e6 100644 (file)
@@ -316,9 +316,10 @@ class ObjectRef : public ModApiBase {
        // set_sky(self, sky_parameters)
        static int l_set_sky(lua_State *L);
 
-       // get_sky(self)
+       // get_sky(self, as_table)
        static int l_get_sky(lua_State *L);
 
+       // DEPRECATED
        // get_sky_color(self)
        static int l_get_sky_color(lua_State* L);