Refactor gm-unit: DRY up appearance modifier logic in editor_body.lua - #1594
Refactor gm-unit: DRY up appearance modifier logic in editor_body.lua#1594sizzlins wants to merge 7 commits into
Conversation
Fixes #5793. Manually calculates size_cur from size_base and body modifiers to emulate native DF scaling logic, fulfilling the 3-year-old TODO.
chdoc
left a comment
There was a problem hiding this comment.
This pull request makes a user-observable change (recalculating body sizes) and requires a changelog entry.
| function Editor_Body_Modifier:recalculateBodySize() | ||
| -- Manually recalculate body size | ||
| local new_size = self.target_unit.body.size_info.size_base | ||
| local caste = df.creature_raw.find(self.target_unit.race).caste[self.target_unit.caste] | ||
| for idx, mod_entry in ipairs(caste.body_appearance_modifiers) do | ||
| local t = mod_entry.modifier.type | ||
| if t >= 0 and t <= 2 then -- 0=HEIGHT, 1=BROADNESS, 2=LENGTH | ||
| local mod_val = self.target_unit.appearance.body_modifiers[idx] | ||
| new_size = math.floor((new_size * mod_val) / 100) | ||
| end | ||
| end | ||
| self.target_unit.body.size_info.size_cur = new_size | ||
| end |
There was a problem hiding this comment.
This was not present previously. Please explain where this comes from.
|
Apologies for the delay. We are currently short on reviewers, while also receiving a large number of pull requests from first-time and inexperienced contributors. To help us make the best use of our limited review capacity and give every contribution the attention it deserves, we’re currently limiting first-time contributors to one active pull request at a time. I have therefore added the label wait:first-contribution to all of your open PRs. Please comment on one of your PRs to indicate which one you would like us to review. If we do not receive a response within a month, we will close your open PRs for now. Please don't let this discourage you — we appreciate your interest in contributing! Once your first PR has been merged and you are familiar with the process, you can update your remaining PRs and we will remove the label. |
This PR is a cleanup and refactor of internal/gm-unit/editor_body.lua to remove duplicated code and follow standard DRY
Created unified setModifier and getModifier methods that intelligently handle both "part" and "body" modifications.
Deleted the nearly identical setPartModifier and setBodyModifier methods.
Stripped out the redundant if self.partChoice.type == "part" conditional checks that were scattered inside the selected(), random(), step(), and updateChoices() actions.