mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-10-15 23:25:39 +02:00
Minor maintenance changes
This commit is contained in:
@@ -238,7 +238,7 @@ worldedit.register_command("cubeapply", {
|
||||
local cmddef = worldedit.registered_commands[cmd]
|
||||
if cmddef == nil or cmddef.require_pos ~= 2 then
|
||||
return false, S("invalid usage: @1 cannot be used with cubeapply",
|
||||
minetest.colorize("#00ffff", "//"..cmd))
|
||||
minetest.colorize("#0ff", "//"..cmd))
|
||||
end
|
||||
-- run parsing of target command
|
||||
local parsed = {cmddef.parse(args)}
|
||||
|
@@ -25,6 +25,15 @@ local function copy_state(which, name)
|
||||
end
|
||||
end
|
||||
|
||||
local function compare_state(state, old_state)
|
||||
for i, v in ipairs(state) do
|
||||
if not (v == nil and old_state[i] == nil) and not vector.equals(v, old_state[i]) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function chatcommand_handler(cmd_name, name, param)
|
||||
local def = assert(worldedit.registered_commands[cmd_name])
|
||||
|
||||
@@ -66,11 +75,7 @@ local function chatcommand_handler(cmd_name, name, param)
|
||||
local old_state = copy_state(def.require_pos, name)
|
||||
safe_region(name, count, function()
|
||||
local state = copy_state(def.require_pos, name)
|
||||
local ok = true
|
||||
for i, v in ipairs(state) do
|
||||
ok = ok and ( (v == nil and old_state[i] == nil) or vector.equals(v, old_state[i]) )
|
||||
end
|
||||
if not ok then
|
||||
if not compare_state(state, old_state) then
|
||||
worldedit.player_notify(name, S("ERROR: the operation was cancelled because the region has changed."), "error")
|
||||
return
|
||||
end
|
||||
@@ -111,6 +116,7 @@ function worldedit.register_command(name, def)
|
||||
def.require_pos = def.require_pos or 0
|
||||
assert(def.require_pos >= 0 and def.require_pos < 3)
|
||||
if def.params == "" and not def.parse then
|
||||
-- FIXME: shouldn't this check for param to be empty?
|
||||
def.parse = function(param) return true end
|
||||
else
|
||||
assert(def.parse)
|
||||
@@ -124,7 +130,7 @@ function worldedit.register_command(name, def)
|
||||
end--]]
|
||||
|
||||
-- disable further modification
|
||||
setmetatable(def, {__newindex = {}})
|
||||
setmetatable(def, {__newindex = function() end})
|
||||
|
||||
minetest.register_chatcommand("/" .. name, {
|
||||
privs = def.privs,
|
||||
@@ -172,7 +178,9 @@ function worldedit.player_notify(name, message, typ)
|
||||
minetest.chat_send_player(name, table.concat(t, " "))
|
||||
end
|
||||
|
||||
-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
|
||||
-- Determines the axis in which a player is facing
|
||||
-- @return axis ("x", "y", or "z") and the sign (1 or -1)
|
||||
-- @note Not part of API
|
||||
function worldedit.player_axis(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
@@ -200,7 +208,7 @@ worldedit.register_command("about", {
|
||||
worldedit.player_notify(name, S("WorldEdit @1"..
|
||||
" is available on this server. Type @2 to get a list of "..
|
||||
"commands, or find more information at @3",
|
||||
worldedit.version_string, minetest.colorize("#00ffff", "//help"),
|
||||
worldedit.version_string, minetest.colorize("#0ff", "//help"),
|
||||
"https://github.com/Uberi/Minetest-WorldEdit"
|
||||
), "info")
|
||||
end,
|
||||
@@ -209,10 +217,10 @@ worldedit.register_command("about", {
|
||||
-- initially copied from builtin/chatcommands.lua
|
||||
local function help_command(name, param)
|
||||
local function format_help_line(cmd, def, follow_alias)
|
||||
local msg = minetest.colorize("#00ffff", "//"..cmd)
|
||||
local msg = minetest.colorize("#0ff", "//"..cmd)
|
||||
if def.name ~= cmd then
|
||||
msg = msg .. ": " .. S("alias to @1",
|
||||
minetest.colorize("#00ffff", "//"..def.name))
|
||||
minetest.colorize("#0ff", "//"..def.name))
|
||||
if follow_alias then
|
||||
msg = msg .. "\n" .. format_help_line(def.name, def)
|
||||
end
|
||||
@@ -255,7 +263,7 @@ local function help_command(name, param)
|
||||
end
|
||||
end
|
||||
table.sort(list)
|
||||
local help = minetest.colorize("#00ffff", "//help")
|
||||
local help = minetest.colorize("#0ff", "//help")
|
||||
return true, S("Available commands: @1@n"
|
||||
.. "Use '@2' to get more information,"
|
||||
.. " or '@3' to list everything.",
|
||||
|
@@ -1,6 +1,4 @@
|
||||
-- Strips any kind of escape codes (translation, colors) from a string
|
||||
-- https://github.com/minetest/minetest/blob/53dd7819277c53954d1298dfffa5287c306db8d0/src/util/string.cpp#L777
|
||||
local function strip_escapes(input)
|
||||
local strip_escapes = minetest.strip_escapes or function(input)
|
||||
local s = function(idx) return input:sub(idx, idx) end
|
||||
local out = ""
|
||||
local i = 1
|
||||
@@ -22,12 +20,14 @@ local function strip_escapes(input)
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
--print(("%q -> %q"):format(input, out))
|
||||
return out
|
||||
end
|
||||
|
||||
local function string_endswith(full, part)
|
||||
return full:find(part, 1, true) == #full - #part + 1
|
||||
if #full < #part then
|
||||
return false
|
||||
end
|
||||
return full:sub(-#part) == part
|
||||
end
|
||||
|
||||
local description_cache = nil
|
||||
@@ -35,7 +35,9 @@ local description_cache = nil
|
||||
-- normalizes node "description" `nodename`, returning a string (or nil)
|
||||
worldedit.normalize_nodename = function(nodename)
|
||||
nodename = nodename:gsub("^%s*(.-)%s*$", "%1") -- strip spaces
|
||||
if nodename == "" then return nil end
|
||||
if nodename == "" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local fullname = ItemStack({name=nodename}):get_name() -- resolve aliases
|
||||
if minetest.registered_nodes[fullname] or fullname == "air" then -- full name
|
||||
@@ -51,9 +53,12 @@ worldedit.normalize_nodename = function(nodename)
|
||||
|
||||
if description_cache == nil then
|
||||
-- cache stripped descriptions
|
||||
-- Note: since we don't handle translations this will work only in the original
|
||||
-- language of the description (English)
|
||||
description_cache = {}
|
||||
for key, value in pairs(minetest.registered_nodes) do
|
||||
local desc = strip_escapes(value.description):gsub("\n.*", "", 1):lower()
|
||||
for key, def in pairs(minetest.registered_nodes) do
|
||||
local desc = def.short_description or (def.description or ""):gsub("\n.*", "", 1)
|
||||
desc = strip_escapes(desc):lower()
|
||||
if desc ~= "" then
|
||||
description_cache[key] = desc
|
||||
end
|
||||
|
@@ -95,6 +95,7 @@ worldedit.register_command("unmark", {
|
||||
|
||||
local function set_pos1(name, pos)
|
||||
assert(pos)
|
||||
pos = vector.round(pos)
|
||||
worldedit.pos1[name] = pos
|
||||
worldedit.mark_pos1(name)
|
||||
worldedit.player_notify(name, S("position @1 set to @2", 1, minetest.pos_to_string(pos)), "ok")
|
||||
@@ -102,6 +103,7 @@ end
|
||||
|
||||
local function set_pos2(name, pos)
|
||||
assert(pos)
|
||||
pos = vector.round(pos)
|
||||
worldedit.pos2[name] = pos
|
||||
worldedit.mark_pos2(name)
|
||||
worldedit.player_notify(name, S("position @1 set to @2", 2, minetest.pos_to_string(pos)), "ok")
|
||||
@@ -115,7 +117,7 @@ worldedit.register_command("pos1", {
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
set_pos1(name, vector.round(player:get_pos()))
|
||||
set_pos1(name, player:get_pos())
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -127,7 +129,7 @@ worldedit.register_command("pos2", {
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
set_pos2(name, vector.round(player:get_pos()))
|
||||
set_pos2(name, player:get_pos())
|
||||
end,
|
||||
})
|
||||
|
||||
|
@@ -20,8 +20,8 @@ local function safe_region(name, count, callback)
|
||||
count_str = minetest.colorize("#f33", count_str:sub(1, -7)) .. count_str:sub(-6, -1)
|
||||
end
|
||||
|
||||
local yes_cmd = minetest.colorize("#00ffff", "//y")
|
||||
local no_cmd = minetest.colorize("#00ffff", "//n")
|
||||
local yes_cmd = minetest.colorize("#0ff", "//y")
|
||||
local no_cmd = minetest.colorize("#0ff", "//n")
|
||||
local msg = S("WARNING: this operation could affect up to @1 nodes; type @2 to continue or @3 to cancel",
|
||||
count_str, yes_cmd, no_cmd)
|
||||
worldedit.player_notify(name, msg, "info")
|
||||
|
Reference in New Issue
Block a user