]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Give CSM access to use `core.colorize()` (#5113)
authorred-001 <red-001@outlook.ie>
Fri, 17 Mar 2017 18:20:13 +0000 (18:20 +0000)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 17 Mar 2017 18:20:13 +0000 (19:20 +0100)
builtin/common/misc_helpers.lua
builtin/game/misc.lua
clientmods/preview/init.lua
doc/client_lua_api.md

index 70b23600aab46423cd9dd97c1962246b25895ade..e145a5bfc2507b5b50744e382b1591131b28f010 100644 (file)
@@ -638,3 +638,35 @@ if INIT == "client" or INIT == "mainmenu" then
                return core.formspec_escape(fgettext_ne(text, ...))
        end
 end
+
+-- Client-sided mods don't have access to getbool
+if core.setting_getbool and core.setting_getbool("disable_escape_sequences") then
+
+       function core.get_color_escape_sequence(color)
+               return ""
+       end
+
+       function core.get_background_escape_sequence(color)
+               return ""
+       end
+
+       function core.colorize(color, message)
+               return message
+       end
+
+else
+
+       local ESCAPE_CHAR = string.char(0x1b)
+       function core.get_color_escape_sequence(color)
+               return ESCAPE_CHAR .. "(c@" .. color .. ")"
+       end
+
+       function core.get_background_escape_sequence(color)
+               return ESCAPE_CHAR .. "(b@" .. color .. ")"
+       end
+
+       function core.colorize(color, message)
+               return core.get_color_escape_sequence(color) .. message .. core.get_color_escape_sequence("#ffffff")
+       end
+
+end
index 25376c18046756b68d286f0fe4d587054a8c0d17..618d4d97ff4c1cc6b8b230fd37745576ad43a1a9 100644 (file)
@@ -170,37 +170,6 @@ function core.http_add_fetch(httpenv)
        return httpenv
 end
 
-if minetest.setting_getbool("disable_escape_sequences") then
-
-       function core.get_color_escape_sequence(color)
-               return ""
-       end
-
-       function core.get_background_escape_sequence(color)
-               return ""
-       end
-
-       function core.colorize(color, message)
-               return message
-       end
-
-else
-
-       local ESCAPE_CHAR = string.char(0x1b)
-       function core.get_color_escape_sequence(color)
-               return ESCAPE_CHAR .. "(c@" .. color .. ")"
-       end
-
-       function core.get_background_escape_sequence(color)
-               return ESCAPE_CHAR .. "(b@" .. color .. ")"
-       end
-
-       function core.colorize(color, message)
-               return core.get_color_escape_sequence(color) .. message .. core.get_color_escape_sequence("#ffffff")
-       end
-
-end
-
 function core.close_formspec(player_name, formname)
        return minetest.show_formspec(player_name, formname, "")
 end
index 25a61da51b723e71769be356bbfe45c9869c14b2..008f7ac148e0aea0e5c6f0fdfe3ce4ad263fe820 100644 (file)
@@ -40,6 +40,12 @@ core.register_chatcommand("dump", {
        end,
 })
 
+core.register_chatcommand("colorize_test", {
+       func = function(param)
+               return true, core.colorize("red", param)
+       end,
+})
+
 core.register_chatcommand("test_node", {
        func = function(param)
                core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
index 70716ee41e536a8a820549b8f75acc35ab5762cc..5fba66c69171e2cece3c93061dbcb45be959ec27 100644 (file)
@@ -787,12 +787,12 @@ Call these functions only at load time!
       extra arguments and return the result
 * `fgettext(string, ...)` : returns string
     * same as fgettext_ne(), but calls core.formspec_escape before returning result
-* `show_formspec(formname, formspec)` : returns true on success
-       * Shows a formspec to the player
 
 ### UI
 * `minetest.ui.minimap`
     * Reference to the minimap object. See `Minimap` class reference for methods.
+* `show_formspec(formname, formspec)` : returns true on success
+       * Shows a formspec to the player
 
 Class reference
 ---------------
@@ -837,3 +837,37 @@ Definition tables
         func = function(name, param), -- Called when command is run.
                                       -- Returns boolean success and text output.
     }
+
+Escape sequences
+----------------
+Most text can contain escape sequences, that can for example color the text.
+There are a few exceptions: tab headers, dropdowns and vertical labels can't.
+The following functions provide escape sequences:
+* `core.get_color_escape_sequence(color)`:
+    * `color` is a ColorString
+    * The escape sequence sets the text color to `color`
+* `core.colorize(color, message)`:
+    * Equivalent to:
+      `core.get_color_escape_sequence(color) ..
+       message ..
+       core.get_color_escape_sequence("#ffffff")`
+* `color.get_background_escape_sequence(color)`
+    * `color` is a ColorString
+    * The escape sequence sets the background of the whole text element to
+      `color`. Only defined for item descriptions and tooltips.
+         
+`ColorString`
+-------------
+`#RGB` defines a color in hexadecimal format.
+
+`#RGBA` defines a color in hexadecimal format and alpha channel.
+
+`#RRGGBB` defines a color in hexadecimal format.
+
+`#RRGGBBAA` defines a color in hexadecimal format and alpha channel.
+
+Named colors are also supported and are equivalent to
+[CSS Color Module Level 4](http://dev.w3.org/csswg/css-color/#named-colors).
+To specify the value of the alpha channel, append `#AA` to the end of the color name
+(e.g. `colorname#08`). For named colors the hexadecimal string representing the alpha
+value must (always) be two hexadecima
\ No newline at end of file