Add time_to_day_night_ratio to the Lua API

This commit is contained in:
Gregor Parzefall 2024-09-13 13:14:31 +02:00 committed by sfan5
parent f9c0354af1
commit 7bab390413
3 changed files with 22 additions and 0 deletions

View File

@ -5659,6 +5659,9 @@ Utilities
form. If the ColorSpec is invalid, returns `nil`. You can use this to parse
ColorStrings.
* `colorspec`: The ColorSpec to convert
* `minetest.time_to_day_night_ratio(time_of_day)`: Returns a "day-night ratio" value
(as accepted by `ObjectRef:override_day_night_ratio`) that is equivalent to
the given "time of day" value (as returned by `minetest.get_timeofday`).
* `minetest.encode_png(width, height, data, [compression])`: Encode a PNG
image and return it in string form.
* `width`: Width of the image
@ -8519,6 +8522,7 @@ child will follow movement and rotation of that bone.
* `0`...`1`: Overrides day-night ratio, controlling sunlight to a specific
amount.
* Passing no arguments disables override, defaulting to sunlight based on day-night cycle
* See also `minetest.time_to_day_night_ratio`,
* `get_day_night_ratio()`: returns the ratio or nil if it isn't overridden
* `set_local_animation(idle, walk, dig, walk_while_dig, frame_speed)`:
set animation for player model in third person view.

View File

@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "my_sha256.h"
#include "util/png.h"
#include "player.h"
#include "daynightratio.h"
#include <cstdio>
// only available in zstd 1.3.5+
@ -640,6 +641,17 @@ int ModApiUtil::l_colorspec_to_table(lua_State *L)
return 0;
}
// time_to_day_night_ratio(time_of_day)
int ModApiUtil::l_time_to_day_night_ratio(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
float time_of_day = lua_tonumber(L, 1) * 24000;
u32 dnr = time_to_daynight_ratio(time_of_day, true);
lua_pushnumber(L, dnr / 1000.0f);
return 1;
}
// encode_png(w, h, data, level)
int ModApiUtil::l_encode_png(lua_State *L)
{
@ -741,6 +753,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(colorspec_to_colorstring);
API_FCT(colorspec_to_bytes);
API_FCT(colorspec_to_table);
API_FCT(time_to_day_night_ratio);
API_FCT(encode_png);
@ -777,6 +790,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
API_FCT(colorspec_to_colorstring);
API_FCT(colorspec_to_bytes);
API_FCT(colorspec_to_table);
API_FCT(time_to_day_night_ratio);
API_FCT(get_last_run_mod);
API_FCT(set_last_run_mod);
@ -822,6 +836,7 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
API_FCT(colorspec_to_colorstring);
API_FCT(colorspec_to_bytes);
API_FCT(colorspec_to_table);
API_FCT(time_to_day_night_ratio);
API_FCT(encode_png);

View File

@ -125,6 +125,9 @@ private:
// colorspec_to_table(colorspec)
static int l_colorspec_to_table(lua_State *L);
// time_to_day_night_ratio(time_of_day)
static int l_time_to_day_night_ratio(lua_State *L);
// encode_png(w, h, data, level)
static int l_encode_png(lua_State *L);