Westgrass (vitalap | szerkesztései) ({{tr}} auto translation.) |
Rye Greenwood (vitalap | szerkesztései) (sync :: en revid:1013759::) |
||
(7 közbenső módosítás, amit 3 másik szerkesztő végzett, nincs mutatva) | |||
1. sor: | 1. sor: | ||
+ | |||
− | local function explode(div,str) -- credit: http://richard.warburton.it |
||
+ | ------- l10n info -------------- |
||
+ | local l10n_info = mw.loadData('Module:Item/l10n') |
||
+ | |||
+ | ------- The following is not related to l10n. -------------- |
||
+ | |||
+ | local trim = mw.text.trim |
||
+ | local cargo = mw.ext.cargo |
||
+ | local eicons = require('Module:Exclusive').simpleEicons |
||
+ | |||
+ | local currentFrame |
||
+ | local args_table |
||
+ | local lang |
||
+ | local l10n_table |
||
+ | |||
+ | local l10n = function(key) |
||
+ | return l10n_table[key] or l10n_info['en'][key] |
||
+ | end |
||
+ | |||
+ | local getArg = function(key) |
||
+ | local value = args_table[key] |
||
+ | if not value then |
||
+ | return nil |
||
+ | end |
||
+ | value = trim(value) |
||
+ | if value == '' then |
||
+ | return nil |
||
+ | end |
||
+ | return value |
||
+ | end |
||
+ | |||
+ | -- credit: http://richard.warburton.it |
||
+ | -- this version is with trim. |
||
+ | local function explode(div,str) |
||
if (div=='') then return false end |
if (div=='') then return false end |
||
local pos,arr = 0,{} |
local pos,arr = 0,{} |
||
-- for each divider found |
-- for each divider found |
||
for st,sp in function() return string.find(str,div,pos,true) end do |
for st,sp in function() return string.find(str,div,pos,true) end do |
||
− | + | arr[#arr + 1] = trim(string.sub(str,pos,st-1)) -- Attach chars left of current divider |
|
pos = sp + 1 -- Jump past current divider |
pos = sp + 1 -- Jump past current divider |
||
end |
end |
||
− | + | arr[#arr + 1] = trim(string.sub(str,pos)) -- Attach chars right of last divider |
|
return arr |
return arr |
||
end |
end |
||
− | local function |
+ | local function parseSize(size) |
+ | if not size then return end |
||
+ | local basescale, width, height |
||
+ | size, basescale = unpack(explode('*', size)) |
||
+ | if size ~= '' then |
||
+ | width, height = unpack(explode('x', string.gsub(size, 'px', ''))) |
||
+ | width, height = tonumber(width), tonumber(height) |
||
+ | if width == 0 then width = nil end |
||
+ | if height == 0 then height = nil end |
||
+ | end |
||
+ | return basescale, width, height |
||
+ | end |
||
+ | |||
+ | local function getInfoFromCargo(image) |
||
+ | -- try to get from cargo cache |
||
+ | local result = mw.ext.cargo.query('Imageinfo', 'width, height, cached', { |
||
+ | where = 'image='.. "'"..image:gsub("'", "\\'"):gsub("'", "\\'").."'", |
||
+ | orderBy = "cached DESC", |
||
+ | limit = 1, |
||
+ | }) |
||
+ | for _, row in ipairs(result) do |
||
+ | return tonumber(row['width']), tonumber(row['height']), row['cached'] |
||
+ | end |
||
+ | end |
||
+ | |||
+ | local function storeInfoToCargo(image) |
||
+ | local width, height |
||
+ | width = tonumber(currentFrame:callParserFunction( '#imgw', image)) |
||
+ | if width and width ~= 0 then -- save one expensive call when the file is not a valid image. |
||
+ | height = tonumber(currentFrame:callParserFunction( '#imgh', image)) |
||
+ | if height and height ~= 0 then |
||
+ | currentFrame:callParserFunction('#cargo_store:_table=Imageinfo',{ |
||
+ | image = image, |
||
+ | width = width, |
||
+ | height = height, |
||
+ | cached = os.time(), |
||
+ | }) |
||
+ | end |
||
+ | end |
||
+ | return width, height |
||
+ | end |
||
+ | |||
+ | local function getSizeInfo(image) |
||
+ | local width, height, cached = getInfoFromCargo(image) |
||
+ | -- cache missed, init cache |
||
+ | if not cached then |
||
+ | width, height = storeInfoToCargo(image) |
||
+ | end |
||
+ | if width == 0 then width = nil end |
||
+ | if height == 0 then height = nil end |
||
+ | return width, height |
||
+ | end |
||
+ | |||
+ | local function getImageSize(image, width, height, scale, maxwidth, maxheight) |
||
+ | -- get size info from image file itself (may be expensive) |
||
+ | local w, h = getSizeInfo(image) -- store data to cache |
||
+ | |||
+ | if not width and not height and (scale or maxwidth or maxheight) then |
||
+ | width, height = w, h |
||
+ | end |
||
+ | |||
+ | -- apply scale to width/height if needed |
||
+ | if scale then |
||
+ | if width then width = width * scale end |
||
+ | if height then height = height * scale end |
||
+ | end |
||
+ | |||
+ | -- apply maxwidth/maxheight. |
||
+ | if maxwidth then |
||
+ | if width then |
||
+ | if width > maxwidth then width = maxwidth end |
||
+ | else |
||
+ | if height then width = maxwidth end |
||
+ | end |
||
+ | end |
||
+ | if maxheight then |
||
+ | if height then |
||
+ | if height > maxheight then height = maxheight end |
||
+ | else |
||
+ | if width then height = maxheight end |
||
+ | end |
||
+ | end |
||
+ | |||
+ | -- rounding |
||
+ | if width then width = math.ceil(width) end |
||
+ | if height then height = math.ceil(height) end |
||
+ | |||
+ | return width, height |
||
+ | end |
||
+ | |||
+ | local function parseMaxSize(maxsize) |
||
+ | if not maxsize then return end |
||
+ | local maxwidth, maxheight = unpack(explode('x', string.gsub(maxsize, 'px', ''))) |
||
+ | maxwidth, maxheight = tonumber(maxwidth), tonumber(maxheight) |
||
+ | if maxwidth == 0 then maxwidth = nil end |
||
+ | if maxheight == 0 then maxheight = nil end |
||
+ | return maxwidth, maxheight |
||
+ | end |
||
+ | |||
+ | local function imagecode(image, link, text, size, scale, maxsize) |
||
local image_output = '[[File:' .. image .. '|link='.. link .. '|' .. text |
local image_output = '[[File:' .. image .. '|link='.. link .. '|' .. text |
||
− | if size then |
+ | if size or scale or maxsize then |
+ | local basescale, width, height = parseSize(size) -- width,height: number or nil |
||
− | return image_output .. '|' .. size .. ']]' |
||
+ | scale = (tonumber(scale) or 1) * (tonumber(basescale) or 1) |
||
+ | if scale == 0 or scale == 1 then |
||
+ | scale = nil |
||
+ | end |
||
+ | local maxwidth, maxheight = parseMaxSize(maxsize) |
||
+ | width, height = getImageSize(image, width, height, scale, maxwidth, maxheight) -- can be 0 |
||
+ | if width or height then |
||
+ | return image_output .. '|' .. (width or '') .. 'x' .. (height or '') .. 'px]]' |
||
+ | else |
||
+ | return image_output .. ']]' |
||
+ | end |
||
else |
else |
||
return image_output .. ']]' |
return image_output .. ']]' |
||
20. sor: | 163. sor: | ||
end |
end |
||
+ | |||
− | local image_for_cargo |
||
− | local function images(image, link, text, size) |
+ | local function images(image, link, text, size, scale, maxsize) |
if not image:find('/') then |
if not image:find('/') then |
||
+ | return imagecode(image, link, text, size, scale, maxsize) |
||
− | image_for_cargo = image |
||
− | return imagecode(image, link, text, size) |
||
end |
end |
||
32. sor: | 174. sor: | ||
if size and size:find('/') then |
if size and size:find('/') then |
||
size = explode('/', size) |
size = explode('/', size) |
||
− | for |
+ | for i, v in ipairs(image) do |
− | result = result .. imagecode(v, link, text, size[ |
+ | result = result .. imagecode(v, link, text, size[i], scale, maxsize) |
end |
end |
||
else |
else |
||
− | for |
+ | for i, v in ipairs(image) do |
− | result = result .. imagecode(v, link, text, size) |
+ | result = result .. imagecode(v, link, text, size, scale, maxsize) |
end |
end |
||
end |
end |
||
43. sor: | 185. sor: | ||
end |
end |
||
+ | local getIdText = function(_type) |
||
+ | local id_text |
||
+ | if _type == 'item' then -- a shortcut for faster |
||
+ | id_text = l10n('id_text_item') |
||
+ | elseif _type == 'tile' then |
||
+ | id_text = l10n('id_text_tile') |
||
+ | elseif _type == 'wall' then |
||
+ | id_text = l10n('id_text_wall') |
||
+ | elseif _type == 'npc' then |
||
+ | id_text = l10n('id_text_npc') |
||
+ | elseif _type == 'mount' then |
||
+ | id_text = l10n('id_text_mount') |
||
+ | elseif _type == 'buff' or _type == 'debuff' then |
||
+ | id_text = l10n('id_text_buff') |
||
+ | elseif _type == 'projectile' then |
||
+ | id_text = l10n('id_text_projectile') |
||
+ | elseif _type == 'armor' then |
||
+ | id_text = l10n('id_text_armor') |
||
+ | else |
||
+ | id_text = l10n('id_text_item') |
||
+ | end |
||
+ | return id_text |
||
+ | end |
||
+ | ----------------------------------------------------------------- |
||
− | |||
-- main return object |
-- main return object |
||
− | return { |
+ | return { |
+ | |||
− | |||
− | + | go = function(frame, args) |
|
+ | -- init cache |
||
− | local value = frame.args[key] |
||
+ | currentFrame = frame |
||
− | if not value then |
||
+ | args_table = args or frame.args |
||
− | return nil |
||
+ | lang = getArg('lang') or 'en' |
||
− | end |
||
+ | l10n_table = l10n_info[lang] or l10n_info['en'] |
||
− | value = mw.text.trim(value) |
||
− | if value == '' then |
||
− | return nil |
||
− | else |
||
− | return value |
||
− | end |
||
− | end |
||
local _arg1 = getArg(1) or '' |
local _arg1 = getArg(1) or '' |
||
− | local |
+ | local _nolink = getArg('nolink') |
+ | local _link = _nolink and '' or getArg('link') or frame:expandTemplate{ title = 'tr', args = {_arg1, link='y'} } -- now: _link == '' means nolink. |
||
− | -- {{tr}} for auto translation |
||
− | if _link ~= '' then |
||
− | _link = frame:expandTemplate{ title = 'tr', args = {_link} } |
||
− | end |
||
− | local |
+ | local text = getArg(2) or '' |
+ | |||
− | local text |
||
+ | local hovertext |
||
− | if _arg2 then |
||
− | + | if _arg1 ~= '' then |
|
+ | hovertext = frame:expandTemplate{ title = 'tr', args = {_arg1} } |
||
− | text = _arg1 .. _arg2 |
||
− | + | elseif text ~= '' then |
|
+ | hovertext = text |
||
− | text = _arg1:sub(0, -2) .. _arg2 |
||
− | elseif _arg2 == 'ves' then |
||
− | text = _arg1:sub(0, -3) .. _arg2 |
||
− | else |
||
− | text = _arg2 |
||
− | end |
||
else |
else |
||
− | + | hovertext = _link |
|
end |
end |
||
+ | local class = 'i' |
||
− | --display text auto translation |
||
− | text = frame:expandTemplate{ title = 'tr', args = {text} } |
||
− | |||
− | local class = 'item-link' |
||
+ | local output_image, output_text, output_table = true, true, false |
||
local _mode = getArg('mode') |
local _mode = getArg('mode') |
||
− | |||
− | local output_image, output_text, output_table = true, true, false |
||
if _mode then |
if _mode then |
||
if _mode == 'image' or _mode == 'imageonly' or _mode =='onlyimage' then |
if _mode == 'image' or _mode == 'imageonly' or _mode =='onlyimage' then |
||
102. sor: | 249. sor: | ||
end |
end |
||
− | local image_output |
+ | local image_output, text_output |
if output_image then |
if output_image then |
||
+ | local image_arg = string.gsub(_arg1, ":%s*", " ") |
||
− | image_output = images(getArg('image') or (_arg1 .. '.' .. (getArg('ext') or 'png')), _link, text, getArg('size')) |
||
+ | if _arg1 == '1/2 Second Timer' then |
||
+ | image_arg = '1 2 Second Timer' |
||
+ | elseif _arg1 == '1/4 Second Timer' then |
||
+ | image_arg = '1 4 Second Timer' |
||
+ | end |
||
+ | image_arg = getArg('image') or image_arg .. '.' .. (getArg('ext') or 'png') |
||
+ | image_output = images(image_arg, _link, hovertext, getArg('size'), getArg('scale'), getArg('maxsize')) |
||
+ | else |
||
+ | image_output = '' |
||
end |
end |
||
− | |||
− | local text_output = '' |
||
if output_text then |
if output_text then |
||
− | local _note = getArg('note') |
+ | local _note, _note2, _showid, _id = getArg('note'), getArg('note2'), getArg('showid'), getArg('id') |
+ | |||
− | local _note2 = getArg('note2') |
||
− | + | if _id and not _showid then |
|
+ | _showid = true |
||
+ | end |
||
+ | if _showid and (_showid == 'n' or _showid == 'no') then |
||
+ | _showid = false |
||
+ | end |
||
local _wrap |
local _wrap |
||
− | if |
+ | if _showid or _note2 then |
_wrap = false |
_wrap = false |
||
else |
else |
||
_wrap = getArg('wrap') |
_wrap = getArg('wrap') |
||
end |
end |
||
− | |||
if _link ~= '' then |
if _link ~= '' then |
||
− | text = |
+ | if text == _link then |
+ | text = '<span>[['..text..']]</span>' |
||
− | end |
||
− | |||
− | local _icon = getArg('icons') |
||
− | local icon = '' |
||
− | if not (_icon == 'n' or _icon == 'no' or _icon == 'off') then |
||
− | -- eicons should base on _arg1 first. |
||
− | local t |
||
− | if _arg1 == '' then |
||
− | t = _link |
||
else |
else |
||
+ | text = '<span>[['.._link..'|'..text..']]</span>' |
||
− | t = _arg1 |
||
end |
end |
||
+ | else |
||
− | local args = {t} |
||
+ | text = '<span title="'..hovertext..'">'..text..'</span>' |
||
− | if _id or _note2 or _wrap or getArg('small') then |
||
+ | end |
||
− | args['small'] = 'y' |
||
+ | |||
− | end |
||
+ | local _icon, icon = getArg('icons'), nil |
||
− | icon = frame:expandTemplate{ title = 'eicons', args = args } |
||
+ | if _icon == 'n' or _icon == 'no' or _icon == 'off' then |
||
+ | icon = '' |
||
+ | else |
||
+ | icon = eicons(getArg('epage') or _arg1, lang, (_showid or _note2 or _wrap or getArg('small')) and 'y') |
||
end |
end |
||
− | local content = |
+ | local content = text -- item name link text first. |
+ | -- '-w' class means 'wrapmode', optimized for multiple lines of text. But it should be disabled for single line text. |
||
if _wrap then |
if _wrap then |
||
+ | -- eicons in the same line |
||
if icon ~= '' then |
if icon ~= '' then |
||
− | class = ' |
+ | class = class .. ' -w' |
content = content .. icon |
content = content .. icon |
||
end |
end |
||
+ | -- note in next line |
||
if _note then |
if _note then |
||
− | class = ' |
+ | class = class .. ' -w' |
− | content = content .. |
+ | content = content .. '<span class="note">' .. _note .. '</span>' |
end |
end |
||
else |
else |
||
+ | -- note first |
||
if _note then |
if _note then |
||
− | content = content .. |
+ | content = content .. '<span class="note">' .. _note .. '</span>' |
end |
end |
||
if icon ~= '' then |
if icon ~= '' then |
||
160. sor: | 318. sor: | ||
end |
end |
||
if _note2 then |
if _note2 then |
||
− | class = ' |
+ | class = class .. ' -w' |
− | content = content .. |
+ | content = content .. '<div class="note">' .. _note2 .. '</div>' |
end |
end |
||
− | if |
+ | if _showid then |
− | class = ' |
+ | class = class .. ' -w' |
− | local |
+ | local idtype = (getArg('type') or 'item'):lower() |
− | + | if not _id then |
|
+ | _id = frame:expandTemplate{ title = idtype .. 'IdFromName', args = {_arg1} } |
||
− | local id_text |
||
− | if _type == 'item' then -- a shortcut for faster |
||
− | id_text = 'Internal [[Item IDs|Item ID]]: ' |
||
− | if output_image and image_for_cargo then |
||
− | frame:expandTemplate{ title = 'Item/cargo', args = {name=_arg1, image=image_for_cargo, id=_id} } |
||
− | end |
||
− | elseif _type == 'tile' then |
||
− | id_text = 'Internal [[Tile IDs|Tile ID]]: ' |
||
− | elseif _type == 'wall' then |
||
− | id_text = 'Internal [[Wall IDs|Wall ID]]: ' |
||
− | elseif _type == 'npc' then |
||
− | id_text = 'Internal [[NPC IDs|NPC ID]]: ' |
||
− | elseif _type == 'mount' then |
||
− | id_text = 'Internal [[Mount IDs|Mount ID]]: ' |
||
− | elseif _type == 'buff' or _type == 'debuff' then |
||
− | id_text = 'Internal [[Buff IDs|Buff ID]]: ' |
||
− | elseif _type == 'projectile' then |
||
− | id_text = 'Internal [[Projectile IDs|Projectile ID]]: ' |
||
− | elseif _type == 'armor' then |
||
− | id_text = 'Internal [[Armor IDs|Armor ID]]: ' |
||
− | else |
||
− | id_text = 'Internal [[Item IDs|Item ID]]: ' |
||
− | if output_image and image_for_cargo then |
||
− | frame:expandTemplate{ title = 'Item/cargo', args = {name=_arg1, image=image_for_cargo, id=_id} } |
||
− | end |
||
end |
end |
||
+ | local id_text = getIdText(idtype) |
||
− | content = content .. mw.text.tag('div', {class='id'}, id_text .. _id) |
||
+ | content = content .. '<div class="id">' .. id_text .. _id .. '</div>' |
||
end |
end |
||
end |
end |
||
− | text_output = |
+ | text_output = '<span>' .. content .. '</span>' |
+ | else |
||
+ | text_output = '' |
||
end |
end |
||
− | local _class = getArg('class') |
+ | local _class, _css = getArg('class'), getArg('css') |
− | local _css = getArg('css') |
||
− | |||
− | |||
if _class then |
if _class then |
||
class = class .. ' ' .. _class |
class = class .. ' ' .. _class |
||
211. sor: | 345. sor: | ||
end |
end |
||
− | local anchor = '' |
||
if getArg('anchor') then |
if getArg('anchor') then |
||
− | + | text_output = text_output .. '<div class="anchor" id="' .. frame:callParserFunction('anchorencode', _arg1) .. '"></div>' |
|
end |
end |
||
if output_table then |
if output_table then |
||
− | attr.class = class |
+ | attr.class = class |
− | local |
+ | local rowspan = getArg('rowspan') |
+ | return (rowspan and (' rowspan='..rowspan..' class="il1c" | ') or ' class="il1c" | ') .. mw.text.tag('span', attr, image_output) .. ' || class="il2c"'.. (rowspan and (' rowspan='..rowspan) or '')..' | ' .. mw.text.tag('span', attr, text_output) |
||
− | attr.class = class .. ' block alignleft' |
||
− | return result .. mw.text.tag('span', attr, text_output .. anchor) |
||
else |
else |
||
− | return mw.text.tag('span', attr, image_output .. text_output |
+ | return mw.text.tag('span', attr, image_output .. text_output) |
end |
end |
||
− | end |
+ | end, |
+ | |||
+ | } |
A lap jelenlegi, 2020. június 3., 06:14-kori változata
------- l10n info --------------
local l10n_info = mw.loadData('Module:Item/l10n')
------- The following is not related to l10n. --------------
local trim = mw.text.trim
local cargo = mw.ext.cargo
local eicons = require('Module:Exclusive').simpleEicons
local currentFrame
local args_table
local lang
local l10n_table
local l10n = function(key)
return l10n_table[key] or l10n_info['en'][key]
end
local getArg = function(key)
local value = args_table[key]
if not value then
return nil
end
value = trim(value)
if value == '' then
return nil
end
return value
end
-- credit: http://richard.warburton.it
-- this version is with trim.
local function explode(div,str)
if (div=='') then return false end
local pos,arr = 0,{}
-- for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
arr[#arr + 1] = trim(string.sub(str,pos,st-1)) -- Attach chars left of current divider
pos = sp + 1 -- Jump past current divider
end
arr[#arr + 1] = trim(string.sub(str,pos)) -- Attach chars right of last divider
return arr
end
local function parseSize(size)
if not size then return end
local basescale, width, height
size, basescale = unpack(explode('*', size))
if size ~= '' then
width, height = unpack(explode('x', string.gsub(size, 'px', '')))
width, height = tonumber(width), tonumber(height)
if width == 0 then width = nil end
if height == 0 then height = nil end
end
return basescale, width, height
end
local function getInfoFromCargo(image)
-- try to get from cargo cache
local result = mw.ext.cargo.query('Imageinfo', 'width, height, cached', {
where = 'image='.. "'"..image:gsub("'", "\\'"):gsub("'", "\\'").."'",
orderBy = "cached DESC",
limit = 1,
})
for _, row in ipairs(result) do
return tonumber(row['width']), tonumber(row['height']), row['cached']
end
end
local function storeInfoToCargo(image)
local width, height
width = tonumber(currentFrame:callParserFunction( '#imgw', image))
if width and width ~= 0 then -- save one expensive call when the file is not a valid image.
height = tonumber(currentFrame:callParserFunction( '#imgh', image))
if height and height ~= 0 then
currentFrame:callParserFunction('#cargo_store:_table=Imageinfo',{
image = image,
width = width,
height = height,
cached = os.time(),
})
end
end
return width, height
end
local function getSizeInfo(image)
local width, height, cached = getInfoFromCargo(image)
-- cache missed, init cache
if not cached then
width, height = storeInfoToCargo(image)
end
if width == 0 then width = nil end
if height == 0 then height = nil end
return width, height
end
local function getImageSize(image, width, height, scale, maxwidth, maxheight)
-- get size info from image file itself (may be expensive)
local w, h = getSizeInfo(image) -- store data to cache
if not width and not height and (scale or maxwidth or maxheight) then
width, height = w, h
end
-- apply scale to width/height if needed
if scale then
if width then width = width * scale end
if height then height = height * scale end
end
-- apply maxwidth/maxheight.
if maxwidth then
if width then
if width > maxwidth then width = maxwidth end
else
if height then width = maxwidth end
end
end
if maxheight then
if height then
if height > maxheight then height = maxheight end
else
if width then height = maxheight end
end
end
-- rounding
if width then width = math.ceil(width) end
if height then height = math.ceil(height) end
return width, height
end
local function parseMaxSize(maxsize)
if not maxsize then return end
local maxwidth, maxheight = unpack(explode('x', string.gsub(maxsize, 'px', '')))
maxwidth, maxheight = tonumber(maxwidth), tonumber(maxheight)
if maxwidth == 0 then maxwidth = nil end
if maxheight == 0 then maxheight = nil end
return maxwidth, maxheight
end
local function imagecode(image, link, text, size, scale, maxsize)
local image_output = '[[File:' .. image .. '|link='.. link .. '|' .. text
if size or scale or maxsize then
local basescale, width, height = parseSize(size) -- width,height: number or nil
scale = (tonumber(scale) or 1) * (tonumber(basescale) or 1)
if scale == 0 or scale == 1 then
scale = nil
end
local maxwidth, maxheight = parseMaxSize(maxsize)
width, height = getImageSize(image, width, height, scale, maxwidth, maxheight) -- can be 0
if width or height then
return image_output .. '|' .. (width or '') .. 'x' .. (height or '') .. 'px]]'
else
return image_output .. ']]'
end
else
return image_output .. ']]'
end
end
local function images(image, link, text, size, scale, maxsize)
if not image:find('/') then
return imagecode(image, link, text, size, scale, maxsize)
end
image = explode('/', image)
local result = ''
if size and size:find('/') then
size = explode('/', size)
for i, v in ipairs(image) do
result = result .. imagecode(v, link, text, size[i], scale, maxsize)
end
else
for i, v in ipairs(image) do
result = result .. imagecode(v, link, text, size, scale, maxsize)
end
end
return result
end
local getIdText = function(_type)
local id_text
if _type == 'item' then -- a shortcut for faster
id_text = l10n('id_text_item')
elseif _type == 'tile' then
id_text = l10n('id_text_tile')
elseif _type == 'wall' then
id_text = l10n('id_text_wall')
elseif _type == 'npc' then
id_text = l10n('id_text_npc')
elseif _type == 'mount' then
id_text = l10n('id_text_mount')
elseif _type == 'buff' or _type == 'debuff' then
id_text = l10n('id_text_buff')
elseif _type == 'projectile' then
id_text = l10n('id_text_projectile')
elseif _type == 'armor' then
id_text = l10n('id_text_armor')
else
id_text = l10n('id_text_item')
end
return id_text
end
-----------------------------------------------------------------
-- main return object
return {
go = function(frame, args)
-- init cache
currentFrame = frame
args_table = args or frame.args
lang = getArg('lang') or 'en'
l10n_table = l10n_info[lang] or l10n_info['en']
local _arg1 = getArg(1) or ''
local _nolink = getArg('nolink')
local _link = _nolink and '' or getArg('link') or frame:expandTemplate{ title = 'tr', args = {_arg1, link='y'} } -- now: _link == '' means nolink.
local text = getArg(2) or ''
local hovertext
if _arg1 ~= '' then
hovertext = frame:expandTemplate{ title = 'tr', args = {_arg1} }
elseif text ~= '' then
hovertext = text
else
hovertext = _link
end
local class = 'i'
local output_image, output_text, output_table = true, true, false
local _mode = getArg('mode')
if _mode then
if _mode == 'image' or _mode == 'imageonly' or _mode =='onlyimage' then
output_text = false
elseif _mode == 'text' or _mode == 'noimage' then
output_image = false
elseif _mode == 'table' or _mode == '2-cell' then
output_table = true
end
end
local image_output, text_output
if output_image then
local image_arg = string.gsub(_arg1, ":%s*", " ")
if _arg1 == '1/2 Second Timer' then
image_arg = '1 2 Second Timer'
elseif _arg1 == '1/4 Second Timer' then
image_arg = '1 4 Second Timer'
end
image_arg = getArg('image') or image_arg .. '.' .. (getArg('ext') or 'png')
image_output = images(image_arg, _link, hovertext, getArg('size'), getArg('scale'), getArg('maxsize'))
else
image_output = ''
end
if output_text then
local _note, _note2, _showid, _id = getArg('note'), getArg('note2'), getArg('showid'), getArg('id')
if _id and not _showid then
_showid = true
end
if _showid and (_showid == 'n' or _showid == 'no') then
_showid = false
end
local _wrap
if _showid or _note2 then
_wrap = false
else
_wrap = getArg('wrap')
end
if _link ~= '' then
if text == _link then
text = '<span>[['..text..']]</span>'
else
text = '<span>[['.._link..'|'..text..']]</span>'
end
else
text = '<span title="'..hovertext..'">'..text..'</span>'
end
local _icon, icon = getArg('icons'), nil
if _icon == 'n' or _icon == 'no' or _icon == 'off' then
icon = ''
else
icon = eicons(getArg('epage') or _arg1, lang, (_showid or _note2 or _wrap or getArg('small')) and 'y')
end
local content = text -- item name link text first.
-- '-w' class means 'wrapmode', optimized for multiple lines of text. But it should be disabled for single line text.
if _wrap then
-- eicons in the same line
if icon ~= '' then
class = class .. ' -w'
content = content .. icon
end
-- note in next line
if _note then
class = class .. ' -w'
content = content .. '<span class="note">' .. _note .. '</span>'
end
else
-- note first
if _note then
content = content .. '<span class="note">' .. _note .. '</span>'
end
if icon ~= '' then
content = content .. icon
end
if _note2 then
class = class .. ' -w'
content = content .. '<div class="note">' .. _note2 .. '</div>'
end
if _showid then
class = class .. ' -w'
local idtype = (getArg('type') or 'item'):lower()
if not _id then
_id = frame:expandTemplate{ title = idtype .. 'IdFromName', args = {_arg1} }
end
local id_text = getIdText(idtype)
content = content .. '<div class="id">' .. id_text .. _id .. '</div>'
end
end
text_output = '<span>' .. content .. '</span>'
else
text_output = ''
end
local _class, _css = getArg('class'), getArg('css')
if _class then
class = class .. ' ' .. _class
end
local attr = {class = class}
if _css then
attr.style = _css
end
if getArg('anchor') then
text_output = text_output .. '<div class="anchor" id="' .. frame:callParserFunction('anchorencode', _arg1) .. '"></div>'
end
if output_table then
attr.class = class
local rowspan = getArg('rowspan')
return (rowspan and (' rowspan='..rowspan..' class="il1c" | ') or ' class="il1c" | ') .. mw.text.tag('span', attr, image_output) .. ' || class="il2c"'.. (rowspan and (' rowspan='..rowspan) or '')..' | ' .. mw.text.tag('span', attr, text_output)
else
return mw.text.tag('span', attr, image_output .. text_output)
end
end,
}