Difference between revisions of "Module:OInfobox-Building"

Jump to navigation Jump to search
m
no edit summary
m
m
 
(68 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- adapted from Levrin's iteration to Sakaratte's original --
-- adapted by Olessan from Levrin's iteration to Sakaratte's original --
-- Layout changed and all labels, etc, updated to pull from Module:BuildingINdex --
-- I may expand later to have functions for other infobox types (but this game doesn't really need any other?? 22/04/2025 --
local com = require('Module:Common')
local com = require('Module:Common')
local a = require('Module:Arguments')
local a = require('Module:Arguments')
Line 15: Line 17:
end
end


local function addImage(box, image, caption, defaultImage, defaultCaption)
local function addImage(box, image, defaultImage)
     if not image and not defaultImage then
     if not image and not defaultImage then
         box:wikitext('[[Category:Image Needed]]')
         box:wikitext('[[Category:Image Needed]]')
Line 28: Line 30:


     imageDiv:wikitext(fileWiki)
     imageDiv:wikitext(fileWiki)
    if caption or defaultCaption then
        imageDiv:tag('span')
            :addClass('infoboxCaption')
            :wikitext(caption or defaultCaption)
    end


     box:node(imageDiv)
     box:node(imageDiv)
Line 51: Line 47:
     end
     end


    local function createDataRow(label, value, defaultValue)
        local function createDataRow(label, value, defaultValue)
         if not value and not defaultValue then
        local actualValue = value or defaultValue
 
         if not actualValue or actualValue == '' then  
             return nil
             return nil
         end
         end
Line 66: Line 64:
             :tag('span')
             :tag('span')
                 :addClass('infobox-data')
                 :addClass('infobox-data')
                 :wikitext(value or defaultValue)
                 :wikitext(actualValue)
         else
         else
             dataRow:tag('span')
             dataRow:tag('span')
                 :addClass('infobox-data')
                 :addClass('infobox-data')
                 :wikitext(value or defaultValue)
                 :wikitext(actualValue)
         end
         end


Line 121: Line 119:
     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'], buildingData and buildingData.defaultImage, buildingData and buildingData.defaultCaption)


     if buildingData then
     if buildingData then
Line 195: Line 193:
         end
         end
         --/
         --/
        ---SECTION-UNLOCKING
        --SECTION-UNLOCKING
         if buildingData.influence then
         if buildingData.influence then
            local unlockData = {}
        local unlockData = {}
            local first = true;
        local first = true
            for resource, amount in pairs(buildingData.influence) do
          for resource, amount in pairs(buildingData.influence) do
                local displayAmount = amount
          if resource ~= 'tier' and resource ~= 'bsplendour' then -- Exclude 'tier' and 'bsplendour'
                if first and buildingData.influence.tier then
            local displayAmount = amount
                    displayAmount = displayAmount .. ' ' .. buildingData.influence.tier
            if first and buildingData.influence.tier then
                    first = false;
              displayAmount = displayAmount .. ' ' .. buildingData.influence.tier
                end
              first = false
                local resourceIcon = i.icon(resource, nil, nil, com.firstUpper({resource}), 'en')
          end
local tierPosition = string.find(displayAmount, "tier", nil, true) -- Find the last occurrence of "tier"
          local resourceIcon = i.icon(resource, nil, nil, com.firstUpper({resource}), 'en')
          local tierPosition = string.find(displayAmount, "tier", nil, true)
if tierPosition then
       
  local beforeTier = string.sub(displayAmount, 1, tierPosition - 1)
            if tierPosition then
  local theTier = string.sub(displayAmount, tierPosition)
              local beforeTier = string.sub(displayAmount, 1, tierPosition - 1)
  table.insert(unlockData, {label = resourceIcon, value = beforeTier .. "(" .. theTier .. ")"})
              local theTier = string.sub(displayAmount, tierPosition)
else
              table.insert(unlockData, {label = resourceIcon, value = beforeTier .. "(" .. theTier .. ")"})
  table.insert(unlockData, {label = resourceIcon, value = displayAmount})
            else
end
              table.insert(unlockData, {label = resourceIcon, value = displayAmount})
end
            end
 
            if #unlockData > 0 then
                addSection(infobox, unlockData, 'Unlocking Conditions', 2)
             end
             end
        end
          end
       
          if #unlockData > 0 then
            addSection(infobox, unlockData, 'Unlocking Conditions', 2)
          end
          end
         --/
         --/
         ---SECTION-CONSTRUCTION
         ---SECTION-CONSTRUCTION
Line 236: Line 236:
         --/
         --/
         --SECTION-RUNNING-COSTS
         --SECTION-RUNNING-COSTS
        local costData = {}
local costData = {}
local goldCoinsFound = false


         if buildingData.maintenance then
    if buildingData.costs or buildingData.influence['bsplendour'] then
             local maintenanceLabel = i.icon('maintenance cost', nil, nil, 'Maintenance Cost', 'en')
         for resource, amount in pairs(buildingData.costs) do
            table.insert(costData, {label = maintenanceLabel, value = buildingData.maintenance})
            if resource == 'gold coins' then
                local resourceIcon = i.icon('gold coins', nil, nil, 'gold coins', 'en')
                table.insert(costData, {label = '[[File:Gold Coins.png|frameless|20x20px]] ' .. '[[Gold Coins|Build Cost]]', value = amount})
                goldCoinsFound = true
            elseif resource ~= 'maintenance' then
                local resourceIcon = i.icon(resource, nil, nil, com.firstUpper({resource}), 'en')
                table.insert(costData, {label = resourceIcon, value = amount})
            end
            if resource ~= 'maintenance' then
            local displayAmount = amount
            if second and buildingData.costs.maintenance then
              displayAmount = displayAmount .. ' ' .. buildingData.costs.maintenance
              second = false
              end
          end
        end
       
        if buildingData.costs and buildingData.costs['maintenance'] then
             local resourceIcon = i.icon('maintenance', nil, nil, 'maintenance', 'en')
            table.insert(costData, {label = resourceIcon, value = '[[File:Gold Coins.png|frameless|20x20px]] ' .. buildingData.costs['maintenance'] .. ' monthly'})
         end
         end


         if buildingData.tax then
         if buildingData.influence['bsplendour'] then
             local taxLabel = i.icon('coin', nil, nil, 'Tax', 'en')
             local resourceIcon = i.icon('bsplendour', nil, nil, 'splendor', 'en')
            table.insert(costData, {label = taxLabel, value = buildingData.tax})
            table.insert(costData, {label = '[[File:Splendor.png|frameless|20x20px]] ' .. '[[Splendour|Splendour]]', value = '+ ' .. buildingData.influence['bsplendour'] .. ' ea'})
         end
         end


         if #costData > 0 then
         if #costData > 0 then
             addSection(infobox, costData, 'Running Costs')
             addSection(infobox, costData, 'Economic Impact', 2)
        end
         end
         end
        --/
     end
     end
     --/
     --/
606

edits

Navigation menu