Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make lever.lua module capable #1168

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Template for new versions:
- `quickfort`: new ``delete`` command for deleting player-owned blueprints (library and mod-added blueprints cannot be deleted)
- `gui/launcher`: refresh default tag filter when mortal mode is toggled in `gui/control-panel` so changes to which tools autocomplete take effect immediately
- `gui/civ-alert`: you can now register multiple burrows as civilian alert safe spaces
- `lever`: enable use of ``reqscript`` to access lever pulling functions.

## Removed
- `max-wave`: merged into `pop-control`
Expand Down
13 changes: 8 additions & 5 deletions lever.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Inspect and pull levers
local argparse = require('argparse')
--@ module = true

function leverPullJob(lever, priority)
local ref = df.general_ref_building_holderst:new()
Expand All @@ -18,8 +18,6 @@ function leverPullJob(lever, priority)

dfhack.job.linkIntoWorld(job, true)
dfhack.job.checkBuildingsNow()

print(leverDescribe(lever))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because these weren't documented doesn't mean they should be removed. Lots of script output isn't documented, and is generally useful. I don't know exactly how useful this was. It would be possible to keep it by adding a verbose flag that this script uses to these functions. (Actually, such a flag could go in PullLever() because lever is set there.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't think it is useful to describe the lever after pulling it. There is already separate functionality for describing levers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you insist on preserving the printing, I would simply move the print statement after the point(s) of use within this script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the output is useful as feedback to the player when calling from the CLI. When called as an API, it should be controlled by a quiet flag -- at least that's the pattern that I've been following for most other publicly-accessible calls like this (e.g. https://github.com/DFHack/scripts/blob/master/assign-minecarts.lua#L72)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the output was a diagnostic that related to what the function was doing, I would agree. In this case though, printing the description of the lever is only indirectly related to pulling it. In any case, I restored the behavior of the script by moving the print statements after the point of invocation.

end

function leverPullInstant(lever)
Expand All @@ -35,8 +33,6 @@ function leverPullInstant(lever)
else
lever.state = 1
end

print(leverDescribe(lever))
end

function leverDescribe(lever)
Expand Down Expand Up @@ -146,8 +142,15 @@ function PullLever(opts)
else
leverPullJob(lever, opts.priority)
end
print(leverDescribe(lever))
end

if dfhack_flags.module then
return
end

local argparse = require('argparse')

local function parse_commandline(args)
local opts = {}
local commands = argparse.processArgsGetopt(args, {{
Expand Down