Difference between revisions of "Module:OInfobox-Building"

Jump to navigation Jump to search
m
no edit summary
m
m
Tag: Undo
Line 43: Line 43:
         return box
         return box
     end
     end
 
   
     if header then
     if header then
         box:tag('div')
         box:tag('div')
Line 50: Line 50:
             :done()
             :done()
     end
     end
 
   
     local function createDataRow(label, value, defaultValue)
     local function createDataRow(label, value, defaultValue)
        if not value and not defaultValue then
    if not value and not defaultValue then
            return nil
        return nil
        end
 
        local dataRow = mw.html.create('div')
        dataRow:addClass('infobox-data-section')
 
        if label then
            dataRow:tag('span')
                :addClass('infobox-label')
                :wikitext(label)
                :done()
            :tag('span')
                :addClass('infobox-data')
                :wikitext(value or defaultValue)
        else
            dataRow:tag('span')
                :addClass('infobox-data')
                :wikitext(value or defaultValue)
        end
 
        return dataRow
     end
     end
 
   
     if columnCount and columnCount > 1 then
     local dataRow = mw.html.create('div')
        local row = box:tag('div'):addClass('infobox-row')
    dataRow:addClass('infobox-data-section')
        for i, item in ipairs(data) do
   
            local label = (header == 'Construction Requirements') and nil or item.label
    if label then
            local dataDiv = createDataRow(label, item.value, item.label) -- Pass icon as defaultValue if no label
        dataRow:tag('span')
            if dataDiv then
            :addClass('infobox-label')
                row:tag('div'):addClass('infobox-data-item'):node(dataDiv):done()
            :wikitext(label)
                if i % columnCount == 0 and i < #data then
            :done()
                    row = box:tag('div'):addClass('infobox-row'):done()
        :tag('span')
                end
            :addClass('infobox-data')
             end
             :wikitext(value or defaultValue)
        end
        if row.parent == box then
            row:done()
        end
     else
     else
         for _, item in ipairs(data) do
         dataRow:tag('span')
             local label = (header == 'Construction Requirements') and nil or item.label
            :addClass('infobox-data')
            local dataRow = createDataRow(label, item.value, item.label) -- Pass icon as defaultValue if no label
             :wikitext(value or defaultValue)
            if dataRow then
    end
                box:node(dataRow)
   
            end
    return dataRow
end
   
    local rowClass = 'infobox-row'
    if columnCount then
        rowClass = rowClass .. ' data-rows-' .. columnCount
    end
   
    local rowContainer = mw.html.create('div')
    rowContainer:addClass(rowClass)
   
    for _, item in ipairs(data) do
        local dataRow = createDataRow(item.label, item.value, item.defaultValue)
        if dataRow then
            rowContainer:node(dataRow)
         end
         end
     end
     end
 
   
    box:node(rowContainer)
     return box
     return box
end
end
Line 225: Line 216:
             for resource, amount in pairs(buildingData.construction) do
             for resource, amount in pairs(buildingData.construction) do
                 local resourceIcon = i.icon(resource, amount, nil, com.firstUpper({resource}), 'en')
                 local resourceIcon = i.icon(resource, amount, nil, com.firstUpper({resource}), 'en')
                 table.insert(constructionData, { label = resourceIcon, value = amount })
                 table.insert(constructionData, { label = resourceIcon })
             end
             end


606

edits

Navigation menu