Clean up unused media, add autogen banner
This commit is contained in:
parent
8a137ec91f
commit
e4cbbd9065
25
commands.lua
25
commands.lua
@ -1,6 +1,8 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, pairs
|
||||
= minetest, pairs
|
||||
local minetest, pairs, string, tonumber, vector
|
||||
= minetest, pairs, string, tonumber, vector
|
||||
local string_format
|
||||
= string.format
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local include = ...
|
||||
@ -9,10 +11,16 @@ local exportall = include("exportall")
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
||||
local function save_export_report()
|
||||
savedb()
|
||||
local defs, media = exportall()
|
||||
return true, string_format("exported %d defs and %d media", defs, media)
|
||||
end
|
||||
|
||||
minetest.register_chatcommand(modname, {
|
||||
description = "Rip all items in already marked for export",
|
||||
privs = {server = true},
|
||||
func = function() return true, "exported " .. exportall() end
|
||||
func = save_export_report
|
||||
})
|
||||
|
||||
minetest.register_chatcommand(modname .. "_clear", {
|
||||
@ -20,8 +28,7 @@ minetest.register_chatcommand(modname .. "_clear", {
|
||||
privs = {server = true},
|
||||
func = function()
|
||||
for k in pairs(exportdb) do exportdb[k] = nil end
|
||||
savedb()
|
||||
return true, "exported " .. exportall()
|
||||
return save_export_report()
|
||||
end
|
||||
})
|
||||
|
||||
@ -38,12 +45,11 @@ minetest.register_chatcommand(modname .. "_inv", {
|
||||
end
|
||||
end
|
||||
end
|
||||
savedb()
|
||||
return true, "exported " .. exportall()
|
||||
return save_export_report()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand(modname .. "_here", {
|
||||
minetest.register_chatcommand(modname .. "_here", {
|
||||
description = "Rip all nodes within a radius",
|
||||
params = "[radius = 100]",
|
||||
privs = {server = true},
|
||||
@ -68,7 +74,6 @@ minetest.register_chatcommand(modname .. "_inv", {
|
||||
if n then exportdb[n] = true end
|
||||
end
|
||||
|
||||
savedb()
|
||||
return true, "exported " .. exportall()
|
||||
return save_export_report()
|
||||
end
|
||||
})
|
||||
|
@ -1,13 +1,13 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local io, minetest, pairs, string, type
|
||||
= io, minetest, pairs, string, type
|
||||
local io_open, string_gsub, string_sub
|
||||
= io.open, string.gsub, string.sub
|
||||
local io, ipairs, minetest, os, pairs, string, type
|
||||
= io, ipairs, minetest, os, pairs, string, type
|
||||
local io_open, os_remove, string_gsub, string_sub
|
||||
= io.open, os.remove, string.gsub, string.sub
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local include = ...
|
||||
local dumptable, sortedpairs = include("dumptable")
|
||||
local getdir, stealmedia = include("fileops")
|
||||
local getdir, ripmedia = include("fileops")
|
||||
local exportdb = include("exportdb")
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
@ -49,7 +49,8 @@ local function exportall()
|
||||
local outdir = getdir(minetest.get_worldpath() .. "/" .. modname)
|
||||
|
||||
local outf = io_open(outdir .. "/exported.lua", "w")
|
||||
outf:write("local reg = ...\n\n")
|
||||
outf:write("-- AUTOMATICALLY GENERATED by <https://gitlab.com/szest/defripper>"
|
||||
.. "\n\nlocal reg = ...\n\n")
|
||||
|
||||
local filtered = {}
|
||||
for k, v in pairs(minetest.registered_items) do
|
||||
@ -115,16 +116,17 @@ local function exportall()
|
||||
end
|
||||
end
|
||||
|
||||
local mymedia = {}
|
||||
for _, v in sortedpairs(filtered) do
|
||||
stealmedia(v.sounds, outdir, "sounds", function(spec, fn)
|
||||
ripmedia(mymedia, v.sounds, outdir, "sounds", function(spec, fn)
|
||||
return string_sub(fn, 1, #spec + 1) == spec .. "."
|
||||
and string_sub(fn, -4) == ".ogg"
|
||||
end)
|
||||
stealmedia(v.tiles, outdir, "textures")
|
||||
stealmedia(v.special_tiles, outdir, "textures")
|
||||
stealmedia(v.inventory_image, outdir, "textures")
|
||||
stealmedia(v.wield_image, outdir, "textures")
|
||||
stealmedia(v.mesh, outdir, "models")
|
||||
ripmedia(mymedia, v.tiles, outdir, "textures")
|
||||
ripmedia(mymedia, v.special_tiles, outdir, "textures")
|
||||
ripmedia(mymedia, v.inventory_image, outdir, "textures")
|
||||
ripmedia(mymedia, v.wield_image, outdir, "textures")
|
||||
ripmedia(mymedia, v.mesh, outdir, "models")
|
||||
outf:write("reg(" .. dumptable(v, {
|
||||
locals = function(item)
|
||||
return localized[item]
|
||||
@ -134,7 +136,19 @@ local function exportall()
|
||||
end
|
||||
outf:close()
|
||||
|
||||
return count
|
||||
for _, mdir in ipairs({"sounds", "textures", "models"}) do
|
||||
for _, fn in pairs(minetest.get_dir_list(outdir .. "/" .. mdir, false) or {}) do
|
||||
local fulldest = outdir .. "/" .. mdir .. "/" .. fn
|
||||
if not mymedia[fulldest] then
|
||||
os_remove(fulldest)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local mediaqty = 0
|
||||
for _ in pairs(mymedia) do mediaqty = mediaqty + 1 end
|
||||
|
||||
return count, mediaqty
|
||||
end
|
||||
|
||||
return exportall
|
||||
|
12
fileops.lua
12
fileops.lua
@ -34,23 +34,25 @@ local function cpfile(src, dst)
|
||||
end
|
||||
end
|
||||
|
||||
local function stealmedia(thing, dest, rel, test)
|
||||
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
|
||||
cpfile(v, getdir(dest .. "/" .. rel) .. "/" .. k)
|
||||
local fulldest = getdir(dest .. "/" .. rel) .. "/" .. k
|
||||
cpfile(v, fulldest)
|
||||
reffed[fulldest] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(thing) == "table" then
|
||||
if thing.name then return stealmedia(thing.name, dest, rel, test) end
|
||||
if thing.name then return ripmedia(reffed, thing.name, dest, rel, test) end
|
||||
for _, v in pairs(thing) do
|
||||
stealmedia(v, dest, rel, test)
|
||||
ripmedia(reffed, v, dest, rel, test)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return getdir, stealmedia
|
||||
return getdir, ripmedia
|
||||
|
Loading…
x
Reference in New Issue
Block a user