Module:BuildingInfoboxGenerator: Difference between revisions

From Corsair Cove Official Wiki
Dorce (talk | contribs)
Created Infobox Generator
 
Dorce (talk | contribs)
mNo edit summary
Line 4: Line 4:
local data = mw.loadData("Module:BuildingData")
local data = mw.loadData("Module:BuildingData")


function p.build(frame)
function p.makeInfobox(frame)
     -- Get the building name from the template parameter
     -- Get the building name from the template parameter
     local name = frame.args[1]
     local name = frame.args[1]
Line 60: Line 60:
             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,
             production_input_1 = b.production_input[1] and b.production_input[1].resource,
             production_input_1_qty = b.production_input_1_qty,
             production_input_1_qty = b.production_input[1] and b.production_input[1].qty,
             production_input_2 = b.production_input_2,
             production_input_2 = b.production_input[2] and b.production_input[2].resource,
             production_input_2_qty = b.production_input_2_qty,
             production_input_2_qty = b.production_input[2] and b.production_input[2].qty,
             production_output = b.production_output,
             production_output = b.production_output,
             production_output_qty = b.production.output_qty,
             production_output_qty = b.production.output_qty,

Revision as of 07:51, 30 July 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)
    -- Get the building name from the template parameter
    local name = frame.args[1]

    -- Or automatically use the current page name:
    -- local name = mw.title.getCurrentTitle().text

    -- 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 = b.description,
            
            unlocked_by_1 = b.unlocked_by_1,
            unlocked_by_2 = b.unlocked_by_2,
            unlocked_by_3 = b.unlocked_by_3,
            
            housing = b.housing,
            
            hands_builders = b.hands_builders,
            hands_fetchers = b.hands_fetchers,
            hands_masterhands = b.hands_masterhands,
            
            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].resource,
            production_input_1_qty = b.production_input[1] and b.production_input[1].qty,
            production_input_2 = b.production_input[2] and b.production_input[2].resource,
            production_input_2_qty = b.production_input[2] and b.production_input[2].qty,
            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 = b.production_output_storage,
            
            community_upkeep_1 = b.community_upkeep_1,
            community_upkeep_1_qty = b.community_upkeep_1_qty,
            community_upkeep_2 = b.community_upkeep_2,
            community_upkeep_2_qty = b.community_upkeep_2_qty,
            community_upkeep_3 = b.community_upkeep_3,
            community_upkeep_3_qty = b.community_upkeep_3_qty,
            community_upkeep_4 = b.community_upkeep_4,
            community_upkeep_4_qty = b.community_upkeep_4_qty,
        }
    }
end

return p