Minetest-WorldEditAdditions/worldeditadditions/lib/sculpt/scan_static.lua

50 lines
1.7 KiB
Lua
Raw Normal View History

local wea = worldeditadditions
2022-09-19 02:16:22 +02:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
local import_static = dofile(wea.modpath.."/lib/sculpt/import_static.lua")
local function import_filepath(filepath, name, overwrite_existing)
if overwrite_existing and wea.sculpt.brushes[name] ~= nil then
return false, "Error: A brush with the name '"..name.."' already exists."
end
local success, brush, brush_size = import_static(filepath)
if not success then return success, "Error while reading from '"..filepath.."': "..brush end
wea.sculpt.brushes[name] = {
brush = brush,
size = brush_size
}
return true
end
--- Scans the given directory and imports all static brushes found.
-- Static brushes have the file extension ".brush.tsv" (without quotes).
-- @param dirpath string The path to directory that contains the static brushs to import.
-- @returns bool,loaded,errors A success boolean, followed by the number of brushes loaded, followed by the number of errors encountered while loading brushes (errors are logged as warnings with Minetest)
return function(dirpath, overwrite_existing)
if overwrite_existing == nil then overwrite_existing = false end
2022-09-19 02:16:22 +02:00
local files = wea_c.io.scandir_files(dirpath)
local brushes_loaded = 0
local errors = 0
2021-12-31 02:39:04 +01:00
for i, filename in pairs(files) do
2022-09-19 02:16:22 +02:00
if wea_c.str_ends(filename, ".brush.tsv") then
local filepath = dirpath.."/"..filename
local name = filename:gsub(".brush.tsv", "")
local success, msg = import_filepath(filepath, name, overwrite_existing)
if not success then
minetest.log("warning", "[WorldEditAdditions:sculpt] Encountered error when loading brush from '"..filepath.."':"..msg)
end
brushes_loaded = brushes_loaded + 1
end
end
return true, brushes_loaded, errors
end