Module:Abilities/card: Difference between revisions

Jump to navigation Jump to search
m Missing altbox number checks
m Use resource lookup for faster hero key retrieval
Line 5: Line 5:
local p = {}
local p = {}
local data = mw.loadJsonData("Data:AbilityCards.json")
local data = mw.loadJsonData("Data:AbilityCards.json")
local resourceLookup = mw.loadJsonData("Data:ResourceLookup.json")


-- Maps attr type to an appropriate image and page link
-- Maps attr type to an appropriate image and page link
-- Optional icon size, will be defaulted on the template
-- Optional icon size, will be defaulted on the template
local ATTR_TYPE_ICON_MAP = require("Module:Icon/attr")
local ATTR_TYPE_ICON_MAP = require("Module:Icon/attr")
-- TODO - replace this with utils file
function utils.get_ability_card_data(hero_key, ability_num)
if(hero_key == nil) then return nil end
return data[hero_key][tonumber(ability_num)]
end




Line 23: Line 17:
-- if name starts with "hero_", use it directly as the key
-- if name starts with "hero_", use it directly as the key
if string.sub(hero_name, 1, 5) == "hero_" then return hero_name end
if string.sub(hero_name, 1, 5) == "hero_" then return hero_name end
return resourceLookup[hero_name:lower()].key
for i, hero in pairs(data) do
if hero["Name"] == hero_name then
return i
end
end
return nil
end
end