-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathcopybuilding.lua
More file actions
92 lines (69 loc) · 2.04 KB
/
copybuilding.lua
File metadata and controls
92 lines (69 loc) · 2.04 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
--@ module = true
local help = [====[
copybuilding
============
Copy a building and start building placement mode for the same building type.
Usage:
copybuilding
Copy building under cursor
copybuilding 1..9
Copy the last n building you copied
Examples:
copybuilding
Copy the building under the cursor and start placing the same type
copybuilding 1
Re-copy the last building type you copied
Note:
- Calling this script is intended to be done via keybindings. e.g. `keybinding add Alt-1 "copybuilding 1"`
- History is not persisted between sessions
]====]
local argparse = require('argparse')
local copybuilding = require('plugins.buildingplan.copybuilding')
local function print_help()
print(help)
end
local function process_args(opts, args)
if args[1] == 'help' then
opts.help = true
return {}
end
local positionals = argparse.processArgsGetopt(args, {
{'h', 'help', handler=function() opts.help = true end},
})
return positionals
end
local function main(...)
local args, opts = {...}, {}
local positionals = process_args(opts, args)
if opts.help then
print_help()
return
end
local history_index = tonumber(positionals[1])
if history_index then
if history_index < 1 or history_index > copybuilding.MAX_HISTORY then
qerror('History index must be 1-' .. copybuilding.MAX_HISTORY)
end
local success, message = copybuilding.copy_building_from_history(history_index)
if message then
if success then
print('Copied ' .. message)
else
qerror(message)
end
end
else
local success, message = copybuilding.copy_building_at_cursor()
if message then
if success then
print('Copied ' .. message .. ' and starting construction mode...')
else
qerror(message)
end
end
end
end
if dfhack_flags.module then
return
end
main(...)