Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local iconData = mw.loadJsonData("Data:ResourceLookup.json") | |||
local iconData = mw.loadJsonData("Data: | |||
local lang_codes = mw.loadJsonData("Data:LangCodes.json") | local lang_codes = mw.loadJsonData("Data:LangCodes.json") | ||
local cachedLangCode, cachedLangData | local cachedLangCode, cachedLangData | ||
local linkOverrides = { | local linkOverrides = { | ||
["Bullet Lifesteal"] = "Bullet Lifesteal (item)", | ["Bullet Lifesteal"] = "Bullet Lifesteal (item)", | ||
["Spirit Lifesteal"] = "Spirit Lifesteal (item)" | ["Spirit Lifesteal"] = "Spirit Lifesteal (item)" | ||
} | |||
local missingImageOverrides = { | |||
["boho"] = "Module-Icon missing.png", | |||
["druid"] = "Module-Icon missing.png", | |||
["fortuna"] = "Module-Icon missing.png", | |||
["graf"] = "Module-Icon missing.png", | |||
["gunslinger"] = "Module-Icon missing.png", | |||
["skyrunner"] = "Module-Icon missing.png", | |||
["swan"] = "Module-Icon missing.png", | |||
["thumper"] = "Module-Icon missing.png", | |||
} | } | ||
| Line 50: | Line 59: | ||
cachedLangData = langData | cachedLangData = langData | ||
return langCode, langData | return langCode, langData | ||
end | |||
-- Infer image path from name, with override support for missing images | |||
local function getImage(iconInfo) | |||
local lowerName = iconInfo.name:lower() | |||
return missingImageOverrides[lowerName] or (iconInfo.name .. ".png") | |||
end | |||
-- Infer link from type and available fields | |||
local function getLink(iconInfo) | |||
if iconInfo.type == "ability" then | |||
return iconInfo.hero_name or iconInfo.name | |||
end | |||
return linkOverrides[iconInfo.name] or iconInfo.name | |||
end | end | ||
| Line 57: | Line 80: | ||
local lowerName = name:lower() | local lowerName = name:lower() | ||
if aliases[lowerName] then | if aliases[lowerName] then | ||
lowerName = aliases[lowerName] | lowerName = aliases[lowerName] | ||
end | end | ||
local iconInfo = iconData[lowerName] | local iconInfo = iconData[lowerName] | ||
| Line 69: | Line 90: | ||
end | end | ||
local customText = args.l1 or "" | local customText = args.l1 or "" | ||
local size = args.size or "20px" | local size = args.size or "20px" | ||
| Line 84: | Line 104: | ||
end | end | ||
local langCode, langData = getLangData() | local langCode, langData = getLangData() | ||
| Line 96: | Line 115: | ||
end | end | ||
local baseLink = getLink(iconInfo) | |||
local baseLink = | |||
local link = baseLink | local link = baseLink | ||
if langCode ~= "en" and baseLink ~= "" then | if langCode ~= "en" and baseLink ~= "" then | ||
| Line 103: | Line 121: | ||
end | end | ||
-- | -- Abilities get the module-icon-ability class for light/dark theme filter support | ||
local style | local style | ||
if iconInfo. | if iconInfo.type == "ability" then | ||
style = 'class="module-icon-ability" style="position:relative; bottom:2px;"' | style = 'class="module-icon-ability" style="position:relative; bottom:2px;"' | ||
else | else | ||
| Line 113: | Line 129: | ||
end | end | ||
local image = getImage(iconInfo) | |||
local imageLink = noLink and "" or link | local imageLink = noLink and "" or link | ||
local iconHtml = string.format('<span %s>[[File:%s|%s|link=%s]]</span>', style, | local iconHtml = string.format('<span %s>[[File:%s|%s|link=%s]]</span>', style, image, size, imageLink) | ||
if iconOnly or displayName == "" then | if iconOnly or displayName == "" then | ||