aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOch Noe <och_noe@forksworld.de>2020-05-10 10:10:27 +0200
committerOch Noe <och_noe@forksworld.de>2020-05-10 10:10:27 +0200
commit6bc407c12e5a7aecd106d5768563b0a3fb8e5254 (patch)
tree1f08545958fddfc89e40f2a202e8dd166e3ae4ee
parent67a8908d9f41894abb30b57a837a0d22a71a6ff0 (diff)
downloadcolour_chat-6bc407c12e5a7aecd106d5768563b0a3fb8e5254.tar.gz
colour_chat-6bc407c12e5a7aecd106d5768563b0a3fb8e5254.tar.bz2
colour_chat-6bc407c12e5a7aecd106d5768563b0a3fb8e5254.zip
missing changes
-rw-r--r--README.md27
-rw-r--r--init.lua152
2 files changed, 136 insertions, 43 deletions
diff --git a/README.md b/README.md
index a937710..0fd2e74 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,27 @@
A minetest CSM mod for changing the colour of text sent to the server.
### Usage
-Use .set_colour to set the colour of chat sent to the server, you can
-use either HTML named colours or HTML hexdecimal colour codes. Use
-.rainbow to generate rainbow text
+Use
+.set_colour
+ to set the colour of chat sent to the server, you can
+ use either HTML named colours or HTML hexdecimal colour
+ codes.
+.rainbow
+ generate rainbow text
+
+.pastel
+ for a pastel coloured rainbow
+
+.get_colour
+ to see the current colour
+
+.mi / .mw
+ Moderator Info / Warning
+ (depends on /mi and /mw server commands)
+
+.fade col1 col2 text
+ fades a text from col1 to col2
+
+
+Original mod by red-001, additions (pastel and others) by dhausmig
+Currently maintained by Och_Noe
diff --git a/init.lua b/init.lua
index e55419d..0d9d6a4 100644
--- a/init.lua
+++ b/init.lua
@@ -1,10 +1,44 @@
local modstorage = core.get_mod_storage()
+local modpath = minetest.get_modpath("colour_chat")
+
+dofile(modpath .. "/colournames.lua")
+
local register_on_message = core.register_on_sending_chat_message
if core.register_on_sending_chat_messages then
register_on_message = core.register_on_sending_chat_messages
end
+local function safe(func)
+ -- wrap a function w/ logic to avoid crashing the game
+ local f = function(...)
+ local status, out = pcall(func, ...)
+ if status then
+ return out
+ else
+ log('warning', 'Error (func): ' .. out)
+ return nil
+ end
+ end
+ return f
+end
+
+local function paramsplit(str)
+ -- minetest.display_chat_message("paramsplit 1")
+ local s = str:gsub("^%s*(.-)%s*$", "%1")
+ local p1 = string.find(s," ",1,true)
+ if not p1 then return nil end
+ -- minetest.display_chat_message("paramsplit 2")
+ local p2 = string.find(s," ",p1+1,true)
+ local s1 = str:sub(1,p1-1)
+ if not p2 then return {s1,s1,str:sub(p1+1,512)}
+ end
+ -- minetest.display_chat_message("paramsplit 3")
+ local s2 = str:sub(p1+1,p2-1)
+ local s3 = str:sub(p2+1,512)
+ return {s1,s2,s3}
+end
+
local function rgb_to_hex(rgb)
local hexadecimal = '#'
@@ -79,6 +113,8 @@ function hex2rgb(hex) -- added - found on github
end
local function color_step(pos, col1, col2) -- added - gets a color between colors
+ -- if not col1 then col1 = "#888888" end
+ -- if not col2 then col2 = "#888888" end
local rgb1 = hex2rgb(col1)
local rgb2 = hex2rgb(col2)
local rgb = {}
@@ -109,30 +145,50 @@ local function say(message)
end
function fade(parameter)
- local col1 = string.sub(parameter, 1, 7)
- local col2 = string.sub(parameter, 9, 15)
- local message = string.sub(parameter, 17)
- if not canTalk() then
- return false, "You need 'shout' in order to use this command"
- end
- if col1 == col2 then
- say(core.get_color_escape_sequence(col1) .. message)
- return true
- end
- local step = 255 / message:len()
- local pos = 0
- local output = ""
- for i = 1, message:len() do
- local char = message:sub(i,i)
- if char:match("%s") then
- output = output .. char
- else
- output = output .. core.get_color_escape_sequence(color_step(pos, col1, col2)) .. char
- end
- pos = pos + step
- end
- say(output)
- return true
+ local p = paramsplit(parameter)
+ if not p then return end
+ -- local col1 = string.sub(parameter, 1, 7)
+ -- local col2 = string.sub(parameter, 9, 15)
+ -- local message = string.sub(parameter, 17)
+
+ local col1 = colourname2hex(p[1])
+ -- minetest.display_chat_message("col1.a: "..col1)
+ -- minetest.display_chat_message("col1.b: "..core.get_color_escape_sequence(col1):sub(2,-1))
+ -- minetest.display_chat_message("col1.c: "..minetest.colorize(col1):sub(2,-1))
+ local col2 = colourname2hex(p[2])
+ -- minetest.display_chat_message("col2.a: "..p[2])
+ -- minetest.display_chat_message("col2.b: "..col2)
+ local message = p[3]
+ -- minetest.display_chat_message("msg: "..message)
+
+ -- if true then return end
+
+ if not canTalk() then
+ return false, "You need 'shout' in order to use this command"
+ end
+ if col1 == col2 then
+ -- minetest.display_chat_message("col1=col2")
+ say(minetest.get_color_escape_sequence(col1) .. message)
+ -- minetest.display_chat_message("col1=col2 b")
+ return true
+ end
+
+ -- minetest.display_chat_message("pos4")
+
+ local step = 255 / (message:len()/2)
+ local pos = 0
+ local output = ""
+ for i = 1, message:len() do
+ local char = message:sub(i,i)
+ if char:match("%s") then
+ output = output .. char
+ else
+ output = output .. minetest.get_color_escape_sequence(color_step(pos, col1, col2)) .. char
+ end
+ pos = pos + step
+ end
+ say(output)
+ return true
end
register_on_message(function(message)
@@ -147,12 +203,26 @@ end)
core.register_chatcommand("set_colour", {
description = core.gettext("Change chat colour"),
func = function(colour)
- if colour:len() == 7 then
- modstorage:set_string("colour", colour.." "..colour)
- else
- modstorage:set_string("colour", colour)
+ local c = paramsplit(colour)
+ if not c then
+ local c1 = colourname2hex(colour)
+ if c1 and c1 ~= "" then
+ modstorage:set_string("colour", colour.." "..colour)
+ return true, "Chat colour changed."
+ else
+ return true,"'"..colour.."' is not a colour"
+ end
+ end
+ c1 = colourname2hex(c[1])
+ c2 = colourname2hex(c[3])
+ if not c1 or c1 == "" then
+ return true,"'"..c[1].."' is not a colour"
end
- return true, "Chat colour changed."
+ if not c2 or c2 == "" then
+ return true,"'"..c[2].."' is not a colour"
+ end
+ modstorage:set_string("colour", c1.." "..c2)
+ return true, "Chat colours changed."
end,
})
@@ -190,9 +260,9 @@ end,
})
core.register_chatcommand("fade", { -- added - fades between any two colors
- description = core.gettext("fade message between two colors"),
- func = fade,
-})
+ description = core.gettext("fade message between two colors"),
+ func = fade,
+ })
core.register_chatcommand("pastel", {
description = core.gettext("pastel rainbow text"),
@@ -224,10 +294,11 @@ core.register_chatcommand("mw", {
if not canTalk() then
return false, "You need 'shout' in order to use this comand"
end
- local output = ""
- output = core.get_color_escape_sequence("#ffdf00") .. "MODERATOR WARNING: "
- output = output .. core.get_color_escape_sequence("#ff7fff") ..param
- say(output)
+ minetest.run_server_chatcommand('mw', param)
+ -- local output = ""
+ -- output = core.get_color_escape_sequence("#ffdf00") .. "MODERATOR WARNING: "
+ -- output = output .. core.get_color_escape_sequence("#ff7fff") ..param
+ -- say(output)
return true
end,
})
@@ -239,10 +310,11 @@ core.register_chatcommand("mi", {
if not canTalk() then
return false, "You need 'shout' in order to use this command"
end
- local output = ""
- output = core.get_color_escape_sequence("#d0ff00") .. "MODERATOR INFO: "
- output = output .. core.get_color_escape_sequence("#dfdfff") .. param
- say(output)
+ minetest.run_server_chatcommand('mi', param)
+ -- local output = ""
+ -- output = core.get_color_escape_sequence("#d0ff00") .. "MODERATOR INFO: "
+ -- output = output .. core.get_color_escape_sequence("#dfdfff") .. param
+ -- say(output)
return true
end,
})