1+
12-- @enable = true
23-- @module = true
4+
35local argparse = require (" argparse" )
46local eventful = require (" plugins.eventful" )
57local utils = require (" utils" )
68
7- local GLOBAL_KEY = " eggwatch "
9+ local GLOBAL_KEY = " nestboxes "
810local 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
2511
2612local function get_default_state ()
2713 return {
@@ -41,6 +27,24 @@ function isEnabled()
4127 return state .enabled
4228end
4329
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+
4448local function print_local (text )
4549 print (GLOBAL_KEY .. " : " .. text )
4650end
@@ -54,12 +58,14 @@ local function print_details(details)
5458 print_local (details )
5559 end
5660end
61+
5762local function format_target_count_row (header , row )
5863 return header ..
5964 " : " ..
6065 " target count: " ..
6166 row [1 ] .. " ; count children: " .. tostring (row [2 ]) .. " ; count adults: " .. tostring (row [3 ])
6267end
68+
6369local function print_status ()
6470 print_local ((GLOBAL_KEY .. " is currently %s." ):format (state .enabled and " enabled" or " disabled" ))
6571 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)
9197 return dfhack .internal .readPersistentSiteConfigInt (key , index )
9298end
9399
94- local function migrate_enabled_status_from_ccp_nestboxes ()
100+ local function migrate_enabled_status_from_cpp_nestboxes ()
95101 print_local (" About to attempt migration from cpp to lua" )
96102 local nestboxes_status = read_persistent_config (" nestboxes/config" , " 0" )
97103 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()
122128 utils .assign (state , processed_persisted_data )
123129
124130 if not state .migration_from_cpp_to_lua_done then
125- migrate_enabled_status_from_ccp_nestboxes ()
131+ migrate_enabled_status_from_cpp_nestboxes ()
126132 end
127133
128134 print_details ((" end load_state" ))
@@ -168,10 +174,6 @@ dfhack.onStateChange[GLOBAL_KEY] = function(sc)
168174 update_event_listener ()
169175end
170176
171- if dfhack_flags .module then
172- return
173- end
174-
175177local function is_egg (item )
176178 return df .item_type .EGG == item :getType ()
177179end
@@ -499,8 +501,16 @@ if df.global.gamemode ~= df.game_mode.DWARF or not dfhack.isMapLoaded() then
499501 return
500502end
501503
504+ if dfhack_flags .module then
505+ return
506+ end
507+
502508load_state ()
509+
503510local args , opts = {... }, {}
511+ if dfhack_flags and dfhack_flags .enable then
512+ args = {dfhack_flags .enable_state and " enable" or " disable" }
513+ end
504514local positionals =
505515 argparse .processArgsGetopt (
506516 args ,
@@ -515,18 +525,15 @@ local positionals =
515525 }
516526)
517527
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
525528
526529local command = positionals [1 ]
527530
528531if command == " help" or opts .help then
529532 print (dfhack .script_help ())
533+ elseif command == " enable" then
534+ do_enable ()
535+ elseif command == " disable" then
536+ do_disable ()
530537elseif command == " target" then
531538 set_target (positionals [2 ], positionals [3 ], positionals [4 ], positionals [5 ])
532539 print_status ()
0 commit comments