Skip to content

Commit

Permalink
Fix filename specification
Browse files Browse the repository at this point in the history
  • Loading branch information
random-geek committed May 11, 2020
1 parent b598a0c commit 1dd3aa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 1 addition & 12 deletions export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 15 additions & 5 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

0 comments on commit 1dd3aa4

Please sign in to comment.