mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Allow get_sky to return a table (#11963)
This commit is contained in:
parent
f2d1295fe6
commit
44fc888bd6
4 changed files with 90 additions and 47 deletions
|
@ -1874,32 +1874,35 @@ int ObjectRef::l_set_sky(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// get_sky(self)
|
||||
int ObjectRef::l_get_sky(lua_State *L)
|
||||
static void push_sky_color(lua_State *L, const SkyboxParams ¶ms)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
ObjectRef *ref = checkobject(L, 1);
|
||||
RemotePlayer *player = getplayer(ref);
|
||||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
SkyboxParams skybox_params = player->getSkyParams();
|
||||
|
||||
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++);
|
||||
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");
|
||||
}
|
||||
lua_pushboolean(L, skybox_params.clouds);
|
||||
return 4;
|
||||
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_color(self)
|
||||
int ObjectRef::l_get_sky_color(lua_State *L)
|
||||
// get_sky(self, as_table)
|
||||
int ObjectRef::l_get_sky(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
ObjectRef *ref = checkobject(L, 1);
|
||||
|
@ -1909,29 +1912,59 @@ int ObjectRef::l_get_sky_color(lua_State *L)
|
|||
|
||||
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");
|
||||
// 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;
|
||||
}
|
||||
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");
|
||||
|
||||
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;
|
||||
for (const std::string &texture : skybox_params.textures) {
|
||||
lua_pushlstring(L, texture.c_str(), texture.size());
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
lua_setfield(L, -2, "textures");
|
||||
lua_pushboolean(L, skybox_params.clouds);
|
||||
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();
|
||||
push_sky_color(L, skybox_params);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue