-
Notifications
You must be signed in to change notification settings - Fork 200
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 gui/workorder-details.lua: adjusts input item, material, traits #358
Conversation
Adjust input items, material, or traits for work orders. Actual jobs created for it will inherit the details.
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.
Overall, looks solid. Thanks!
A couple questions:
- instead of copying code, can you
reqscript('gui/workshop-job')
and call any existing functions/inherit from existing classes directly? - instead of
workorder-finetune
, how aboutworkorder-details
orworkorder-edit
? - could you add some tests in the test/gui directory to validate that the code continues to work when DF or DFHack behavior changes? This will help a lot to identify code that breaks on the upcoming steam version of DF
- could you add a changelog entry, under new scripts?
Also, does it make sense to be able to adjust order quantities or frequency with this script? |
IMO this would be too deep in the details: from the work order list view |
I definitely don't like I am not quite sure about |
This allows to reuse previously duplicated code from `gui/workshop-job.lua`. Also, minor wording changes and comments.
did that. Had to modify (very minorly) the |
gui/workorder-finetune
Outdated
JobDetails.canChangeIType = wsj.JobDetails.canChangeIType | ||
JobDetails.setItemType = wsj.JobDetails.setItemType | ||
JobDetails.onChangeIType = wsj.JobDetails.onChangeIType | ||
JobDetails.canChangeMat = wsj.JobDetails.canChangeMat | ||
JobDetails.setMaterial = wsj.JobDetails.setMaterial | ||
JobDetails.findUnambiguousItem = wsj.JobDetails.findUnambiguousItem | ||
JobDetails.onChangeMat = wsj.JobDetails.onChangeMat |
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.
Stealing individual methods from a class, while technically functional, could lead to issues later if wsj
is updated with undesired behavior. Could you refactor wsj.JobDetails
so that the common functions are in a superclass? Then that class could be clearly marked as "shared" and both the JobDetails
here and the JobDetails
in wsj
could inherit from that common class.
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.
Is there a convention how such a shared class should look like? I think to call it JobDetailsBase
and place in /scripts/gui/
.
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.
JobDetailsBase
sounds good. It can either stay in wsj (commented to indicate that it is shared across scripts) or it can go in internal/gui/
. It shouldn't go in a new file in gui/
because then it would show up in ls
as an independent script
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.
so, I started to actually do this and it would be a huge refactoring. The problem is one class inherits from MenuOverlay
while another from FramedScreen
. We need multi-inheritance or to change both scripts in such a way most of the rendering happens inside a widget, then JobDetailsBase
can inherit from Widget
. But this is IMO too much work for little benefit. Should we actually have the class inheritance in place, any change in the base class that's undesired in one of the scripts will still need to be addressed. The only thing we win is obviously marking those functions as shared
- maybe we could just leave a comment? "Beware: this script shares functions with worder-details.lua
" or something.
Started on that. There is currently some ugliness involved, f.e. I couldn't figure out how to emulate typing: Also, the test file-name has underscore instead of hyphen because
|
You have to use the actual key code to navigate the df menus. Look in |
Not matching hyphens sounds like a bug in the test harness. I'll get that fixed. |
Actually, the test harness is working as designed. The problem is that the Or just |
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.
I'd like to test in-game a bit before merging, but code looks good. Thanks for the test!
Could you add a changelog entry for this? |
I've not forgotten about that, there is a dependency graph in my head: find out if the hyphen is a problem for tests (✔), decide on the script name (will probably go with |
👍 |
Yeah, that's tricky. I did something like that here: scripts/test/gui/blueprint.lua Line 371 in a1df858
You essentially have to call the onInput method directly
|
I think this only works when |
Sorry about that -- I thought this was one of our filters. Finding the keycode for each key such that the viewscreen will accept it would work, but would be messy and arduous. Quickfort has an API that might be useful here. For example, to enqueue a 'cut slade' job, you could use this:
The key sequence enters the Specifically for creating orders, you could also use the edit: now that #372 is merged, if you pull latest master, you can simplify the above function to:
|
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.
Could you merge latest master so everything is up to date with the latest code?
ping on this |
about |
It would be possible to factor some functionality out, but I'm not sure if there's anything shady about using the public API of quickfort to implement a test. It is used by other scripts (e.g. assign-minecarts) to perform similar utility functions. Interdependencies among the scripts is starting to become more common. (especially with quickfort, which has its own ecosystem test harness) |
test/gui/workorder-details.lua
Outdated
if c.enabled then | ||
confirmRemove = function() | ||
wait() | ||
-- without delays `confirm` can miss the key event |
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.
are you sure? I have not found this to be the case in the past.
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.
it happens sporadically, when it does, removing order fails and test doesn't exit to map screen (and test fails at the Test order should've been removed
-check). With delay(5)
it happened once the first time I startet DF after PC restart -- I think it has something to do with anti-virus... Without the first delay(5)
it happens every 3rd time or so.
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.
Let me look into this a little before merging. Otherwise code looks great!
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.
Thanks :)
The most important question: could you reproduce the issue?
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.
yes, reproduced, and I tracked down why. When the SELECT key is sent to the confirm prompt, the intercepted key isn't passed on to the underlying screen until the next rendered frame. Since we escape out of that screen before the next rendered frame, it is never sent -- until the screen is reopened. If you run the test, and it fails, and then you manually open the manager orders screen, you can see the test order there before it quickly disappears. If you pause the confirm dialog and resend MANAGER_REMOVE, it works without any injected delays. I'll put that suggestion in the PR.
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.
Is there a way to "wait until the next rendered frame"? It seems possible with dfhack.timeout
, but probably cumbersome. On a related note, I can't find docs for the delay
itself...
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.
Yes, but it's somewhat hacky. You can get how many ticks occur between each frame and wait that many ticks plus one. I'm not sure if this is always consistent, though, since the ticks per graphics frame is variable.
There are no docs for the unit tests, which is a bad thing. You can see the implementation of delay
here: https://github.com/DFHack/dfhack/blob/0aa7ec877e4201af76b429438037fb5fc8a501c2/ci/test.lua#L82
It gets injected into the global environment for unit tests along with some other utility functions. In fact, you might be able to use delay_until
to detect when a frame has been rendered.
When the `SELECT` key is sent to the `confirm` prompt, the intercepted key isn't passed on to the underlying screen until the next rendered frame. Since we escape out of that screen before the next rendered frame, it is never sent -- until the screen is reopened. If you run the test, and it fails, and then you manually open the manager orders screen, you can see the test order there before it quickly disappears. If you pause the confirm dialog and resend `MANAGER_REMOVE`, it works. Co-authored-by: Myk <[email protected]>
Adjust input items, material, or traits for work orders. Actual jobs created for it will inherit the details.
This is the equivalent of
gui/workshop-job
for work orders, with the additional possibility to set input items' traits.F.e., we can make a work order to "Cut unknown material":
Which then appears like this in the workshop:
It has to be run from a work order's detail screen (:kbd:
j-m
, select work order, :kbd:d
), because the game initializes work order's.items
array as soon as the screen is opened (and then copies it over to the job).For best experience add the following to your
dfhack*.init
::