Module:StreetBrawlAbilities: Difference between revisions

Jump to navigation Jump to search
Add change() to describe a Street Brawl property change as reduced/increased by a percentage (with help from vergir-bot LLM)
Vergir (talk | contribs)
Round change output to nearest 5% step, prefixing ~ when rounding exceeds 1.5% (with help from vergir-bot LLM)
Line 84: Line 84:


-- {{#invoke:StreetBrawlAbilities|change|ABILITY|PROP}} describes how far a property moved
-- {{#invoke:StreetBrawlAbilities|change|ABILITY|PROP}} describes how far a property moved
-- in Street Brawl, as "reduced by 45%" or "increased by 44%".
-- in Street Brawl, as "reduced by 45%" or "increased by ~40%".
function p.change(frame)
function p.change(frame)
local ability = mw.text.trim(frame.args[1] or "")
local ability = mw.text.trim(frame.args[1] or "")
Line 104: Line 104:
local direction = sb > base and "increased" or "reduced"
local direction = sb > base and "increased" or "reduced"
local percent = math.abs(sb - base) / math.abs(base) * 100
local percent = math.abs(sb - base) / math.abs(base) * 100
return direction .. " by " .. string.format("%.0f", percent) .. "%"
-- Rounded to the nearest 5% so the prose reads as a round figure; when that rounding
-- moves the number by more than 1.5 points, "~" marks it as approximate.
local rounded = math.floor(percent / 5 + 0.5) * 5
local approx = math.abs(percent - rounded) > 1.5 and "~" or ""
return direction .. " by " .. approx .. string.format("%.0f", rounded) .. "%"
end
end