Module:Bestiary tables
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:Bestiary tables/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Bestiary tables/doc. [edit]
Module:Bestiary tables requires Module:DPL scroll.
Module:Bestiary tables requires Module:Paramtest.
Module:Bestiary tables loads data from Module:Weakness clickpic/data.
| Function list |
|---|
| L 12 — get_copy L 20 — make_row L 21 — checkWeak L 100 — p.row L 104 — get L 191 — make_link |
-- <nowiki>
local p = {}
local pt = require('Module:Paramtest')
local hc = pt.has_content
local dt = pt.default_to
local weaknessmap = mw.loadData('Module:Weakness clickpic/data')
local dplscroll = require('Module:DPL scroll')._main
-- shallow copy of a table, only for use on a basic primitive=primitive table, like url query
-- use mw.clone() for deep copy
local function get_copy(t)
local r = {}
for i,v in pairs(t) do
r[i] = v
end
return r
end
local function make_row(info)
local function checkWeak(v)
local wkarr = {
melee = {
['Weak to melee attacks'] = true,
['Weak to stab attacks'] = true,
['Weak to slash attacks'] = true,
['Weak to crush attacks'] = true,
},
magic = {
['Weak to magic attacks'] = true,
['Weak to air spells'] = true,
['Weak to water spells'] = true,
['Weak to earth spells'] = true,
['Weak to fire spells'] = true,
},
ranged = {
['Weak to ranged attacks'] = true,
['Weak to arrows'] = true,
['Weak to bolts'] = true,
['Weak to thrown weapons'] = true,
},
none = {
['Weak to nothing'] = true,
}
}
local wf = info.weakFilter
if wf == 'any' then
return true
end
if wkarr[wf][v] then
return true
end
return false
end
local lang = mw.getContentLanguage()
local ret = '\n|-\n| [[' .. info.name .. ']]'
if info.version then
ret = ret .. ' <small>' .. info.version .. '</small>'
end
local weakness = mw.text.split(string.lower(info.weakness or ''),'%s*,%s*')
local wkstr = {}
local wkfound = false
for _, v in ipairs(weakness) do
v = weaknessmap[v]
if v then
wkfound = wkfound or checkWeak(v.category)
table.insert(wkstr, string.format('[[File:%s|25px|link=%s]]',v.image,v.link))
end
end
if not wkfound then
return ''
end
weakness = table.concat(wkstr, ' ')
local lp = '?'
if info.lifepoints then
if tonumber(info.lifepoints) then
lp = lang:formatNum(tonumber(info.lifepoints))
else
lp = info.lifepoints
end
end
ret = ret .. string.format('\n| %s\n| %s\n| %s\n| %s',
info.combat or '?',
lp,
info.members or '?',
weakness or '?')
return ret
end
function p.row(frame)
local a = frame:getParent().args
local a2 = frame.args
local function get(q, v, cont)
local ret = dt(a[q..v], a[q])
local doll = ret and ret:match('%$(%d+)')
if not cont and doll then
ret = get(p, doll, true)
end
return ret
end
-- fetch some variables from the page
local cbmin, cbmax, memFilt, weakFilt
cbmin = tonumber(a2.cbmin)
cbmax = tonumber(a2.cbmax)
memFilt = tonumber(dt(a2.members, 0))
weakFilt = dt(a2.weakness, 'any')
if not cbmin then
local vars = frame:preprocess('{{#dplvar:cbmin}},{{#dplvar:cbmax}},{{#dplvar:members}},{{#dplvar:weakness}}')
vars = mw.text.split(vars, ',')
cbmin = tonumber(vars[1])
cbmax = tonumber(vars[2])
memFilt = tonumber(dt(vars[3], 0))
weakFilt = dt(vars[4], 'any')
end
local ret = ''
local i = 1
if hc(a.version1) then
while hc(a['version'..i]) do
local cb, weak, memb = get('level', i), get('weakness', i), get('members', i)
local ok = true
if tonumber(cb) < cbmin or tonumber(cb) > cbmax then
ok = false
end
if ok and memFilt ~= 0 then
if (memFilt == 1 and memb:lower() == 'yes') or
(memFilt == 2 and memb:lower() == 'no') then
ok = false
end
end
if ok then
ret = ret .. make_row({
name = a['%TITLE%'],
version = a['version'..i],
combat = cb,
lifepoints = get('lifepoints', i),
members = memb,
weakness = weak,
weakFilter = weakFilt
})
end
i = i + 1
end
else
ret = make_row({
name = a['%TITLE%'],
combat = a.level,
lifepoints = a.lifepoints,
members = a.members,
weakness = a.weakness,
weakFilter = 'any'
})
end
return ret
end
-- creates navigation links at the top of the table
-- combat classes, members/free to play, restriction, augmentation, tierless, tier range search
-- page navigation
-- changing filter resets to first page
-- changing page preserves filters
p.filters = function(frame)
local a = frame:getParent().args
local title = mw.title.getCurrentTitle()
local table = mw.html.create('table')
local query = { action = 'purge', DPL_offset = 0 }
local thcss = {} -- {['border-top'] = '1px dashed black'}
local css = { ['background-color'] = '#e5e5e5', padding = '0.1em 0.7em 0.2em 0.7em' } --, ['border-top'] = '1px dashed black' }
local td, query_working
local boldmem, boldloc = '0', '0'
local boldweakness = 'any'
local sep = ' • '
local function make_link(td_, link, query_new, bold)
td_:css(css)
if bold then
td_:wikitext("'''" .. link .. "'''")
else
td_:wikitext(string.format('[%s %s]', title:fullUrl(query_new), link))
end
end
-- setup base query
if hc(a.mems) then
query.members = a.mems
boldmem = a.mems
end
if hc(a.weakness) then
query.weakness = a.weakness
boldweakness = string.lower(a.weakness)
end
if hc(a.loc) then
query.loc = a.loc
boldloc = a.loc
end
if hc(a.useskin) then
query.useskin = a.useskin
end
table:addClass('dplequipmenttable')
:css('text-align', 'left')
-- total reset
td = table:tag('tr'):tag('th')
:wikitext('Reset filters')
:done()
:tag('td')
query_working = {action = 'purge'}
if hc(a.useskin) then
query_working.useskin = a.useskin
end
make_link(td, 'Reset', query_working, false)
-- membership status links
td = table:tag('tr'):tag('th'):css(thcss)
:wikitext('Membership')
:done()
:tag('td')
query_working = get_copy(query)
query_working.members = '0'
make_link(td, 'All', query_working, boldmem == '0')
td:wikitext(sep)
query_working.members = '1'
make_link(td, 'Members only', query_working, boldmem == '1')
td:wikitext(sep)
query_working.members = '2'
make_link(td, 'Free-to-play only', query_working, boldmem == '2')
-- weakness links
td = table:tag('tr'):tag('th'):css(thcss)
:wikitext('Weakness')
:done()
:tag('td')
query_working = get_copy(query)
query_working.weakness = 'any'
make_link(td, 'Any', query_working, boldweakness == 'any')
td:wikitext(sep)
query_working.class = 'melee'
make_link(td, 'Melee', query_working, boldweakness == 'melee')
td:wikitext(sep)
query_working.class = 'magic'
make_link(td, 'Magic', query_working, boldweakness == 'magic')
td:wikitext(sep)
query_working.class = 'ranged'
make_link(td, 'Ranged', query_working, boldweakness == 'ranged')
td:wikitext(sep)
query_working.class = 'none'
make_link(td, 'None', query_working, boldweakness == 'none')
td = table:tag('tr'):tag('th'):css(thcss)
:wikitext('Restriction')
:done()
:tag('td')
query_working = get_copy(query)
query_working.loc = '0'
make_link(td, 'All', query_working, boldloc == '0')
td:wikitext(sep)
query_working.loc = '1'
make_link(td, 'Surface only', query_working, boldloc == '1')
td:wikitext(sep)
query_working.loc = '2'
make_link(td, 'Daemonheim only', query_working, boldloc == '2')
-- pagination
--separate from filters by a bit
table:tag('tr'):tag('td'):attr('colspan','2'):wikitext(' '):done():done()
local pages_b, pages = dplscroll({
total = a.total,
count = a.count,
offset = a.offset,
query = query
})
table:tag('tr'):tag('td'):attr('colspan','2'):wikitext(string.format("'''Total results: %s'''", a.total)):done():done()
-- only show pagination if there are pages to show
if pages_b then
table:tag('tr')
:tag('th')
:wikitext('Pages')
:done()
:tag('td')
:css(css)
:node(pages)
:done()
:done()
end
return tostring(table)
end
return p
