Module:Item: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local getArgs = require('Module:Arguments').getArgs local p = {} function p.main(frame) local args = getArgs(frame) local game = args[1]:lower() local item = args[2]:lower() local itemData = require('Module:Data/Item/' .. game).item local iconPage = mw.title.makeTitle('Module', 'Data/Icon/' .. game) local iconData = {} if iconPage.exists then iconData = require('Module:Data/Item/' .. game)["icon"] end local link = "" local itemIcon = "" if itemData[item]["i...") |
m (Protected "Module:Item" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
local game = args[1]:lower() | local game = args[1]:lower() | ||
local item = args[2]:lower() | local item = args[2]:lower() | ||
if item == "—" then | |||
return item | |||
end | |||
local itemData = require('Module:Data/Item/' .. game).item | local itemData = require('Module:Data/Item/' .. game).item | ||
local iconPage = mw.title.makeTitle('Module', 'Data/Icon/' .. game) | local iconPage = mw.title.makeTitle('Module', 'Data/Icon/' .. game) | ||
if not itemData[item] then | |||
error("Item ".. item.. " not defined for "..game) | |||
end | |||
local iconData = {} | local iconData = {} | ||
if iconPage.exists then | if iconPage.exists then | ||
iconData = require('Module:Data/ | iconData = require('Module:Data/Icon/' .. game)["icon"] | ||
end | end | ||
local link = "" | local link = "" | ||
local itemIcon = "" | local itemIcon = "" | ||
local gap = " " | |||
if game == "desum" then | |||
gap = "<small> </small>" | |||
end | |||
if itemData[item]["icon"] then | if itemData[item]["icon"] then | ||
itemIcon = itemData[item]["icon"] | itemIcon = itemData[item]["icon"] | ||
end | end | ||
if iconData[itemIcon] then | if iconData[itemIcon] then | ||
link = iconData[itemIcon] | link = iconData[itemIcon] .. gap | ||
end | end | ||
if itemData[item]["link"] then | if itemData[item]["link"] then | ||
link = " [[" .. itemData[item]["link"] .. "|" .. itemData[item]["name"] .. "]]" | link = link .. "[[" .. itemData[item]["link"] .. "|" .. itemData[item]["name"] .. "]]" | ||
else | else | ||
link = " [[" .. itemData[item]["name"] .. "]]" | link = link .. "[[" .. itemData[item]["name"] .. "]]" | ||
end | end | ||
return link | return link |
Latest revision as of 21:06, 28 November 2024
Documentation
Designed to be part of a template like so:
{{#invoke:Item|main|{{{1}}}|{{{2}}}}}
Parameter 1 is the game abbreviation and parameter 2 is the item name. This module will output the item icon and name together. If parameter 2 is an emdash, it outputs an emdash.
See also: Template:Item/Documentation
local getArgs = require('Module:Arguments').getArgs local p = {} function p.main(frame) local args = getArgs(frame) local game = args[1]:lower() local item = args[2]:lower() if item == "—" then return item end local itemData = require('Module:Data/Item/' .. game).item local iconPage = mw.title.makeTitle('Module', 'Data/Icon/' .. game) if not itemData[item] then error("Item ".. item.. " not defined for "..game) end local iconData = {} if iconPage.exists then iconData = require('Module:Data/Icon/' .. game)["icon"] end local link = "" local itemIcon = "" local gap = " " if game == "desum" then gap = "<small> </small>" end if itemData[item]["icon"] then itemIcon = itemData[item]["icon"] end if iconData[itemIcon] then link = iconData[itemIcon] .. gap end if itemData[item]["link"] then link = link .. "[[" .. itemData[item]["link"] .. "|" .. itemData[item]["name"] .. "]]" else link = link .. "[[" .. itemData[item]["name"] .. "]]" end return link end return p