-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add a display for melt remainders #1326
base: master
Are you sure you want to change the base?
Add a display for melt remainders #1326
Conversation
pre-commit.ci autofix |
e6a6e86
to
a3cb1dc
Compare
|
||
ENABLED = ENABLED or false | ||
|
||
local function i_hate_lua(tbl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really an appropriate place to express your opinions on the scripting language DFHack uses.
local rems = get_melt_remainders(workshop) | ||
if not rems then return end | ||
|
||
printall(rems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover debug statement?
gui/melt-remainder | ||
================== | ||
When enabled, a line of text is added to the Tasks screen of melters and magma smelters | ||
that shows how much metal is "stored" as a result of melting items in it. (The base game | ||
has no display of this information,) | ||
|
||
Click on the text for more detailed information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs should go in docs/gui/melt-remainder.rst
. You can copy another file in that directory to get the format. More info on the documentation format is at: https://docs.dfhack.org/en/stable/docs/dev/Documentation.html#documentation-standards
-- the existence of this is not documented anywhere of course | ||
local dialogs = require("gui.dialogs") | ||
|
||
ENABLED = ENABLED or false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overlays don't need to track their enabled state. that is handled by the overlay framework itself. You will be able to toggle the overlay in gui/control-panel
on the Overlays tab.
|
||
local overlay = require("plugins.overlay") | ||
local widgets = require("gui.widgets") | ||
-- the existence of this is not documented anywhere of course |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contributions are welcome for the docs, of course, but you can remove this comment. It doesn't help.
end | ||
|
||
local function get_melt_remainders(smelter) | ||
if not smelter.melt_remainder then return nil end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a non-pointer vector field, this can never be falsey. if you want to check for an empty vector, it should be if #smelter.melt_remainder == 0 then return nil end
local mat_count = #df.global.world.raws.inorganics | ||
for i = 0, mat_count - 1 do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although #smelter.melt_remainder
should be the same as #df.global.world.raws.inorganics
, it would be more consistent to define mat_count = #smelter.melt_remainder
since you are indexing into smelter.melt_remainder
in the loop.
return fractions | ||
end | ||
|
||
-- lua doesn't hoist functions nerd emoji |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is true, but the comment doesn't add value
printall(rems) | ||
local lines = {} | ||
for mat_id, tenths in pairs(rems) do | ||
local mat_name = df.global.world.raws.inorganics[mat_id].id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should probably be using the material lookup functions for this: https://docs.dfhack.org/en/stable/docs/dev/Lua%20API.html#material-info-lookup
e.g. dfhack.matinfo.decode(0, mat_id)
then you can get the in-game name from the returned object.
if #lines == 0 then | ||
table.insert(lines, "<There were no melt remainders>") | ||
end | ||
dialogs.DialogScreen{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DialogScreen
is lower level than you need to be here. The dialogs.showMessage()
function would be more appropriate. https://github.com/DFHack/dfhack/blob/develop/library/lua/gui/dialogs.lua#L121
'dwarfmode/ViewSheets/BUILDING/Furnace/MagmaSmelter/Tasks', | ||
}, | ||
frame = { w = 58, h = 1 }, | ||
visible = function() return ENABLED end, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can take this out. overlay widget visibility is controlled by the framework
return | ||
end | ||
|
||
print("gui/melt-remainder is " .. (ENABLED and "enabled" or "disabled") .. ".") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when this script is run by name, it should check to see if it is in an appropriate context (a smelter is selected). If not in an appropriate context, qerror
. if a smelter is selected, it should show the dialog with the remainder info.
Hello, I wrote this script that adds an overlay for how much metal a smelter has from "Melt an Item" jobs.
If there's 0 or 1 melt remainder types, it'll say what it is and how much; otherwise it will tell you the number of metals inside. You can click for a full view of all the metals and their remainders.
This is my first foray into DFHack-ing, so please give me feedback! (Especially, I can't figure out how to use the actual material name, so I'm just using its internal raws name. Also, I bet it doesn't handle divine metals properly, but I only have a few divine metal items in my fort and I'm using them to keep my monarch happy, so I can't test it 😅 )