mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 23:42:59 +00:00
Update notify.lua
This commit is contained in:
parent
a9307d3725
commit
e0f6d9d9ce
1 changed files with 12 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
--- A player notification system for worldeditadditions.
|
--- A player notification system for worldeditadditions.
|
||||||
|
local wea_c = worldeditadditions_core
|
||||||
|
|
||||||
-- Helper functions
|
-- Helper functions
|
||||||
local set_colour = function(colour, text)
|
local set_colour = function(colour, text)
|
||||||
|
@ -12,8 +13,8 @@ local globalstate = {
|
||||||
on_error_send_all = false,
|
on_error_send_all = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
local validate = dofile(worldeditadditions_core.modpath ..
|
local validate = dofile(wea_c.modpath .. "/utils/notify/validate.lua")
|
||||||
"/utils/notify/validate.lua")
|
local split = dofile(wea_c.modpath .. "/utils/strings/split.lua")
|
||||||
|
|
||||||
|
|
||||||
-- @class worldeditadditions_core.notify
|
-- @class worldeditadditions_core.notify
|
||||||
|
@ -25,23 +26,25 @@ local send = function(name, ntype, message, colour, message_coloured)
|
||||||
local sucess, details = validate.all(name, message, colour)
|
local sucess, details = validate.all(name, message, colour)
|
||||||
-- Report errors if any
|
-- Report errors if any
|
||||||
if not sucess then
|
if not sucess then
|
||||||
if not details.name then
|
if details.name_err then
|
||||||
-- Send error to all players or log it
|
-- Send error to all players or log it
|
||||||
if globalstate.on_error_send_all then
|
if globalstate.on_error_send_all then
|
||||||
minetest.chat_send_all(details.name_err)
|
minetest.chat_send_all(details.name_err)
|
||||||
else minetest.log("error", details.name_err) end
|
else minetest.log("error", details.name_err) end
|
||||||
elseif not details.message then
|
elseif not details.message then
|
||||||
Notify.error(name, "Invalid message: " .. tostring(message) ..
|
Notify.error(name, "Invalid message: " .. tostring(message) ..
|
||||||
" is not a string. " .. debug.traceback())
|
" is not a string.\n" .. debug.traceback())
|
||||||
elseif not details.colour then
|
elseif not details.colour then
|
||||||
Notify.error(name, "Invalid colour: " .. tostring(colour) .. ".\n" ..
|
Notify.error(name, "Invalid colour: " .. tostring(colour) ..
|
||||||
"Message: " .. message .. "\n" .. debug.traceback())
|
"\nMessage: " .. message .. "\n" .. debug.traceback())
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
-- Colour the message if applicable
|
-- Colour the message if applicable
|
||||||
if message_coloured then
|
if message_coloured then
|
||||||
message = set_colour(colour, message)
|
local msg = split(message, "\n")
|
||||||
|
msg[1] = set_colour(colour, msg[1])
|
||||||
|
message = table.concat(msg, "\n")
|
||||||
end
|
end
|
||||||
-- Create the notification
|
-- Create the notification
|
||||||
local ret = table.concat({
|
local ret = table.concat({
|
||||||
|
@ -83,7 +86,9 @@ end
|
||||||
--- Register predefined notification types.
|
--- Register predefined notification types.
|
||||||
-- @usage
|
-- @usage
|
||||||
-- Notify.error(name, message)
|
-- Notify.error(name, message)
|
||||||
|
-- Notify.errinfo(name, message) -- For verbose errors and stack traces
|
||||||
-- Notify.warn(name, message)
|
-- Notify.warn(name, message)
|
||||||
|
-- Notify.wrninfo(name, message) -- For verbose warnings and stack traces
|
||||||
-- Notify.ok(name, message)
|
-- Notify.ok(name, message)
|
||||||
-- Notify.info(name, message)
|
-- Notify.info(name, message)
|
||||||
do
|
do
|
||||||
|
|
Loading…
Reference in a new issue