1
+
1
2
-- @enable = true
2
3
-- @module = true
4
+
3
5
local argparse = require (" argparse" )
4
6
local eventful = require (" plugins.eventful" )
5
7
local utils = require (" utils" )
6
8
7
- local GLOBAL_KEY = " eggwatch "
9
+ local GLOBAL_KEY = " nestboxes "
8
10
local default_table = {10 , false , false }
9
- local string_or_int_to_boolean = {[" true" ] = true , [" false" ] = false , [" 1" ] = true , [" 0" ] = false , [" Y" ] = true , [" N" ] = false , [1 ] = true , [0 ] = false }
10
-
11
- function dump (o )
12
- if type (o ) == " table" then
13
- local s = " { "
14
- for k , v in pairs (o ) do
15
- if type (k ) ~= " number" then
16
- k = ' "' .. k .. ' "'
17
- end
18
- s = s .. " [" .. k .. " ] = " .. dump (v ) .. " ,"
19
- end
20
- return s .. " } "
21
- else
22
- return tostring (o )
23
- end
24
- end
25
11
26
12
local function get_default_state ()
27
13
return {
@@ -41,6 +27,24 @@ function isEnabled()
41
27
return state .enabled
42
28
end
43
29
30
+ local function dump (o )
31
+ if type (o ) == " table" then
32
+ local s = " { "
33
+ for k , v in pairs (o ) do
34
+ if type (k ) ~= " number" then
35
+ k = ' "' .. k .. ' "'
36
+ end
37
+ s = s .. " [" .. k .. " ] = " .. dump (v ) .. " ,"
38
+ end
39
+ return s .. " } "
40
+ else
41
+ return tostring (o )
42
+ end
43
+ end
44
+
45
+ local string_or_int_to_boolean = {[" true" ] = true , [" false" ] = false , [" 1" ] = true , [" 0" ] = false , [" Y" ] = true , [" N" ] = false , [1 ] = true , [0 ] = false }
46
+
47
+
44
48
local function print_local (text )
45
49
print (GLOBAL_KEY .. " : " .. text )
46
50
end
@@ -54,12 +58,14 @@ local function print_details(details)
54
58
print_local (details )
55
59
end
56
60
end
61
+
57
62
local function format_target_count_row (header , row )
58
63
return header ..
59
64
" : " ..
60
65
" target count: " ..
61
66
row [1 ] .. " ; count children: " .. tostring (row [2 ]) .. " ; count adults: " .. tostring (row [3 ])
62
67
end
68
+
63
69
local function print_status ()
64
70
print_local ((GLOBAL_KEY .. " is currently %s." ):format (state .enabled and " enabled" or " disabled" ))
65
71
print_local ((" egg stack splitting is %s" ):format (state .split_stacks and " enabled" or " disabled" ))
@@ -91,7 +97,7 @@ local function read_persistent_config(key, index)
91
97
return dfhack .internal .readPersistentSiteConfigInt (key , index )
92
98
end
93
99
94
- local function migrate_enabled_status_from_ccp_nestboxes ()
100
+ local function migrate_enabled_status_from_cpp_nestboxes ()
95
101
print_local (" About to attempt migration from cpp to lua" )
96
102
local nestboxes_status = read_persistent_config (" nestboxes/config" , " 0" )
97
103
print_local ((" Migrating status %s from cpp nestboxes to lua" ):format (string_or_int_to_boolean [nestboxes_status ] and " enabled" or " disabled" ))
@@ -122,7 +128,7 @@ local function load_state()
122
128
utils .assign (state , processed_persisted_data )
123
129
124
130
if not state .migration_from_cpp_to_lua_done then
125
- migrate_enabled_status_from_ccp_nestboxes ()
131
+ migrate_enabled_status_from_cpp_nestboxes ()
126
132
end
127
133
128
134
print_details ((" end load_state" ))
@@ -168,10 +174,6 @@ dfhack.onStateChange[GLOBAL_KEY] = function(sc)
168
174
update_event_listener ()
169
175
end
170
176
171
- if dfhack_flags .module then
172
- return
173
- end
174
-
175
177
local function is_egg (item )
176
178
return df .item_type .EGG == item :getType ()
177
179
end
@@ -499,8 +501,16 @@ if df.global.gamemode ~= df.game_mode.DWARF or not dfhack.isMapLoaded() then
499
501
return
500
502
end
501
503
504
+ if dfhack_flags .module then
505
+ return
506
+ end
507
+
502
508
load_state ()
509
+
503
510
local args , opts = {... }, {}
511
+ if dfhack_flags and dfhack_flags .enable then
512
+ args = {dfhack_flags .enable_state and " enable" or " disable" }
513
+ end
504
514
local positionals =
505
515
argparse .processArgsGetopt (
506
516
args ,
@@ -515,18 +525,15 @@ local positionals =
515
525
}
516
526
)
517
527
518
- if dfhack_flags .enable then
519
- if dfhack_flags .enable_state then
520
- do_enable ()
521
- else
522
- do_disable ()
523
- end
524
- end
525
528
526
529
local command = positionals [1 ]
527
530
528
531
if command == " help" or opts .help then
529
532
print (dfhack .script_help ())
533
+ elseif command == " enable" then
534
+ do_enable ()
535
+ elseif command == " disable" then
536
+ do_disable ()
530
537
elseif command == " target" then
531
538
set_target (positionals [2 ], positionals [3 ], positionals [4 ], positionals [5 ])
532
539
print_status ()
0 commit comments