2021-12-31 02:03:56 +01:00
local wea = worldeditadditions
2022-09-19 02:16:22 +02:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2021-12-31 02:03:56 +01:00
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).
2023-07-02 21:05:46 +02:00
-- @name scan_static
-- @internal
2021-12-31 02:03:56 +01:00
-- @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 )
2021-12-31 02:03:56 +01:00
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
2021-12-31 02:03:56 +01:00
local filepath = dirpath .. " / " .. filename
2021-12-31 02:43:53 +01:00
local name = filename : gsub ( " .brush.tsv " , " " )
2021-12-31 02:03:56 +01:00
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