Module:StreetBrawlAbilities: Difference between revisions

Add change() to describe a Street Brawl property change as reduced/increased by a percentage (with help from vergir-bot LLM)
Vergir (talk | contribs)
Add hero_has_changes checker for the Street Brawl hero category (with help from vergir-bot LLM)
 
(One intermediate revision by the same user not shown)
Line 81: Line 81:
return "* <code>" .. mw.text.nowiki(call) .. "</code> &rarr; '''" .. sb
return "* <code>" .. mw.text.nowiki(call) .. "</code> &rarr; '''" .. sb
.. "''' ''(default " .. base .. ")''"
.. "''' ''(default " .. base .. ")''"
end
-- True when Street Brawl changes at least one of this hero's abilities. Accepts a
-- hero_* key or the hero's English name, so callers may pass whichever they hold.
function p.hero_has_changes(hero)
if hero == nil or hero == "" then return false end
local record  = mw.loadJsonData(HERO_PAGE)[hero]
local name    = (record and record.Name) or hero
local owners  = build_owner_map()
local changes = mw.loadJsonData(SB_PAGE)["ability-changes"]
for key in pairs(changes) do
local owner = owners[key]
if owner and owner.hero == name then return true end
end
return false
end
-- {{#invoke:StreetBrawlAbilities|hasChanges|HERO}} exposes the same check to wikitext,
-- answering "1" or the empty string so #if can branch on it.
function p.hasChanges(frame)
return p.hero_has_changes(mw.text.trim(frame.args[1] or "")) and "1" or ""
end
end


-- {{#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 125:
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