-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.lua
More file actions
101 lines (90 loc) · 2.3 KB
/
builder.lua
File metadata and controls
101 lines (90 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
--- UI for Builder
---@class Builder_Lib
local builder = require("builder-lib")
local function help()
print("Usage:")
print("builder <command> <options>")
print("Commands: ")
print("'floor'")
print("'clearArea'")
print("Options:")
print("-mH[movementDir. Horizon] <'left'|'right'> [default: right]")
print("-mV[movementDir. Vertical] <'down'|'up'> [default: up]")
print("-p (place) up | down")
print("-w[width] <number>")
print("-l[length] <number>")
print("-h[height] <number>")
print("help")
end
if #arg == 0 then
help()
return
end
local stopExec = false
local size = {
["length"] = nil,
["width"] = nil,
["height"] = nil
}
local argsSwitch = {
["-mH"] = function(no)
no[1] = no[1] + 1
builder.movementDirection.width = arg[no[1]]
end,
["-mV"] = function (no)
no[1] = no[1] + 1
builder.movementDirection.height = arg[no[1]]
end,
["-l"] = function(no)
no[1] = no[1] + 1
size["length"] = tonumber(arg[no[1]]) or error("length not valid")
end,
["-w"] = function(no)
no[1] = no[1] + 1
size["width"] = tonumber(arg[no[1]]) or error("width not valid")
end,
["-h"] = function(no)
no[1] = no[1] + 1
if not tonumber(arg[no[1]]) then
help()
stopExec = true
return
end
size["height"] = tonumber(arg[no[1]])
end,
["-p"] = function(no)
no[1] = no[1] + 1
builder.placeDirection = arg[no[1]]
end,
["help"] = function()
help()
stopExec = true
end
}
local commands = {
["floor"] = function()
builder:floor(size["length"], size["width"])
end,
["clearArea"] = function()
builder:clearArea(size["length"], size["width"], size["height"])
end
}
local function main()
-- table to allow manipulation in argsSwitch
local currentArgNo = {2}
while currentArgNo[1] <= #arg do
if argsSwitch[arg[currentArgNo[1]]] == nil then
help()
return
end
argsSwitch[arg[currentArgNo[1]]](currentArgNo)
currentArgNo[1] = currentArgNo[1] + 1
end
if stopExec then return end
if commands[arg[1]] == nil then
help()
return
end
commands[arg[1]]()
end
main()