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

Feat: Add "show" to pref-adjust #1375

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

TolMera
Copy link

@TolMera TolMera commented Jan 18, 2025

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

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
Copy link
Member

@myk002 myk002 left a 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")
Copy link
Member

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.

Copy link
Author

@TolMera TolMera Jan 19, 2025

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 Show resolved Hide resolved
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
Copy link
Member

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

Copy link
Author

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)

TolMera and others added 6 commits January 19, 2025 18:50
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.
@TolMera
Copy link
Author

TolMera commented Jan 19, 2025

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
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Change preferences for all units to an ideal.
Change preferences for all citizens to an ideal.

Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:tags: fort armok units preferences
:tags: fort armok units

Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
: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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants