Skip to content

Commit 91d1aa9

Browse files
committed
rename script to nestboxes
1 parent f724412 commit 91d1aa9

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

eggwatch.lua renamed to nestboxes.lua

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1+
12
--@enable = true
23
--@module = true
4+
35
local argparse = require("argparse")
46
local eventful = require("plugins.eventful")
57
local utils = require("utils")
68

7-
local GLOBAL_KEY = "eggwatch"
9+
local GLOBAL_KEY = "nestboxes"
810
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
2511

2612
local function get_default_state()
2713
return {
@@ -41,6 +27,24 @@ function isEnabled()
4127
return state.enabled
4228
end
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+
4448
local function print_local(text)
4549
print(GLOBAL_KEY .. ": " .. text)
4650
end
@@ -54,12 +58,14 @@ local function print_details(details)
5458
print_local(details)
5559
end
5660
end
61+
5762
local 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])
6267
end
68+
6369
local 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)
9298
end
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()
169175
end
170176

171-
if dfhack_flags.module then
172-
return
173-
end
174-
175177
local function is_egg(item)
176178
return df.item_type.EGG == item:getType()
177179
end
@@ -499,8 +501,16 @@ if df.global.gamemode ~= df.game_mode.DWARF or not dfhack.isMapLoaded() then
499501
return
500502
end
501503

504+
if dfhack_flags.module then
505+
return
506+
end
507+
502508
load_state()
509+
503510
local args, opts = {...}, {}
511+
if dfhack_flags and dfhack_flags.enable then
512+
args = {dfhack_flags.enable_state and "enable" or "disable"}
513+
end
504514
local 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

526529
local command = positionals[1]
527530

528531
if 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()
530537
elseif command == "target" then
531538
set_target(positionals[2], positionals[3], positionals[4], positionals[5])
532539
print_status()

0 commit comments

Comments
 (0)