Skip to content

Refactor gm-unit: DRY up appearance modifier logic in editor_body.lua - #1594

Open
sizzlins wants to merge 7 commits into
DFHack:masterfrom
sizzlins:refactor/gm-unit-editor-body
Open

Refactor gm-unit: DRY up appearance modifier logic in editor_body.lua#1594
sizzlins wants to merge 7 commits into
DFHack:masterfrom
sizzlins:refactor/gm-unit-editor-body

Conversation

@sizzlins

Copy link
Copy Markdown

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.

@chdoc chdoc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This pull request makes a user-observable change (recalculating body sizes) and requires a changelog entry.

Comment on lines +27 to +39
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was not present previously. Please explain where this comes from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants