-
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
Feat: Add "show" to pref-adjust #1375
base: master
Are you sure you want to change the base?
Feat: Add "show" to pref-adjust #1375
Conversation
This feature returns the list of Likes for a selected dwarf. This script may be useful if: * a user wants to view a quick list of likes for a dwarf * a user wants to view the list of likes after updating a dwarfs likes * Other scripts may find this helpful, as this functionality is not otherwise exposed via dfhack
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.
please also add a line to the Misc Improvements section of the "Future" version in changelog.txt
Thanks!
pref-adjust.lua
Outdated
else | ||
print ("Sets preferences of one dwarf, or of all dwarves, using profiles.") | ||
print ("Valid options:") | ||
print ("list -- show available preference type lists") | ||
print ("show -- show current preferences") |
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 list of print
statements should be replaced with a single call to print(dfhack.script_help())
.
nowadays, script documentation goes in separate files that get rendered by our documentation build. for this script, docs should go in docs/pref-adjust.rst
.
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.
Complete - please confirm implementation
pref-adjust.lua
Outdated
@@ -269,6 +268,51 @@ function build_all_lists(printflag) | |||
end | |||
end -- end func build_all_lists | |||
-- --------------------------------------------------------------------------- | |||
function get_preferences(unit) | |||
if unit == nil then |
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 fine, but the more idiomatic form would be
if not unit then
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.
Implemented - if it was worth the comment, it was worth the change.
pref-adjust.lua
Outdated
elseif pref_type == "LikePlant" then | ||
description = "Likes plant: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex) | ||
elseif pref_type == "HateCreature" then | ||
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.poetic_form_id].creature_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.
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.poetic_form_id].creature_id | |
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.creature_id].creature_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.
the existing code only writes to one field of the union, but you can read the appropriate fields here
pref-adjust.lua
Outdated
elseif pref_type == "HateCreature" then | ||
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.poetic_form_id].creature_id | ||
elseif pref_type == "LikeColor" then | ||
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.poetic_form_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.
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.poetic_form_id].id | |
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.color_id].id |
pref-adjust.lua
Outdated
elseif pref_type == "LikeColor" then | ||
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.poetic_form_id].id | ||
elseif pref_type == "LikeShape" then | ||
description = "Likes shape: " .. df.global.world.raws.descriptors.shapes[pref.poetic_form_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.
description = "Likes shape: " .. df.global.world.raws.descriptors.shapes[pref.poetic_form_id].id | |
description = "Likes shape: " .. df.global.world.raws.descriptors.shapes[pref.shape_id].id |
pref-adjust.lua
Outdated
elseif pref_type == "LikePoeticForm" then | ||
description = "Likes poetic form: " .. dfhack.translation.translateName(df.global.world.poetic_forms.all[pref.poetic_form_id].name, true) | ||
elseif pref_type == "LikeMusicalForm" then | ||
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.poetic_form_id].name, true) |
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.
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.poetic_form_id].name, true) | |
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.musical_form_id].name, true) |
pref-adjust.lua
Outdated
elseif pref_type == "LikeMusicalForm" then | ||
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.poetic_form_id].name, true) | ||
elseif pref_type == "LikeDanceForm" then | ||
description = "Likes dance form: " .. dfhack.translation.translateName(df.global.world.dance_forms.all[pref.poetic_form_id].name, true) |
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.
description = "Likes dance form: " .. dfhack.translation.translateName(df.global.world.dance_forms.all[pref.poetic_form_id].name, true) | |
description = "Likes dance form: " .. dfhack.translation.translateName(df.global.world.dance_forms.all[pref.dance_form_id].name, true) |
otherwise you'll get an extra error printed to the console when no unit is selected Co-authored-by: Myk <[email protected]>
Functional update: updated script to use call to `dfhack.script_help` function
Added notes to future>misc as requested in PR
Feedback on this is that if a unit is not selected, and this function is called, you will get two errors printed instead of the expected one.
pre-commit.ci autofix |
@@ -62,6 +62,7 @@ Template for new versions: | |||
- `caravan`: add filter for written works in display furniture assignment dialog | |||
- `fix/wildlife`: don't vaporize stuck wildlife that is onscreen -- kill them instead (as if they died from old age) | |||
- `gui/sitemap`: show primary group affiliation for visitors and invaders (e.g. civilization name or performance troupe) | |||
- `pref-assign`: updated to allow users to run `pref-assign show` to get a list of units current preferences |
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 should go up in the "Future" section -- this is the section for the already-released 50.15-r2
``pref-adjust all|goth_all|clear_all`` | ||
Changes/clears preferences for all dwarves. | ||
Changes/clears preferences for all units. |
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.
Changes/clears preferences for all units. | |
Changes/clears preferences for all citizens. |
|
||
|
||
Examples | ||
-------- | ||
|
||
``pref-adjust all`` | ||
Change preferences for all dwarves to an ideal. | ||
Change preferences for all units to an ideal. |
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.
Change preferences for all units to an ideal. | |
Change preferences for all citizens to an ideal. |
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 we use "units" in these docs, we mean all units on the map, not just citizens.
``pref-adjust list`` | ||
List all types of preferences. No changes will be made to any units. | ||
``pref-adjust show`` | ||
Show the preferences of a unit. |
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.
Show the preferences of a unit. | |
Show the preferences of the selected unit. |
:summary: Set the preferences of a dwarf to an ideal. | ||
:tags: fort armok units | ||
:summary: Get the preferences of a dwarf, Set the preferences of a dwarf to a designated profile. | ||
:tags: fort armok units preferences |
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.
:tags: fort armok units preferences | |
:tags: fort armok units |
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 only choose from the existing set of tags (documented here: https://docs.dfhack.org/en/latest/docs/Tags.html )
@@ -2,8 +2,8 @@ pref-adjust | |||
=========== | |||
|
|||
.. dfhack-tool:: | |||
:summary: Set the preferences of a dwarf to an ideal. | |||
:tags: fort armok units | |||
:summary: Get the preferences of a dwarf, Set the preferences of a dwarf to a designated profile. |
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.
:summary: Get the preferences of a dwarf, Set the preferences of a dwarf to a designated profile. | |
:summary: See the preferences of a dwarf or set them to a designated profile. |
This feature returns the list of Likes for a selected dwarf.
This script may be useful if: