Module:AbilityHints: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Update stale class name in comment after the iconbox- rename (with help from vergir-bot LLM) |
m add sorting for ability hints |
||
| Line 4: | Line 4: | ||
local AbilityTable = require("Module:AbilityTable") | local AbilityTable = require("Module:AbilityTable") | ||
local ability_data = mw.loadJsonData("Data:AbilityData.json") | local ability_data = mw.loadJsonData("Data:AbilityData.json") | ||
local resource_lookup = mw.loadJsonData("Data:ResourceLookup.json") | |||
local item_data = mw.loadJsonData("Data:ItemData.json") | |||
local p = {} | local p = {} | ||
-- | -- Automatic hints that get shown without corresponding {{AbilityInteraction}}. Powered by Module:AbilityTable | ||
local CONFIG = { | local CONFIG = { | ||
{ list = "melee", file = "Melee Charge.png", tip = "Benefits from melee items ([[Melee Charge]])" }, | { list = "melee", file = "Melee Charge.png", tip = "Benefits from melee items ([[Melee Charge]])" }, | ||
| Line 20: | Line 22: | ||
{ list = "summons", file = "Monster Rounds.png", tip = "Summons affected by [[Monster Rounds]] and [[Heroic Aura]]" }, | { list = "summons", file = "Monster Rounds.png", tip = "Summons affected by [[Monster Rounds]] and [[Heroic Aura]]" }, | ||
} | } | ||
-- Display order: item slot (Weapon, then Vitality, then Spirit), then cost, then name. | |||
local function sort_key(file) | |||
local base = mw.ustring.lower((file:gsub('%.%w+$', ''))) | |||
local entry = resource_lookup[base] | |||
local item = (entry ~= nil and entry.type == 'item') and item_data[entry.key] or nil | |||
if item == nil then | |||
return { 99, math.huge, base } | |||
end | |||
local slot = item["Slot"] | |||
local slot_rank = (slot == "Weapon" and 1) or (slot == "Armor" and 2) or (slot == "Tech" and 3) or 98 | |||
return { | |||
slot_rank, | |||
tonumber(item["Cost"]) or math.huge, | |||
mw.ustring.lower(item["Name"] or base), | |||
} | |||
end | |||
local function compare(a, b) | |||
for i = 1, 3 do | |||
if a.sort[i] ~= b.sort[i] then return a.sort[i] < b.sort[i] end | |||
end | |||
return false | |||
end | |||
-- partial: split the icon so the top-left half is grayscale (mirrors the iconbox-partial box icon). | -- partial: split the icon so the top-left half is grayscale (mirrors the iconbox-partial box icon). | ||
| Line 57: | Line 83: | ||
manual = manual or {} | manual = manual or {} | ||
local manual_by_file = {} | local manual_by_file = {} | ||
for _, m in ipairs(manual) do | for _, m in ipairs(manual) do | ||
| Line 63: | Line 88: | ||
end | end | ||
local | local entries = {} | ||
local placed = {} | local placed = {} | ||
local record = ability_data[ability_key] | local record = ability_data[ability_key] | ||
if record ~= nil then | if record ~= nil then | ||
| Line 75: | Line 99: | ||
local m = manual_by_file[key] | local m = manual_by_file[key] | ||
if m ~= nil then | if m ~= nil then | ||
table.insert( | table.insert(entries, { file = m.file, html = manual_icon(m) }) | ||
placed[key] = true | placed[key] = true | ||
else | else | ||
table.insert( | table.insert(entries, { file = def.file, html = hint_icon(def) }) | ||
end | end | ||
end | end | ||
| Line 84: | Line 108: | ||
end | end | ||
for _, m in ipairs(manual) do | for _, m in ipairs(manual) do | ||
if not placed[mw.ustring.lower(m.file)] then | if not placed[mw.ustring.lower(m.file)] then | ||
table.insert( | table.insert(entries, { file = m.file, html = manual_icon(m) }) | ||
end | end | ||
end | end | ||
if # | if #entries == 0 then return '' end | ||
for _, e in ipairs(entries) do e.sort = sort_key(e.file) end | |||
table.sort(entries, compare) | |||
local icons = {} | |||
for _, e in ipairs(entries) do table.insert(icons, e.html) end | |||
return '<div class="ability-section-hints">' .. table.concat(icons) .. '</div>' | return '<div class="ability-section-hints">' .. table.concat(icons) .. '</div>' | ||
end | end | ||
return p | return p | ||