Add ripping by name pattern match

This commit is contained in:
Aaron Suen 2022-11-23 12:27:16 -05:00
parent e4cbbd9065
commit 3ec66ca9e0
2 changed files with 33 additions and 7 deletions

View File

@ -1,8 +1,8 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, pairs, string, tonumber, vector
= minetest, pairs, string, tonumber, vector
local string_format
= string.format
local minetest, pairs, pcall, string, tonumber, vector
= minetest, pairs, pcall, string, tonumber, vector
local string_format, string_gsub, string_match
= string.format, string.gsub, string.match
-- LUALOCALS > ---------------------------------------------------------
local include = ...
@ -77,3 +77,30 @@ minetest.register_chatcommand(modname .. "_here", {
return save_export_report()
end
})
local function patternfunc(setto)
return function(_, param)
if param == "" then return false, "must supply pattern" end
local ok, err = pcall(function()
for k in pairs(minetest.registered_items) do
if string_match(k, param) then
exportdb[k] = setto
end
end
end)
if not ok then return false, string_gsub(err, ".*:%d+:%s*", "") end
return save_export_report()
end
end
minetest.register_chatcommand(modname .. "_add", {
description = "Rip all defs with technical names matching a pattern",
params = "<lua pattern>",
privs = {server = true},
func = patternfunc(true)
})
minetest.register_chatcommand(modname .. "_rm", {
description = "Un-rip all defs with technical names matching a pattern",
params = "<lua pattern>",
privs = {server = true},
func = patternfunc(nil)
})

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local error, io, ipairs, minetest, pairs, print, string, type
= error, io, ipairs, minetest, pairs, print, string, type
local error, io, ipairs, minetest, pairs, string, type
= error, io, ipairs, minetest, pairs, string, type
local io_open, string_format, string_gsub
= io.open, string.format, string.gsub
-- LUALOCALS > ---------------------------------------------------------
@ -38,7 +38,6 @@ local function ripmedia(reffed, thing, dest, rel, test)
test = test or function(a, b) return a == b end
if type(thing) == "string" then
for _, s in ipairs(string_gsub(thing, "[\\[:,=&{]", "^"):split("^")) do
print(thing .. " -> " .. s)
for k, v in pairs(mediacache) do
if test(s, k) then
local fulldest = getdir(dest .. "/" .. rel) .. "/" .. k