Difference between revisions of "Module:OInfobox-Building"

Jump to navigation Jump to search
m
no edit summary
m
m
Line 20: Line 20:
         return box
         return box
     end
     end
   
 
     local imageDiv = mw.html.create('div')
     local imageDiv = mw.html.create('div')
     imageDiv:addClass('infobox-image')
     imageDiv:addClass('infobox-image')
   
 
     local fileName = image or defaultImage
     local fileName = image or defaultImage
     local fileWiki = '[[File:' .. fileName .. '|260px|frameless]]'
     local fileWiki = '[[File:' .. fileName .. '|260px|frameless]]'
   
 
     imageDiv:wikitext(fileWiki)
     imageDiv:wikitext(fileWiki)
   
 
     if caption or defaultCaption then
     if caption or defaultCaption then
         imageDiv:tag('span')
         imageDiv:tag('span')
Line 34: Line 34:
             :wikitext(caption or defaultCaption)
             :wikitext(caption or defaultCaption)
     end
     end
   
 
     box:node(imageDiv)
     box:node(imageDiv)
     return box
     return box
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
   
 
    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
   
     local rowClass = 'infobox-row'
     local rowClass = 'infobox-row'
     if columnCount then
     if columnCount then
         rowClass = rowClass .. ' data-rows-' .. columnCount
         rowClass = rowClass .. ' data-rows-' .. columnCount
     end
     end
   
 
     local rowContainer = mw.html.create('div')
     local rowContainer = mw.html.create('div')
     rowContainer:addClass(rowClass)
     rowContainer:addClass(rowClass)
   
 
     for _, item in ipairs(data) do
     for _, item in ipairs(data) do
         local dataRow = createDataRow(item.label, item.value, item.defaultValue)
         local dataRow = createDataRow(item.label, item.value, item.defaultValue)
Line 90: Line 90:
         end
         end
     end
     end
   
 
     box:node(rowContainer)
     box:node(rowContainer)
     return box
     return box
end
end


--[[
--[[Levrin:
I left next section, that I commented "Start" and "End," in here in case you all needed or wanted it (blame Pelendur if it's bad.....just kidding (maybe) :p)
I left next section, that I commented "Start" and "End," in here in case you all needed or wanted it (blame Pelendur if it's bad.....just kidding (maybe) :p)
It seemed to be in other templates, and I didn't want to remove it if it was needed or useful to you all. ]]--
It seemed to be in other templates, and I didn't want to remove it if it was needed or useful to you all. ]]--


-- Start
-- Start
local function createIconRow(iconName, value)  
local function createIconRow(iconName, value)
     if not value then
     if not value then
         return nil
         return nil
     end
     end
   
 
     local label = i.icon(iconName, nil, nil, com.firstUpper({iconName}), 'en')
     local label = i.icon(iconName, nil, nil, com.firstUpper({iconName}), 'en')
     return createDataRow(label, value)
     return createDataRow(label, value)
Line 112: Line 112:
function p.building(frame)
function p.building(frame)
     local args = a.getArgs(frame)
     local args = a.getArgs(frame)
   
 
     local titleArg = args['title']
     local titleArg = args['title']
     local currentTitle = mw.title.getCurrentTitle().text
     local currentTitle = mw.title.getCurrentTitle().text
     local building = com.modulePagename(titleArg or currentTitle)
     local building = com.modulePagename(titleArg or currentTitle)
   
 
     local buildingData = require('Module:BuildingIndex')[string.lower(building)]
     local buildingData = require('Module:BuildingIndex')[string.lower(building)]
   
 
     local infobox = createInfobox(building)
     local infobox = createInfobox(building)
       
 
     addImage(infobox, args['image'], args['caption'], buildingData and buildingData.defaultImage, buildingData and buildingData.defaultCaption)
     addImage(infobox, args['image'], args['caption'], buildingData and buildingData.defaultImage, buildingData and buildingData.defaultCaption)
   
 
     if buildingData then
     if buildingData then
--SECTION-PRODUCTION
        --SECTION-PRODUCTION
         local productionData = {}
         local productionData = {}
         if buildingData.employees then
         if buildingData.employees then
Line 148: Line 148:
                 end
                 end
             end
             end
           
 
             if com.exists(input) then
             if com.exists(input) then
                 table.insert(productionData, {label = 'Consumes', value = input})
                 table.insert(productionData, {label = 'Consumes', value = input})
             end
             end
         end
         end
       
 
         if buildingData.output then
         if buildingData.output then
             local output = ''
             local output = ''
Line 162: Line 162:
                 end
                 end
             end
             end
           
 
             if com.exists(output) then
             if com.exists(output) then
                 table.insert(productionData, {label = 'Produces', value = output})
                 table.insert(productionData, {label = 'Produces', value = output})
             end
             end
         end
         end
       
 
         if #productionData > 0 then
         if #productionData > 0 then
             addSection(infobox, productionData, 'Production', 2) -- The 2 means 2 columns, it can add more or less
             addSection(infobox, productionData, 'Production', 2) -- The 2 means 2 columns, it can add more or less
         end
         end
         --/
         --/
--SECTION-PREQUISITES
        --SECTION-PREQUISITES
         local prereqData = {}
         local prereqData = {}
       
 
         if buildingData.building then
         if buildingData.building then
             table.insert(prereqData, {label = 'Building', value = buildingData.building})
             table.insert(prereqData, {label = 'Building', value = buildingData.building})
         end
         end
       
 
         if buildingData.population then
         if buildingData.population then
             table.insert(prereqData, {label = 'Population', value = buildingData.population})
             table.insert(prereqData, {label = 'Population', value = buildingData.population})
         end
         end
       
 
         if buildingData.influence then
         if buildingData.influence then
             for type, value in pairs(buildingData.influence) do
             for type, value in pairs(buildingData.influence) do
Line 188: Line 188:
             end
             end
         end
         end
       
 
         if buildingData.splendor then
         if buildingData.splendor then
             for type, value in pairs(buildingData.splendor) do
             for type, value in pairs(buildingData.splendor) do
Line 194: Line 194:
             end
             end
         end
         end
--/
        --/
        ---SECTION-UNLOCKING
        ---SECTION-UNLOCKING
         if buildingData.influence then
         if buildingData.influence then
             local unlockData = {}
             local unlockData = {}
            local first = true;
             for resource, amount in pairs(buildingData.influence) do
             for resource, amount in pairs(buildingData.influence) do
                local displayAmount = amount
                if first and buildingData.influence.tier then
                    displayAmount = displayAmount  .. ' ' .. buildingData.influence.tier
                    first = false;
                end
                 local resourceIcon = i.icon(resource, nil, nil, com.firstUpper({resource}), 'en')
                 local resourceIcon = i.icon(resource, nil, nil, com.firstUpper({resource}), 'en')
                 table.insert(unlockData, {label = resourceIcon, value = amount})
                 table.insert(unlockData, {label = resourceIcon, value = displayAmount})
             end
             end
           
 
             if #unlockData > 0 then
             if #unlockData > 0 then
                 addSection(infobox, unlockData, 'Unlocking Conditions', 2)
                 addSection(infobox, unlockData, 'Unlocking Conditions', 2)
Line 215: Line 221:
                 table.insert(constructionData, {label = resourceIcon, value = amount})
                 table.insert(constructionData, {label = resourceIcon, value = amount})
             end
             end
           
 
             if #constructionData > 0 then
             if #constructionData > 0 then
                 addSection(infobox, constructionData, 'Construction Resources', 2)
                 addSection(infobox, constructionData, 'Construction Resources', 2)
Line 223: Line 229:
         --SECTION-RUNNING-COSTS
         --SECTION-RUNNING-COSTS
         local costData = {}
         local costData = {}
       
 
         if buildingData.maintenance then
         if buildingData.maintenance then
             local maintenanceLabel = i.icon('maintenance cost', nil, nil, 'Maintenance Cost', 'en')
             local maintenanceLabel = i.icon('maintenance cost', nil, nil, 'Maintenance Cost', 'en')
             table.insert(costData, {label = maintenanceLabel, value = buildingData.maintenance})
             table.insert(costData, {label = maintenanceLabel, value = buildingData.maintenance})
         end
         end
       
 
         if buildingData.tax then
         if buildingData.tax then
             local taxLabel = i.icon('coin', nil, nil, 'Tax', 'en')
             local taxLabel = i.icon('coin', nil, nil, 'Tax', 'en')
             table.insert(costData, {label = taxLabel, value = buildingData.tax})
             table.insert(costData, {label = taxLabel, value = buildingData.tax})
         end
         end
       
 
         if #costData > 0 then
         if #costData > 0 then
             addSection(infobox, costData, 'Running Costs')
             addSection(infobox, costData, 'Running Costs')
         end
         end
--/
        --/
     end
     end
     --/
     --/
606

edits

Navigation menu