Fix filename specification
This commit is contained in:
parent
b598a0c5d5
commit
1dd3aa4000
13
export.lua
13
export.lua
@ -132,7 +132,7 @@ function meshport.create_node(idx, area, content, param2, playerName)
|
|||||||
return faces
|
return faces
|
||||||
end
|
end
|
||||||
|
|
||||||
function meshport.create_mesh(playerName, p1, p2, filename)
|
function meshport.create_mesh(playerName, p1, p2, path)
|
||||||
meshport.print(playerName, "info", "Generating mesh...")
|
meshport.print(playerName, "info", "Generating mesh...")
|
||||||
p1, p2 = vector.sort(p1, p2)
|
p1, p2 = vector.sort(p1, p2)
|
||||||
local vm = minetest.get_voxel_manip()
|
local vm = minetest.get_voxel_manip()
|
||||||
@ -163,17 +163,6 @@ function meshport.create_mesh(playerName, p1, p2, filename)
|
|||||||
end
|
end
|
||||||
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)
|
minetest.mkdir(path)
|
||||||
|
|
||||||
mesh:write_obj(path)
|
mesh:write_obj(path)
|
||||||
|
20
init.lua
20
init.lua
@ -57,19 +57,29 @@ minetest.register_chatcommand("meshport", {
|
|||||||
description = "Save a mesh of the selected area (filename optional).",
|
description = "Save a mesh of the selected area (filename optional).",
|
||||||
privs = {meshport = true},
|
privs = {meshport = true},
|
||||||
|
|
||||||
func = function(name, param)
|
func = function(name, filename)
|
||||||
if not meshport.p1[name] or not meshport.p2[name] then
|
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.")
|
meshport.print(name, "error", "No area selected. Use /mesh1 and /mesh2 to select an area.")
|
||||||
return
|
return
|
||||||
end
|
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][-_]).")
|
meshport.print(name, "error", "Invalid name supplied. Please use valid characters ([A-Z][a-z][0-9][-_]).")
|
||||||
return
|
return
|
||||||
elseif param == "" then
|
elseif filename == "" then
|
||||||
param = nil
|
filename = os.date("%Y-%m-%d_%H-%M-%S")
|
||||||
end
|
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,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user