Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions internal/gm-unit/editor_body.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ function Editor_Body_Modifier:setPartModifier(indexList, value)
-- Update the world texture
self.target_unit.flags4.any_texture_must_be_refreshed = true

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

self:updateChoices()
end

Expand All @@ -45,6 +57,18 @@ function Editor_Body_Modifier:setBodyModifier(modifierIndex, value)
-- Update the world texture
self.target_unit.flags4.any_texture_must_be_refreshed = true

-- Manually recalculate body size

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 code is an exact duplicate of the code above. write a function and call it in both places. Don't Repeat Yourself.

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

self:updateChoices()
end

Expand Down