diff --git a/export.lua b/export.lua index d8aa1c5..58aa7e2 100644 --- a/export.lua +++ b/export.lua @@ -132,7 +132,7 @@ function meshport.create_node(idx, area, content, param2, playerName) return faces end -function meshport.create_mesh(playerName, p1, p2, filename) +function meshport.create_mesh(playerName, p1, p2, path) meshport.print(playerName, "info", "Generating mesh...") p1, p2 = vector.sort(p1, p2) local vm = minetest.get_voxel_manip() @@ -163,17 +163,6 @@ function meshport.create_mesh(playerName, p1, p2, filename) end end - filename = filename or os.date("%Y-%m-%d_%H-%M-%S") - - -- Create path for exported mesh. - local path = string.format("%s%smeshport%s%s_%s", - minetest.get_worldpath(), DIR_DELIM, DIR_DELIM, playerName, filename) - - if file_exists(path) then - meshport.print(playerName, "error", "File already exists.") - return - end - minetest.mkdir(path) mesh:write_obj(path) diff --git a/init.lua b/init.lua index 68d37b8..63a6aa8 100644 --- a/init.lua +++ b/init.lua @@ -57,19 +57,29 @@ minetest.register_chatcommand("meshport", { description = "Save a mesh of the selected area (filename optional).", privs = {meshport = true}, - func = function(name, param) + func = function(name, filename) if not meshport.p1[name] or not meshport.p2[name] then meshport.print(name, "error", "No area selected. Use /mesh1 and /mesh2 to select an area.") return end - if param:find("[^%w-_]") then + if filename:find("[^%w-_]") then meshport.print(name, "error", "Invalid name supplied. Please use valid characters ([A-Z][a-z][0-9][-_]).") return - elseif param == "" then - param = nil + elseif filename == "" then + filename = os.date("%Y-%m-%d_%H-%M-%S") end - meshport.create_mesh(name, meshport.p1[name], meshport.p2[name], param) + local mpPath = minetest.get_worldpath() .. DIR_DELIM .. "meshport" + local folderName = name .. "_" .. filename + + if table.indexof(minetest.get_dir_list(mpPath, true), folderName) > 0 then + meshport.print(name, "error", + string.format("Folder %q already exists. Try using a different name.", folderName)) + return + end + + local path = mpPath .. DIR_DELIM .. folderName + meshport.create_mesh(name, meshport.p1[name], meshport.p2[name], path) end, })