Module:BuildingInfoboxGenerator: Difference between revisions

From Corsair Cove Official Wiki
Dorce (talk | contribs)
mNo edit summary
Dorce (talk | contribs)
No edit summary
 
(18 intermediate revisions by the same user not shown)
Line 5: Line 5:


function p.makeInfobox(frame)
function p.makeInfobox(frame)
     -- Get the building name from the template parameter
     local name = frame.args.name or mw.title.getCurrentTitle().text
     local name = frame.args[1]
     local description_param = frame.args.description or ""
 
    local unlock1_param = frame.args.unlocked_by_1 or ""
     -- Or automatically use the current page name:
     local unlock2_param = frame.args.unlocked_by_2 or ""
     -- local name = mw.title.getCurrentTitle().text
     local unlock3_param = frame.args.unlocked_by_3 or ""


     -- Find the building in the data table
     -- Find the building in the data table
Line 20: Line 20:
     -- Pass the data to your existing template
     -- Pass the data to your existing template
     return frame:expandTemplate{
     return frame:expandTemplate{
         title = "Building Infobox",
         title = "Building infobox",
         args = {
         args = {
             name = b.name,
             name = b.name,
Line 26: Line 26:
             category = b.category,
             category = b.category,
             theme = b.theme,
             theme = b.theme,
             description = b.description,
             description = "''" .. description_param ..  "''",
           
             unlocked_by_1 = unlock1_param,
             unlocked_by_1 = b.unlocked_by_1,
             unlocked_by_2 = unlock2_param,
             unlocked_by_2 = b.unlocked_by_2,
             unlocked_by_3 = unlock3_param,
             unlocked_by_3 = b.unlocked_by_3,
           
            housing = b.housing,
              
              
            hands_builders = b.hands_builders,
housing = b.housing ~= 0 and b.housing or nil,
            hands_fetchers = b.hands_fetchers,
            hands_masterhands = b.hands_masterhands,
hands_builders = b.hands_builders ~= 0 and b.hands_builders or nil,
hands_fetchers = b.hands_fetchers ~= 0 and b.hands_fetchers or nil,
hands_greenhands = b.hands_greenhands ~= 0 and b.hands_greenhands or nil,
hands_masterhands = b.hands_masterhands ~= 0 and b.hands_masterhands or nil,
              
              
             hands_upkeep_1 = b.hands_upkeep_1,
             hands_upkeep_1 = b.hands_upkeep_1,
Line 51: Line 51:
             construction_3 = b.construction[3] and b.construction[3].resource,
             construction_3 = b.construction[3] and b.construction[3].resource,
             construction_3_qty = b.construction[3] and b.construction[3].qty,
             construction_3_qty = b.construction[3] and b.construction[3].qty,
             --construction_4 = b.construction[4] and b.construction[4].resource,
             construction_4 = b.construction[4] and b.construction[4].resource,
             --construction_4_qty = b.construction[4] and b.construction[4].qty,
             construction_4_qty = b.construction[4] and b.construction[4].qty,
             --construction_5 = b.construction[5] and b.construction[5].resource,
             construction_5 = b.construction[5] and b.construction[5].resource,
             --construction_5_qty = b.construction[5] and b.construction[5].qty,
             construction_5_qty = b.construction[5] and b.construction[5].qty,
             --construction_6 = b.construction[6] and b.construction[6].resource,
             construction_6 = b.construction[6] and b.construction[6].resource,
             --construction_6_qty = b.construction[6] and b.construction[6].qty,
             construction_6_qty = b.construction[6] and b.construction[6].qty,
              
              
             construction_requires_fertile_area = b.construction_requires_fertile_area,
             construction_requires_fertile_area = b.construction_requires_fertile_area,
              
              
             production_input_1 = b.production_input[1] and b.production_input[1].resource,
             production_input_1 = b.production_input[1]  
            production_input_1_qty = b.production_input[1] and b.production_input[1].qty,
    and b.production_input[1].qty ~= 0
            production_input_2 = b.production_input[2] and b.production_input[2].resource,
    and b.production_input[1].resource  
            production_input_2_qty = b.production_input[2] and b.production_input[2].qty,
    or nil,
production_input_1_qty = b.production_input[1]  
    and b.production_input[1].qty ~= 0
    and b.production_input[1].qty  
    or nil,
production_input_2 = b.production_input[2]  
    and b.production_input[2].qty ~= 0
    and b.production_input[2].resource  
    or nil,
production_input_2_qty = b.production_input[2]  
    and b.production_input[2].qty ~= 0
    and b.production_input[2].qty  
    or nil,
   
             production_output = b.production_output,
             production_output = b.production_output,
             production_output_qty = b.production_output_qty,
             production_output_qty = b.production_output_qty,
Line 71: Line 87:
             production_booster_2 = b.production_booster_2,
             production_booster_2 = b.production_booster_2,
              
              
             production_output_storage = b.production_output_storage,
             production_output_storage = 2 * b.production_output_qty,
           
            community_upkeep_1 = b.community_upkeep[1]
            and b.community_upkeep[1].qty ~= 0
    and b.community_upkeep[1].resource
    or nil,
community_upkeep_1_qty = b.community_upkeep[1]
            and b.community_upkeep[1].qty ~= 0
    and b.community_upkeep[1].qty
    or nil,
           
            community_upkeep_2 = b.community_upkeep[2]
            and b.community_upkeep[2].qty ~= 0
    and b.community_upkeep[2].resource
    or nil,
community_upkeep_2_qty = b.community_upkeep[2]
            and b.community_upkeep[2].qty ~= 0
    and b.community_upkeep[2].qty
    or nil,
           
            community_upkeep_3 = b.community_upkeep[3]
            and b.community_upkeep[3].qty ~= 0
    and b.community_upkeep[3].resource
    or nil,
community_upkeep_3_qty = b.community_upkeep[3]
            and b.community_upkeep[3].qty ~= 0
    and b.community_upkeep[3].qty
    or nil,
              
              
             community_upkeep_1 = b.community_upkeep_1,
             community_upkeep_4 = b.community_upkeep[4]
            community_upkeep_1_qty = b.community_upkeep_1_qty,
            and b.community_upkeep[4].qty ~= 0
            community_upkeep_2 = b.community_upkeep_2,
    and b.community_upkeep[4].resource
            community_upkeep_2_qty = b.community_upkeep_2_qty,
    or nil,
            community_upkeep_3 = b.community_upkeep_3,
            community_upkeep_3_qty = b.community_upkeep_3_qty,
community_upkeep_4_qty = b.community_upkeep[4]
            community_upkeep_4 = b.community_upkeep_4,
            and b.community_upkeep[4].qty ~= 0
            community_upkeep_4_qty = b.community_upkeep_4_qty,
    and b.community_upkeep[4].qty
    or nil,
         }
         }
     }
     }

Latest revision as of 09:57, 11 August 2026

This module uses data from Module:BuildingData to call the Template:Building infobox and display building information in a rich, stylized format.


local p = {}

-- Load your data table once
local data = mw.loadData("Module:BuildingData")

function p.makeInfobox(frame)
    local name = frame.args.name or mw.title.getCurrentTitle().text
    local description_param = frame.args.description or ""
    local unlock1_param = frame.args.unlocked_by_1 or ""
    local unlock2_param = frame.args.unlocked_by_2 or ""
    local unlock3_param = frame.args.unlocked_by_3 or ""

    -- Find the building in the data table
    local b = data[name]

    if not b then
        return "No data found for '" .. tostring(name) .. "'"
    end

    -- Pass the data to your existing template
    return frame:expandTemplate{
        title = "Building infobox",
        args = {
            name = b.name,
            building_icon_filename = b.building_icon_filename,
            category = b.category,
            theme = b.theme,
            description = "''" .. description_param ..  "''",
            unlocked_by_1 = unlock1_param,
            unlocked_by_2 = unlock2_param,
            unlocked_by_3 = unlock3_param,
            
			housing = b.housing ~= 0 and b.housing or nil,
			
			hands_builders = b.hands_builders ~= 0 and b.hands_builders or nil,
			hands_fetchers = b.hands_fetchers ~= 0 and b.hands_fetchers or nil,
			hands_greenhands = b.hands_greenhands ~= 0 and b.hands_greenhands or nil,
			hands_masterhands = b.hands_masterhands ~= 0 and b.hands_masterhands or nil,
            
            hands_upkeep_1 = b.hands_upkeep_1,
            hands_upkeep_1_qty = b.hands_upkeep_1_qty,
            hands_upkeep_2 = b.hands_upkeep_2,
            hands_upkeep_2_qty = b.hands_upkeep_2_qty,
            hands_upkeep_3 = b.hands_upkeep_3,
            hands_upkeep_3_qty = b.hands_upkeep_3_qty,

            construction_1 = b.construction[1] and b.construction[1].resource,
            construction_1_qty = b.construction[1] and b.construction[1].qty,
            construction_2 = b.construction[2] and b.construction[2].resource,
            construction_2_qty = b.construction[2] and b.construction[2].qty,
            construction_3 = b.construction[3] and b.construction[3].resource,
            construction_3_qty = b.construction[3] and b.construction[3].qty,
            construction_4 = b.construction[4] and b.construction[4].resource,
            construction_4_qty = b.construction[4] and b.construction[4].qty,
            construction_5 = b.construction[5] and b.construction[5].resource,
            construction_5_qty = b.construction[5] and b.construction[5].qty,
            construction_6 = b.construction[6] and b.construction[6].resource,
            construction_6_qty = b.construction[6] and b.construction[6].qty,
            
            construction_requires_fertile_area = b.construction_requires_fertile_area,
            
            production_input_1 = b.production_input[1] 
			    and b.production_input[1].qty ~= 0 
			    and b.production_input[1].resource 
			    or nil,
			
			production_input_1_qty = b.production_input[1] 
			    and b.production_input[1].qty ~= 0 
			    and b.production_input[1].qty 
			    or nil,
			
			production_input_2 = b.production_input[2] 
			    and b.production_input[2].qty ~= 0 
			    and b.production_input[2].resource 
			    or nil,
			
			production_input_2_qty = b.production_input[2] 
			    and b.production_input[2].qty ~= 0 
			    and b.production_input[2].qty 
			    or nil,
			    
            production_output = b.production_output,
            production_output_qty = b.production_output_qty,
            
            production_base_per_min = b.production_base_per_min,
            production_booster_1 = b.production_booster_1,
            production_booster_2 = b.production_booster_2,
            
            production_output_storage = 2 * b.production_output_qty,
            
            community_upkeep_1 = b.community_upkeep[1]
            	and b.community_upkeep[1].qty ~= 0 
			    and b.community_upkeep[1].resource 
			    or nil,
			
			community_upkeep_1_qty = b.community_upkeep[1]
            	and b.community_upkeep[1].qty ~= 0 
			    and b.community_upkeep[1].qty 
			    or nil,
            
            community_upkeep_2 = b.community_upkeep[2]
            	and b.community_upkeep[2].qty ~= 0 
			    and b.community_upkeep[2].resource 
			    or nil,
			
			community_upkeep_2_qty = b.community_upkeep[2]
            	and b.community_upkeep[2].qty ~= 0 
			    and b.community_upkeep[2].qty 
			    or nil,
            
            community_upkeep_3 = b.community_upkeep[3]
            	and b.community_upkeep[3].qty ~= 0 
			    and b.community_upkeep[3].resource 
			    or nil,
			
			community_upkeep_3_qty = b.community_upkeep[3]
            	and b.community_upkeep[3].qty ~= 0 
			    and b.community_upkeep[3].qty 
			    or nil,
            
            community_upkeep_4 = b.community_upkeep[4]
            	and b.community_upkeep[4].qty ~= 0 
			    and b.community_upkeep[4].resource 
			    or nil,
			
			community_upkeep_4_qty = b.community_upkeep[4]
            	and b.community_upkeep[4].qty ~= 0 
			    and b.community_upkeep[4].qty 
			    or nil,
        }
    }
end

return p