add 2 more patterns types (WIP)

This commit is contained in:
AFCMS 2021-03-09 00:57:13 +01:00
parent a22188ccf4
commit 0d3147b13d
4 changed files with 18 additions and 12 deletions

View File

@ -68,7 +68,5 @@ If not specified, a value will be by default with the word pattern.
* alphanumeric
* username: value must be a valid username
* json: value must be a json string (will be parsed automaticaly)
TODO:
* color value must be a color string or a valid named color
* nodename value must be a valid node name

View File

@ -22,7 +22,9 @@ mcl_commands.types = {
alphascore = "([A-Za-z_]+)",
alphanumeric = "([A-Za-z0-9]+)",
username = "([A-Za-z0-9-_]+)",
json = "(.+)",
json = "(.+)", --FIXME
color = "([^ ]+)", --FIXME
nodename = "([A-Za-z_]+)",
}
function mcl_commands.register_command(name, def)
@ -201,6 +203,16 @@ function mcl_commands.build(name, chat_def)
elseif param == "json" then
table.insert(params, parse_json(res[pointer]))
pointer = pointer + 1
elseif param == "color" then
table.insert(params, mcl_util.get_color(res[pointer]))
pointer = pointer + 1
elseif param == "nodename" then
if minetest.registered_nodes[res[pointer]] then
table.insert(params, res[pointer])
pointer = pointer + 1
else
return false, S("Param "..pointer.." must be a valid nodename!")
end
else
table.insert(params, res[pointer])
pointer = pointer + 1

View File

@ -1,6 +1,6 @@
name = mcl_commands
author = AFCMS
description = MCL2 commands API
depends = mcl_colors
depends = mcl_colors, mcl_util
optional_depends =

View File

@ -2,14 +2,10 @@ local S = minetest.get_translator("mcl_commands")
mcl_commands.register_command("setblock", {
func = function(cmd)
cmd:sub(":pos:pos :node:text", { --TODO:replace by upcomming nodename type
func = function(name)
local itemstack = ItemStack(nodestring)
if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then
return false, S("Invalid node") --workaround
end
minetest.set_node(p, {name=nodestring})
return true, S("@1 spawned.", nodestring)
cmd:sub(":pos:pos :node:nodename", {
func = function(name, pos, node)
minetest.set_node(pos, {name=node})
return true, S("@1 spawned.", node)
--return false, S("Invalid parameters (see /help setblock)")
end,
privs = {},