118 lines
2.7 KiB
Lua
118 lines
2.7 KiB
Lua
local strings = require("./utils/strings")
|
|
local debug = require("./utils/print_r")
|
|
local maze2d = require("./maze")
|
|
local maze3d = require("./maze3d")
|
|
local openscad = require("./openscad")
|
|
|
|
local settings = {
|
|
mode = "help",
|
|
extras = {},
|
|
|
|
width = 11,
|
|
height = 11,
|
|
depth = 7,
|
|
|
|
filename = "maze.scad"
|
|
}
|
|
|
|
for i=1,#arg do
|
|
if not strings.starts_with(arg[i], "-") then
|
|
table.insert(settings.extras, arg[i])
|
|
elseif string.match(arg[i], "--width") or string.match(arg[i], "-w") then
|
|
i = i + 1
|
|
settings.width = tonumber(arg[i])
|
|
elseif string.match(arg[i], "--height") or string.match(arg[i], "-h") then
|
|
i = i + 1
|
|
settings.height = tonumber(arg[i])
|
|
elseif string.match(arg[i], "--depth") or string.match(arg[i], "-d") then
|
|
i = i + 1
|
|
settings.depth = tonumber(arg[i])
|
|
elseif string.match(arg[i], "--seed") or string.match(arg[i], "-s") then
|
|
i = i + 1
|
|
settings.seed = tonumber(arg[i])
|
|
elseif string.match(arg[i], "--filename") or string.match(arg[i], "-f") then
|
|
i = i + 1
|
|
settings.filename = arg[i]
|
|
end
|
|
end
|
|
|
|
if #settings.extras > 0 then
|
|
settings.mode = table.remove(settings.extras, 1)
|
|
end
|
|
|
|
local function help()
|
|
print([[
|
|
multimaze: Multidimensional maze generator
|
|
By Starbeamrainbowlabs
|
|
|
|
Usage:
|
|
lua main.lua {mode} [{options}]
|
|
|
|
Modes:
|
|
help Displays this message
|
|
maze Generates a 2d maze
|
|
maze3d Generates a 3d maze
|
|
maze3d_openscad Generates a 3d maze as an openscad file
|
|
|
|
Options:
|
|
-w --width Sets the width of the maze
|
|
-h --height Sets the height of the maze
|
|
-d --depth Sets the depth of the maze (only applicable to 3d mazes)
|
|
-s --seed Sets the seed
|
|
-f --filename Sets the output filename
|
|
]])
|
|
end
|
|
|
|
local function maze_text()
|
|
local world, time = maze2d.generate_maze(
|
|
os.time(),
|
|
settings.width,
|
|
settings.height
|
|
)
|
|
maze2d.printspace(world, settings.width, settings.height)
|
|
print("Generation completed in " .. time .. "ms.")
|
|
end
|
|
|
|
local function maze3d_text()
|
|
local world, time = maze3d.generate_maze(
|
|
os.time(),
|
|
settings.width,
|
|
settings.height,
|
|
settings.depth
|
|
)
|
|
|
|
maze3d.printspace(world, settings.width, settings.height, settings.depth)
|
|
|
|
print("Generation completed in " .. time .. "ms.")
|
|
end
|
|
|
|
local function maze3d_openscad()
|
|
local world, time = maze3d.generate_maze(
|
|
os.time(),
|
|
settings.width,
|
|
settings.height,
|
|
settings.depth
|
|
)
|
|
|
|
openscad.write3d(
|
|
world,
|
|
settings.width, settings.height, settings.depth,
|
|
settings.filename
|
|
)
|
|
print("Maze written to "..settings.filename)
|
|
end
|
|
|
|
local mode_functions = {
|
|
["help"] = help,
|
|
["maze"] = maze_text,
|
|
["maze3d"] = maze3d_text,
|
|
["maze3d_openscad"] = maze3d_openscad
|
|
}
|
|
|
|
local selection = mode_functions[settings.mode]
|
|
if not selection then
|
|
print("Error: Unrecognised mode '"..settings.mode.."'")
|
|
selection = mode_functions["help"]
|
|
end
|
|
|
|
selection()
|