Module:Furniture
Jump to navigation
Jump to search
The Lua source code for the display of furnitures through {{Furniture}}.
local p = {}
local data = {
misc = mw.loadData('Module:Furniture/misc'),
plaque = mw.loadData('Module:Furniture/plaque'),
standalone = mw.loadData('Module:Furniture/standalone'),
theme = mw.loadData('Module:Furniture/theme'),
}
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local rates = {
[0] = {bg='#FFCF00', color='#000', text='3 Stars'},
[1] = {bg='#313131', color='#FFF', text='Guaranteed'},
[2] = {bg='#707070', color='#FFF', text='Common'},
[3] = {bg='#7A7A7A', color='#FFF', text='Uncommon'},
[4] = {bg='#DDDDDD', color='#000', text='Rare'},
[5] = {bg='#A40000', color='#FFF', text='Very Rare'},
[6] = {bg='#01B3FC', color='#FFF', text='First Clear'},
}
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local key = args[1]
local qty = tonumber(args[2])
if not key then return ' <i>Furniture not found</i> ' end
local furn
for k, v in pairs(data) do
furn = v[key]
if furn then
break
end
end
if not furn then return ' <i>Furniture not found</i> ' end
local nolink = yesno(args.nolink)
local link = nolink and '' or args[1]
local name = furn.name or args[1]
local text = furn.title or furn.name
local attrs = {
['data-name'] = furn.name,
['data-title'] = furn.title,
['data-use'] = furn.use or "Used in the dorm to improve the ambience.",
['data-desc'] = furn.desc,
['data-ambience'] = furn.ambience,
['data-cat'] = furn.cat,
['data-theme'] = furn.theme,
['data-set'] = furn.set,
['data-obtain'] = furn.obtain,
['data-firstdrop'] = furn.firstdrop,
['data-regdrop'] = furn.regdrop,
}
local gridview = yesno(args.gridview)
if gridview == nil then
gridview = true
end
local root = mw.html.create('')
if gridview then
local rate = rates[tonumber(args.rate)]
local wrapper = root:tag('div')
:css{
['display'] = 'inline-block',
['position'] = 'relative',
['margin'] = '5px',
}
if rate then
local rateDiv = wrapper:tag('div')
:css{
['font-size'] = 'xx-small',
['text-align'] = 'center',
['padding'] = '1px 2px',
['margin-bottom'] = '0.5em',
['border-radius'] = '3px',
['background'] = rate.bg,
['color'] = rate.color,
}
:wikitext(rate.text)
end
local furniture = wrapper:tag('div')
:addClass('furniture')
local inner = furniture:tag('div')
:addClass('inner')
:addClass(({'furniture-r1', 'furniture-r2'})[tonumber(furn.r) or 2])
local a = inner:tag('div')
:addClass('a')
local tt = a:tag('div')
:addClass('furniture-tooltip')
:attr(attrs)
:wikitext(('[[File:%s.png|70px|link=%s]]'):format(name, link))
if qty then
local qtyDiv = wrapper:tag('div')
:css{position='absolute', right=0, bottom=0}
qtyDiv:tag('div')
:css{
['padding'] = '0 5px',
['background'] = 'rgba(0,0,0,0.8)',
['box-shadow'] = '0 0 2px #000',
['color'] = '#FFF',
['font-size'] = '12px',
['text-shadow'] = '-1px 0 #000, 0 1px #000, 1px 0 #000, 0 -1px #000',
['cursor'] = 'default',
}
:wikitext(qty)
end
else
local wrapper = root:tag('span')
:css('display', 'inline-block')
if qty then
wrapper:wikitext(qty..' ')
end
local tt = wrapper:tag('span')
:addClass('furniture-tooltip')
:attr(attrs)
:wikitext(nolink and text or link == text and ('[[%s]]'):format(link) or ('[[%s|%s]]'):format(link, text))
end
return root
end
return p