From 2d62ac5b4e39df4be10b37ff3a8633c56011a3f1 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 4 Nov 2016 02:08:30 +0100 Subject: [PATCH] Add support for settingtypes.txt --- README.md | 4 ++-- init.lua | 22 +++++++++++++++++----- settingtypes.txt | 5 +++++ 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 settingtypes.txt diff --git a/README.md b/README.md index f4fc0d6..9c55f44 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ This mod can be configured via `minetest.conf`. Currently, these settings are recognized: -* `central_message_max`: Limit the number of messages displayed at once, by providing a number. Use `inf` here for no limit. Default: 7 -* `central_message_color`: Set the message color of all messages. Value must be `ColorString` (see `lua_api.txt`). Default: `0xFFFFFF` (white) +* `central_message_max`: Limit the number of messages displayed at once, by providing a number. Use 0here for no limit. Default: 7 +* `central_message_color`: Set the message color of all messages. Value must be of format `(R,G,B)`. Default: `(255,255,255)` (white). ## API diff --git a/init.lua b/init.lua index b4482b8..ece6f24 100644 --- a/init.lua +++ b/init.lua @@ -7,15 +7,27 @@ cmsg.next_msgids = {} cmsg.settings.max_messages = 7 local setting = minetest.setting_get("central_message_max") if type(tonumber(setting)) == "number" then - cmsg.settings.max_messages = tonumber(setting) -elseif setting == "inf" then - cmsg.settings.max_messages = nil + if tonumber(setting) == 0 then + -- Infinite messages + cmsg.settings.max_messages = nil + else + cmsg.settings.max_messages = tonumber(setting) + end end cmsg.settings.color = 0xFFFFFF setting = minetest.setting_get("central_message_color") -if type(tonumber(setting)) == "number" then - cmsg.settings.color = tonumber(setting) +if setting then + local r, g, b = string.match(setting, "%((%d+),(%d+),(%d+)%)") + r = tonumber(r) + g = tonumber(g) + b = tonumber(b) + if type(r) == "number" and type(g) == "number" and type(b) == "number" and + r >= 0 and r <= 255 and g >= 0 and g <= 255 and b >= 0 and b <= 255 then + cmsg.settings.color = r * 0x10000 + g * 0x100 + b + else + minetest.log("error", "[central_message] Invalid syntax of central_message_color setting!") + end end local function update_display(player, pname) diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..f87e9f6 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,5 @@ +#Maximum number of messages displayed at once. Use 0 for no limit. +central_message_max (Maximum message count) int 7 0 + +#Message color of all messages (R,G,B). +central_message_color (Message color) string (255,255,255)