Module:Item: Difference between revisions
Neko Knight (talk | contribs) No edit summary |
Neko Knight (talk | contribs) No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 19: | Line 19: | ||
local id = args['id'] | local id = args['id'] | ||
local data = mw.loadData('Module:Item/IDAliases') | local data = mw.loadData('Module:Item/IDAliases') | ||
local data4 = mw.loadData('Module:Item/Materials') | |||
local result | local result | ||
local data2 | local data2, data3 | ||
local | local itemname, itemMat | ||
local foundId = nil | |||
if lang == nil then | if lang == nil then | ||
mw.log("error: Language code not specified") | mw.log("error: Language code not specified") | ||
return "error: Language code not specified" | return "error: Language code not specified" | ||
end | |||
if string.find(name,'@') then | |||
itemname, itemMat = name:match("([^@]+)@([^@]+)") | |||
else | |||
itemname = name | |||
end | end | ||
Line 31: | Line 39: | ||
if id == nil then | if id == nil then | ||
if lang == 'EN' then | if lang == 'EN' then | ||
if not isBlank(itemMat) then | |||
for key, value in pairs(data4) do | |||
if value and value.name == itemMat then | |||
foundId = value.id | |||
break | |||
end | |||
end | |||
end | |||
if isBlank(variety) then | if isBlank(variety) then | ||
result = itemname | |||
else | else | ||
result = itemname..' '..variety | |||
end | end | ||
if not isBlank(foundId) then | |||
result = result..' '..foundId | |||
end | |||
image = 'Elin Item Sprite ' ..result..'.'..ext | |||
else | else | ||
if lang == 'JA' then | if lang == 'JA' then | ||
data2 = mw.loadData('Module:Item/JaAliases') | data2 = mw.loadData('Module:Item/JaAliases') | ||
data3 = mw.loadData('Module:Item/JaAliases2') | data3 = mw.loadData('Module:Item/JaAliases2') | ||
if not isBlank(itemMat) then | |||
for key, value in pairs(data4) do | |||
if value and value.name_JP == itemMat then | |||
foundId = value.id | |||
break | |||
end | |||
end | |||
end | |||
end | end | ||
if isBlank(variety) then | if isBlank(variety) then | ||
result = data[data2[ | result = data[data2[itemname]] or data3[itemname] | ||
else | else | ||
result = data[data2[ | result = data[data2[itemname..variety]] or data3[itemname..variety] | ||
end | end | ||
if isBlank(result) then | if not isBlank(foundId) then | ||
result = result..' '..foundId | |||
image = 'Elin Item Sprite ' ..result..'.'..ext | |||
elseif isBlank(result) then | |||
image = 'clear.png' | image = 'clear.png' | ||
else | else | ||
Line 68: | Line 99: | ||
end | end | ||
local wt = mw.html.create('span'):addClass('item | local wt = mw.html.create('span'):addClass('item') | ||
if args['grid'] == 'true' or args['grid'] == 'on' or args['grid'] == '1' or args['grid'] == 'Y' then | if args['grid'] == 'true' or args['grid'] == 'on' or args['grid'] == '1' or args['grid'] == 'Y' then | ||
wt:cssText('display: inline-grid; text-align: center;') | wt:cssText('display: inline-grid; text-align: center;') | ||
Line 79: | Line 110: | ||
end | end | ||
local Mat = '' | |||
if not isBlank(itemMat) then | |||
Mat = Mat..' '..itemMat | |||
end | |||
if link == 'false' or link == 'no' or link == '0' or link == 'N' then | if link == 'false' or link == 'no' or link == '0' or link == 'N' then | ||
wt:wikitext(string.format('[[File:%s|%s|link=|alt=%s|class=itemimg]]',image,size, | wt:wikitext(string.format('[[File:%s|%s|link=|alt=%s%s|class=itemimg]]',image,size,itemname,Mat)) | ||
wt:wikitext(string.format('%s', | wt:wikitext(string.format('%s%s',itemname,Mat)) | ||
else | else | ||
if isBlank(link) then | if isBlank(link) then | ||
link = 'Elin:'.. | link = 'Elin:'..itemname..'|'..itemname..Mat | ||
else | else | ||
link = link..'|'.. | link = link..'|'..itemname..Mat | ||
end | end | ||
wt:wikitext(string.format('[[File:%s|%s|link=%s|alt=%s|class=itemimg]]',image,size,link, | wt:wikitext(string.format('[[File:%s|%s|link=%s|alt=%s|class=itemimg]]',image,size,link,itemname)) | ||
wt:wikitext(string.format('[[%s]]',link)) | wt:wikitext(string.format('[[%s]]',link)) | ||
end | end |
Latest revision as of 15:00, 12 April 2025
このモジュールはTemplate:Item、Template:アイテムに使用されています。
local p = {}
local function isBlank(value)
return value == nil or not value or value == ''
end
function p.itemparameters(f)
local args = f:getParent().args
local lang = f.args[2]
local name = args[1] or f.args[1]
local namelen = string.len(name)
local ext = args['ext'] or 'png'
local size = args['size'] or '32x32px'
local num = args['x'] or args[2]
local image = args['img']
local link = args['link']
local variety = args['v']
local id = args['id']
local data = mw.loadData('Module:Item/IDAliases')
local data4 = mw.loadData('Module:Item/Materials')
local result
local data2, data3
local itemname, itemMat
local foundId = nil
if lang == nil then
mw.log("error: Language code not specified")
return "error: Language code not specified"
end
if string.find(name,'@') then
itemname, itemMat = name:match("([^@]+)@([^@]+)")
else
itemname = name
end
if image == nil then
if id == nil then
if lang == 'EN' then
if not isBlank(itemMat) then
for key, value in pairs(data4) do
if value and value.name == itemMat then
foundId = value.id
break
end
end
end
if isBlank(variety) then
result = itemname
else
result = itemname..' '..variety
end
if not isBlank(foundId) then
result = result..' '..foundId
end
image = 'Elin Item Sprite ' ..result..'.'..ext
else
if lang == 'JA' then
data2 = mw.loadData('Module:Item/JaAliases')
data3 = mw.loadData('Module:Item/JaAliases2')
if not isBlank(itemMat) then
for key, value in pairs(data4) do
if value and value.name_JP == itemMat then
foundId = value.id
break
end
end
end
end
if isBlank(variety) then
result = data[data2[itemname]] or data3[itemname]
else
result = data[data2[itemname..variety]] or data3[itemname..variety]
end
if not isBlank(foundId) then
result = result..' '..foundId
image = 'Elin Item Sprite ' ..result..'.'..ext
elseif isBlank(result) then
image = 'clear.png'
else
image = 'Elin Item Sprite ' ..result..'.'..ext
end
end
else
if data[id] then
image = 'Elin Item Sprite ' ..data[id]..'.'..ext
else
image = 'clear.png'
end
end
else
local v = string.find(image,'%.')
if v then
else
image = image..'.'..ext
end
end
local wt = mw.html.create('span'):addClass('item')
if args['grid'] == 'true' or args['grid'] == 'on' or args['grid'] == '1' or args['grid'] == 'Y' then
wt:cssText('display: inline-grid; text-align: center;')
else
if namelen >=36 then
wt:cssText('font-size: smaller; white-space: pre-wrap; letter-spacing: -0.1em;')
else
wt:cssText('white-space: nowrap;')
end
end
local Mat = ''
if not isBlank(itemMat) then
Mat = Mat..' '..itemMat
end
if link == 'false' or link == 'no' or link == '0' or link == 'N' then
wt:wikitext(string.format('[[File:%s|%s|link=|alt=%s%s|class=itemimg]]',image,size,itemname,Mat))
wt:wikitext(string.format('%s%s',itemname,Mat))
else
if isBlank(link) then
link = 'Elin:'..itemname..'|'..itemname..Mat
else
link = link..'|'..itemname..Mat
end
wt:wikitext(string.format('[[File:%s|%s|link=%s|alt=%s|class=itemimg]]',image,size,link,itemname))
wt:wikitext(string.format('[[%s]]',link))
end
if isBlank(num) then
else
wt:wikitext(string.format('(%s)',num))
end
return tostring(wt)
end
return p