Module:BuildingInfoboxGenerator: Difference between revisions
From Corsair Cove Official Wiki
mNo edit summary |
Added new function |
||
| Line 8: | Line 8: | ||
local name = frame.args[1] | local name = frame.args[1] | ||
-- | -- 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 ~= 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 = 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 | |||
function p.makeThisInfobox(frame) | |||
-- Automatically use the current page name: | |||
local name = mw.title.getCurrentTitle().text | |||
-- Find the building in the data table | -- Find the building in the data table | ||
Revision as of 09:04, 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]
-- 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 ~= 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 = 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
function p.makeThisInfobox(frame)
-- 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 ~= 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 = 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


