From bc53c82bcf923d11725e3de8565eb4c7e435cd2b Mon Sep 17 00:00:00 2001 From: Gael-de-Sailly Date: Fri, 27 Feb 2015 20:51:55 +0100 Subject: [PATCH] Add minetest.rgba function that returns ColorString from RGBA or RGB values --- builtin/common/misc_helpers.lua | 6 ++++++ doc/client_lua_api.md | 4 ++++ doc/lua_api.txt | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index f9b572d9f..776be29d8 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -511,6 +511,12 @@ function core.explode_scrollbar_event(evt) return retval end +-------------------------------------------------------------------------------- +function core.rgba(r, g, b, a) + return a and string.format("#%02X%02X%02X%02X", r, g, b, a) or + string.format("#%02X%02X%02X", r, g, b) +end + -------------------------------------------------------------------------------- function core.pos_to_string(pos, decimal_places) local x = pos.x diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md index 43b33ac97..3bd1e3567 100644 --- a/doc/client_lua_api.md +++ b/doc/client_lua_api.md @@ -794,6 +794,10 @@ Call these functions only at load time! * See documentation on `minetest.compress()` for supported compression methods. * currently supported. * `...` indicates method-specific arguments. Currently, no methods use this. +* `minetest.rgba(red, green, blue[, alpha])`: returns a string + * Each argument is a 8 Bit unsigned integer + * Returns the ColorString from rgb or rgba values + * Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"` * `minetest.encode_base64(string)`: returns string encoded in base64 * Encodes a string in base64. * `minetest.decode_base64(string)`: returns string diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 9bd92b34a..664ad960a 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -580,7 +580,7 @@ Example (colored grass block): description = "Dirt with Grass", -- Regular tiles, as usual -- The dirt tile disables palette coloring - tiles = {{name = "default_grass.png"}, + tiles = {{name = "default_grass.png"}, {name = "default_dirt.png", color = "white"}}, -- Overlay tiles: define them in the same style -- The top and bottom tile does not have overlay @@ -2958,6 +2958,10 @@ These functions return the leftover itemstack. * See documentation on `minetest.compress()` for supported compression methods. * currently supported. * `...` indicates method-specific arguments. Currently, no methods use this. +* `minetest.rgba(red, green, blue[, alpha])`: returns a string + * Each argument is a 8 Bit unsigned integer + * Returns the ColorString from rgb or rgba values + * Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"` * `minetest.encode_base64(string)`: returns string encoded in base64 * Encodes a string in base64. * `minetest.decode_base64(string)`: returns string -- 2.25.1