« Module:Fiche de créature » : différence entre les versions

1 142 octets enlevés ,  13 février 2022
aucun résumé des modifications
Kharmitch (discussion | contributions)
mAucun résumé des modifications
Kharmitch (discussion | contributions)
Aucun résumé des modifications
 
(6 versions intermédiaires par le même utilisateur non affichées)
Ligne 28 : Ligne 28 :
if not value then
if not value then
value = part.defaultvalue
value = part.defaultvalue
end
if not value then
return nil
if value == nil then
end
return nil
end
end
Ligne 43 : Ligne 42 :
function p.buildlist(part)
function p.buildlist(part)
local title = part.title
local title = part.title
local items = part.items
local prefix = part.prefix
if not title or not items then
local maxitems = part.max
if not title or not prefix or not maxitems then
return nil
return nil
end
end


-- create items
-- create items
local expandeditems = {}
local items = {}
for k, row in ipairs(items) do
for i = 1, maxitems do
local v = p.buildblock(row)
local v = p.builditem({ value = prefix..i })
if v then
if not v then
table.insert(expandeditems, v)
break
end
end
table.insert(items, v)
end
end
if (#expandeditems == 0) then
if #items == 0 then
return nil
return nil
end
end
items = expandeditems


-- create list
-- create list
Ligne 115 : Ligne 116 :
local rows = part.rows
local rows = part.rows
-- expand parameters so that we have a list of tables
if not rows then
local i = 1
return nil
 
end
while (i <= #rows) do
local l = rows[i]
if type(l) == 'function' then
l = l(localdata, localdata.item)
end
if (type(l) == 'table') and (l.type == 'multi') then
table.remove(rows, i) 
for j, row in ipairs(l.rows) do
table.insert(rows, i + j - 1, row)
end
elseif type(l) == 'nil' then
table.remove(rows, i)
elseif type(l) ~= 'table' then
return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l))
else
i = i + 1
end
end  


-- CREATE ROW
-- CREATE ROW
Ligne 169 : Ligne 152 :
tab:allDone()
tab:allDone()
return tab
return tab
end
function builddescription()
imageFilename = localdata['image'] or ''
imageUpright = localdata['upright'] or '1'
description = localdata['description'] or ''
text = '[[Fichier:'..imageFilename..'|frameless|center|upright='..imageUpright..']]'
text = text..'\n'..description..'\n'
description = mw.html.create('div')
:addClass('creature-card-description')
:wikitext(text)
:done()
return tostring(description)
end
end


Ligne 197 : Ligne 164 :
['row'] = p.buildrow,
['row'] = p.buildrow,
['list'] = p.buildlist,
['list'] = p.buildlist,
['item'] = p.builditem,
}
}
Ligne 210 : Ligne 176 :
moduledata.name = localdata.modulename
moduledata.name = localdata.modulename
local data = mw.html.create('div')
local card = mw.html.create('div')
:addClass('creature-card-data')
for i, j in pairs(moduledata.parts) do
for i, j in pairs(moduledata.parts) do
data:node(p.buildblock(j))
card:node(p.buildblock(j))
end
end
-- construction de la fiche
local card = mw.html.create('div')
:addClass('creature-card')
:node(builddescription())
:node(data)
return tostring(card)
return tostring(card)
end
end


return p
return p
Bureaucrate, commentadmin, emailconfirmed, Administrateurs d’interface, staff, Administrateur
62 734

modifications