Module:Buildingbox: Difference between revisions

From Against the Storm Official Wiki
(fixing wrong italics. keeping single quotes)
(Overwriting old Buildingbox with new Buildingbox2 code)
Line 1: Line 1:
---
---
--- Module to create an infobox for displaying on a building's wiki page.
--- Retrieves data for the specified building, resource, perk, etc. and sends the data over to the view, another template.
---
--- Shows the facts from the data about the specified building in an easy-to-
--- read table, with a large icon, information, categories, and the flavor
--- text.
---
--- This should be invoked from Template:Buildingbox with the parameter of the
--- building whose infobox should be shown. See the template documentation for
--- more information about parameters and errors and to see examples.
---
---
--- @module Buildingbox
--- @module Buildingbox
Line 15: Line 7:




local StyleUtils = require("Module:StyleUtils")
--region Dependencies
 
--Some dependencies in this module are loaded lazily, but we want them scoped to the entire module, not their local functions
local WorkshopsData
local InstitutionsData
local FarmsData
local CampsData
local CollectorsData


local Infobox = require("Module:Infobox")
local ViewTemplate = "Template:Infobox"


local WorkshopsData = require("Module:WorkshopsData")
--endregion
local InstitutionsData = require("Module:InstitutionsData")
local CampsData = require("Module:CampsData")
local FarmsData = require("Module:FarmsData")
local CollectorsData = require("Module:CollectorsData")




Line 29: Line 24:
--region Private constants
--region Private constants


local ARGS = {
local ARG_NAME = "name"
["name"] = "name",
 
["purpose"] = "purpose",
local PARAM_TITLE = "title"
["species_preference"] = "species_preference",
local PARAM_SUBTITLE = "subtitle"
["specializations"] = "specializations",
local PARAM_DESCRIPTION = "description"
}
local PARAM_SPECIALIZATION = "specialization"
local PARAM_ICON_FILENAME = "iconfilename"
local PARAM_MOVABLE = "movable"
local PARAM_WORKPLACES = "workplaces"
local PARAM_STORAGE = "storage"
local PARAM_RECIPES = "recipes"
local PARAM_CONSTRUCTION_COST = "construction"
local PARAM_CITY_SCORE = "cityscore"
local PARAM_CONSTRUCTION_TIME = "constructiontime"
local PARAM_CONSTRUCTION_SIZE = "constructionsize"
local PARAM_ID = "id"


--endregion
--endregion
Line 42: Line 47:
--region Private methods
--region Private methods


---
---renderSpecializations takes the ID of a building and looks up its specializations, calls external view templates to convert those specializations into usable content strings for display, and returns those strings concatenated together for display by the calling scope.
--- Shortcut method to expand a template with parameters
---@param id string the unique ID of the building
---
---@return string a content string ready for display
---@param buildingName string the name of the building
local function renderSpecializations(id)
---@return string html markup returned by the template
 
local function expandRecipeList(buildingName)
    local SpecializationsData = mw.loadData("Module:SpecializationsData")
    local SpeciesData = mw.loadData("Module:SpeciesData")
    local frame = mw.getCurrentFrame()


return mw.getCurrentFrame():expandTemplate{ title="Recipe", args={
    local listOfSpecializationsAtBuilding = SpecializationsData.buildingSpecializations[id]
building= buildingName, display="list" } }
end


    if not listOfSpecializationsAtBuilding then
        return nil
    end


    local concatenatedStrings = ""
    for _, specIndex in ipairs(listOfSpecializationsAtBuilding) do


---
        -- Specialization link first
--- Shortcut method since the size methods return two values.
        local specData = SpecializationsData.specializations[specIndex]
---
        local specializationString = frame:expandTemplate{
---@param buildingName string the name of the building to check
            title = "Specialization",
---@return number, number the X and Y sizes
            args = {
local function distributeSizes(buildingName)
                ["iconfilename"] = specData[SpecializationsData.ICON_FILENAME],
                ["name"] = specData[SpecializationsData.NAME],
                ["type"] = specData[SpecializationsData.IS_COMFORTABLE] and "Comfort" or "Proficiency",
                ["size"] = "small",
            }, }


local sizeX, sizeY = WorkshopsData.getWorkshopSize(buildingName)
        -- Species link second, but just the icon
if sizeX and sizeY then return sizeX, sizeY end
        local species = specData[SpecializationsData.SPECIES]
        local speciesString = frame:expandTemplate{
            title = "Species",
            args = {
                ["iconfilename"] = SpeciesData.species[species][SpeciesData.ICON_FILENAME] .. ".png",
                ["name"] = SpeciesData.species[species][SpeciesData.NAME],
                ["size"] = "small",
                [1] = "notext",
            }, }


sizeX, sizeY = InstitutionsData.getInstitutionSize(buildingName)
        -- Separate multiple entries with line break
if sizeX and sizeY then return sizeX, sizeY end
        if #concatenatedStrings > 1 then
            concatenatedStrings = concatenatedStrings .. "<br />"
        end


sizeX, sizeY = CampsData.getCampSize(buildingName)
        concatenatedStrings = concatenatedStrings .. specializationString .. "&nbsp;" .. speciesString
if sizeX and sizeY then return sizeX, sizeY end
    end


sizeX, sizeY = FarmsData.getFarmSize(buildingName)
    if #concatenatedStrings < 1 then
if sizeX and sizeY then return sizeX, sizeY end
        return "None"
    end


sizeX, sizeY = CollectorsData.getCollectorSize(buildingName)
    return concatenatedStrings
return sizeX, sizeY
end
end






-- Building interface:
-- getCategory
-- getCityScore
-- getConstructionCosts (as [goodName] = stack size)
-- getConstructionTime
-- getDescription
-- getIcon
-- isMovable
-- getName
-- getNumberOfWorkplaces
-- getSize (as "X x Y")
-- getStorage
local function buildViewParameters(id, buildingInterface, subtitlePrefix)


    local frame = mw.getCurrentFrame()
    local viewParameters = {}
    viewParameters[PARAM_TITLE] = buildingInterface.getName(id)
    viewParameters[PARAM_SUBTITLE] = subtitlePrefix .. " (" .. buildingInterface.getCategory(id) .. ")"
    viewParameters[PARAM_DESCRIPTION] = buildingInterface.getDescription(id)
    viewParameters[PARAM_SPECIALIZATION] = renderSpecializations(id)
    viewParameters[PARAM_ICON_FILENAME] = buildingInterface.getIcon(id)
    viewParameters[PARAM_MOVABLE] = buildingInterface.isMovable(id) and "true"
    viewParameters[PARAM_WORKPLACES] = buildingInterface.getNumberOfWorkplaces(id)
    viewParameters[PARAM_RECIPES] = frame:expandTemplate{ title = "Recipe", args = { ["building"] = buildingInterface.getName(id), ["display"] = "list", }, }
    viewParameters[PARAM_STORAGE] = buildingInterface.getStorage(id)
    viewParameters[PARAM_CONSTRUCTION_COST] = frame:expandTemplate{ title = "Construction", args = buildingInterface.getConstructionCosts(id) }
    viewParameters[PARAM_CITY_SCORE] = buildingInterface.getCityScore(id)
    viewParameters[PARAM_CONSTRUCTION_TIME] = buildingInterface.getConstructionTime(id)
    viewParameters[PARAM_CONSTRUCTION_SIZE] = buildingInterface.getSize(id)
    viewParameters[PARAM_ID] = id
    return viewParameters
end


---
--- Builds using the provided wikiInfobox a few header items.
---
---@param wikiInfobox table mw.html object into which we're building this
---@param buildingName string the name of the building the infobox is about
---@return table the Mediawiki html object into which we've been adding things
local function makeHeaderContent(wikiInfobox, buildingName)


-- Grab the data we'll use to populate this.
local description = WorkshopsData.getWorkshopDescription(buildingName)
or InstitutionsData.getInstitutionDescription(buildingName)
or CampsData.getCampDescription(buildingName)
or FarmsData.getFarmDescription(buildingName)
or CollectorsData.getCollectorDescription(buildingName)
local iconFilename = WorkshopsData.getWorkshopIcon(buildingName)
or InstitutionsData.getInstitutionIcon(buildingName)
or CampsData.getCampIcon(buildingName)
or FarmsData.getFarmIcon(buildingName)
or CollectorsData.getCollectorIcon(buildingName)


-- Start the header area
local function tryWorkshopsData(name)
local header = Infobox.startNewHeader(wikiInfobox)


Infobox.makeTitle(header, buildingName)
    WorkshopsData = require("Module:WorkshopsData")
Infobox.makeFlavorText(header, description)
Infobox.makeTitleIcon(header, iconFilename)


return wikiInfobox
    local id = WorkshopsData.getWorkshopID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, WorkshopsData, "Production Building")
    end
end
end


local function tryInstitutionsData(name)


    InstitutionsData = require("Module:InstitutionsData")


---
    local id = InstitutionsData.getInstitutionID(name)
--- Builds using the provided wikiInfobox a subtable to lay out headers and
    if not id then
--- fields.
        return false
---
    else
---@param wikiInfobox table mw.html object into which we're building this
        return buildViewParameters(id, InstitutionsData, "Service Building")
---@param buildingName string the name of the good the infobox is about
    end
---@param params table of template parameters
end
---@return table the Mediawiki html object into which we've been adding things
local function makeInnerContent(wikiInfobox, buildingName, params)


-- Grab the data we'll use to populate this.
local function tryFarmsData(name)
local category = WorkshopsData.getWorkshopCategory(buildingName)
or InstitutionsData.getInstitutionCategory(buildingName)
or CampsData.getCampCategory(buildingName)
or FarmsData.getFarmCategory(buildingName)
or CollectorsData.getCollectorCategory(buildingName)
local recipesTable = WorkshopsData.getAllWorkshopRecipes(buildingName)
or InstitutionsData.getAllInstitutionRecipes(buildingName)
or CampsData.getAllCampRecipes(buildingName)
or FarmsData.getAllFarmRecipes(buildingName)
or CollectorsData.getAllCollectorRecipes(buildingName)
local isMovable = WorkshopsData.isWorkshopMovable(buildingName)
or InstitutionsData.isInstitutionMovable(buildingName)
or CampsData.isCampMovable(buildingName)
or FarmsData.isFarmMovable(buildingName)
or CollectorsData.isCollectorMovable(buildingName)
local isEssential = WorkshopsData.isWorkshopInitiallyEssential(buildingName)
or InstitutionsData.isInstitutionInitiallyEssential(buildingName)
or CampsData.isCampInitiallyEssential(buildingName)
or FarmsData.isFarmInitiallyEssential(buildingName)
or CollectorsData.isCollectorInitiallyEssential(buildingName)
local sizeX, sizeY = distributeSizes(buildingName)
local range = CampsData.getCampArea(buildingName)
-- Workshops and
-- Institutions don't have a range/area
or FarmsData.getFarmArea(buildingName)
-- Collectors don't have a range
local storageCap = WorkshopsData.getWorkshopStorage(buildingName)
-- Institutions don't have storage
or CampsData.getCampStorage(buildingName)
or FarmsData.getFarmStorage(buildingName)
or CollectorsData.getCollectorStorage(buildingName)
local numWorkplaces = WorkshopsData.getWorkshopNumberOfWorkplaces(buildingName)
or InstitutionsData.getInstitutionNumberOfWorkplaces(buildingName)
or CampsData.getCampNumberOfWorkplaces(buildingName)
or FarmsData.getFarmNumberOfWorkplaces(buildingName)
or CollectorsData.getCollectorNumberOfWorkplaces(buildingName)
local constructionTime = WorkshopsData.getWorkshopConstructionTime(buildingName)
or InstitutionsData.getInstitutionConstructionTime(buildingName)
or CampsData.getCampConstructionTime(buildingName)
or FarmsData.getFarmConstructionTime(buildingName)
or CollectorsData.getCollectorConstructionTime(buildingName)
local constructionGoods = WorkshopsData.getAllWorkshopRequiredGoods(buildingName)
or InstitutionsData.getAllInstitutionRequiredGoods(buildingName)
or CampsData.getAllCampRequiredGoods(buildingName)
or FarmsData.getAllFarmRequiredGoods(buildingName)
or CollectorsData.getAllCollectorRequiredGoods(buildingName)
local buildingID = WorkshopsData.getWorkshopID(buildingName)
or InstitutionsData.getInstitutionID(buildingName)
or CampsData.getCampID(buildingName)
or FarmsData.getFarmID(buildingName)
or CollectorsData.getCollectorID(buildingName)


-- Start the inner table
    FarmsData = require("Module:FarmsData")
local innerTable = Infobox.startNewInnerTable(wikiInfobox)


-- we'll reuse this to mark where separators are needed in the table
    local id = FarmsData.getFarmID(name)
local needsSeparator = false
    if not id then
        return false
    else
        return buildViewParameters(id, FarmsData, "Farm")
    end
end


-- Start with the things from the parameters, if any
local function tryCampsData(name)
for paramTitle, paramValue in pairs(params or {}) do
if paramTitle ~= nil and paramValue ~= nil then
Infobox.makeInnerRow(innerTable, paramValue, false,
Infobox.toTitleCase(paramTitle), paramValue)
-- Require a separator if there were any parameters.
needsSeparator = true
end
end


needsSeparator = Infobox.makeInnerRow(innerTable, category, needsSeparator,
    CampsData = require("Module:CampsData")
Infobox.TITLE_CATEGORY,
Infobox.makeCategoryIcon(category, false) .. StyleUtils.NBSP .. category)
needsSeparator = Infobox.makeInnerRow(innerTable, recipesTable and #recipesTable > 0,
needsSeparator, Infobox.TITLE_RECIPES,
expandRecipeList(buildingName))


needsSeparator = true
    local id = CampsData.getCampID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, CampsData, "Gathering Camp")
    end
end


needsSeparator = Infobox.makeInnerRow(innerTable, isMovable, needsSeparator,
local function tryCollectorsData(name)
Infobox.TITLE_MOVABLE, isMovable and "Yes" or "No")
needsSeparator = Infobox.makeInnerRow(innerTable, isEssential, needsSeparator,
Infobox.TITLE_ESSENTIAL, isEssential and "Yes" or "No")
needsSeparator = Infobox.makeInnerRow(innerTable, sizeX and sizeY,
needsSeparator, Infobox.TITLE_SIZE, sizeX .. " × " .. sizeY)
needsSeparator = Infobox.makeInnerRow(innerTable, range, needsSeparator,
Infobox.TITLE_RANGE, range)
needsSeparator = Infobox.makeInnerRow(innerTable, storageCap, needsSeparator,
Infobox.TITLE_STORAGE_CAPACITY, storageCap)


needsSeparator = true
    CollectorsData = require("Module:CollectorsData")


needsSeparator = Infobox.makeInnerRow(innerTable, numWorkplaces, needsSeparator,
    local id = CollectorsData.getCollectorID(name)
Infobox.TITLE_WORKPLACES, numWorkplaces)
    if not id then
        return false
    else
        return buildViewParameters(id, CollectorsData, "Extraction Building")
    end


needsSeparator = true
end
 
needsSeparator = Infobox.makeInnerRow(innerTable, constructionTime,
needsSeparator, Infobox.TITLE_CONSTRUCTION_TIME,
constructionTime)
needsSeparator = Infobox.makeInnerRow(innerTable, constructionGoods, needsSeparator,
Infobox.TITLE_CONSTRUCTION_COST,
Infobox.writeRequiredGoodsRows(constructionGoods) )


needsSeparator = true


needsSeparator = Infobox.makeInnerRow(innerTable, buildingID, needsSeparator,
---findBoxType
Infobox.TITLE_ID, "'" .. buildingID .. "'")
--- Handles data only, does not interface with the Buildingbox view.
---@param name string the name of the building about which to retrieve data
---@return table the essential data about the building extracted
local function findBoxType(name)


-- Close the inner table, and return it with the passed context
    -- Lazy-load of external data, since it's expensive. Start with the most likely so that most pages load as fast as possible.
Infobox.endInnerTable(wikiInfobox, innerTable)
    local viewParameters = tryWorkshopsData(name)
    if not viewParameters then
        viewParameters = tryInstitutionsData(name)
        if not viewParameters then
            viewParameters = tryFarmsData(name)
            if not viewParameters then
                viewParameters = tryCollectorsData(name)
                if not viewParameters then
                    viewParameters = tryCampsData(name)
                    if not viewParameters then
                        return("No building found with name: " .. name .. ".")
                    end
                end
            end
        end
    end


return wikiInfobox
    return viewParameters
end
end


Line 244: Line 236:
--region Public methods
--region Public methods


---main
--- For calling from Template:Buildingbox. After handling the frame, forwards control to the primary method, findBoxType, then calls the view template with the compiled box data. Does not interface with any data modules.
---
---
--- Creates an html and wiki markup to display the data in an infobox.
---@param frame table the calling template's context
---
---@return string wiki markup, constructed with the template view
--- @param frame table from template's calling context
function Buildingbox.main(frame)
--- @return string of html and wiki markup
 
function Buildingbox.renderBuildingbox(frame)
    local name = frame.args[ARG_NAME]
    if not name then
-- Every building must have a name.
        error("You must specify the name of the building. Please see the template documentation for how to use the parameters.")
local buildingName = frame.args[ARGS.name]
    end
if not buildingName or buildingName == "" then
return "You must specify the name of the building. See [[Template:Buildingbox]] for examples."
end


-- Use this method here to check to see whether the provided name is valid.
    local viewParameters = findBoxType(name)
if not ( WorkshopsData.getWorkshopID(buildingName)
or InstitutionsData.getInstitutionID(buildingName)
or CampsData.getCampID(buildingName)
or FarmsData.getFarmID(buildingName)
or CollectorsData.getCollectorID(buildingName) ) then
return "Buildingbox can't find the specified building: " .. buildingName .. "."
end


-- Additional template parameters, may or may not be present.
    -- Return the message if it's a string, otherwise proceed because it's a table.
local purpose = frame.args[ARGS.purpose]
    if type(viewParameters) == "string" then
local speciesPref = frame.args[ARGS.species_preference]
        return viewParameters
local specializations = frame.args[ARGS.specializations]
    end


local wikiInfobox = Infobox.startNewInfobox()
    return frame:expandTemplate{ title = ViewTemplate, args = viewParameters }
makeHeaderContent(wikiInfobox, buildingName)
makeInnerContent(wikiInfobox, buildingName,
{ [ARGS.purpose] = purpose, [ARGS.species_preference] = speciesPref,
  [ARGS.specializations] = specializations })
return wikiInfobox
end
end



Revision as of 02:53, 9 October 2024

Documentation for this module may be created at Module:Buildingbox/doc

---
--- Retrieves data for the specified building, resource, perk, etc. and sends the data over to the view, another template.
---
--- @module Buildingbox
local Buildingbox = {}



--region Dependencies

--Some dependencies in this module are loaded lazily, but we want them scoped to the entire module, not their local functions
local WorkshopsData
local InstitutionsData
local FarmsData
local CampsData
local CollectorsData

local ViewTemplate = "Template:Infobox"

--endregion



--region Private constants

local ARG_NAME = "name"

local PARAM_TITLE = "title"
local PARAM_SUBTITLE = "subtitle"
local PARAM_DESCRIPTION = "description"
local PARAM_SPECIALIZATION = "specialization"
local PARAM_ICON_FILENAME = "iconfilename"
local PARAM_MOVABLE = "movable"
local PARAM_WORKPLACES = "workplaces"
local PARAM_STORAGE = "storage"
local PARAM_RECIPES = "recipes"
local PARAM_CONSTRUCTION_COST = "construction"
local PARAM_CITY_SCORE = "cityscore"
local PARAM_CONSTRUCTION_TIME = "constructiontime"
local PARAM_CONSTRUCTION_SIZE = "constructionsize"
local PARAM_ID = "id"

--endregion



--region Private methods

---renderSpecializations takes the ID of a building and looks up its specializations, calls external view templates to convert those specializations into usable content strings for display, and returns those strings concatenated together for display by the calling scope.
---@param id string the unique ID of the building
---@return string a content string ready for display
local function renderSpecializations(id)

    local SpecializationsData = mw.loadData("Module:SpecializationsData")
    local SpeciesData = mw.loadData("Module:SpeciesData")
    local frame = mw.getCurrentFrame()

    local listOfSpecializationsAtBuilding = SpecializationsData.buildingSpecializations[id]

    if not listOfSpecializationsAtBuilding then
        return nil
    end

    local concatenatedStrings = ""
    for _, specIndex in ipairs(listOfSpecializationsAtBuilding) do

        -- Specialization link first
        local specData = SpecializationsData.specializations[specIndex]
        local specializationString = frame:expandTemplate{
            title = "Specialization",
            args = {
                ["iconfilename"] = specData[SpecializationsData.ICON_FILENAME],
                ["name"] = specData[SpecializationsData.NAME],
                ["type"] = specData[SpecializationsData.IS_COMFORTABLE] and "Comfort" or "Proficiency",
                ["size"] = "small",
            }, }

        -- Species link second, but just the icon
        local species = specData[SpecializationsData.SPECIES]
        local speciesString = frame:expandTemplate{
            title = "Species",
            args = {
                ["iconfilename"] = SpeciesData.species[species][SpeciesData.ICON_FILENAME] .. ".png",
                ["name"] = SpeciesData.species[species][SpeciesData.NAME],
                ["size"] = "small",
                [1] = "notext",
            }, }

        -- Separate multiple entries with line break
        if #concatenatedStrings > 1 then
            concatenatedStrings = concatenatedStrings .. "<br />"
        end

        concatenatedStrings = concatenatedStrings .. specializationString .. "&nbsp;" .. speciesString
    end

    if #concatenatedStrings < 1 then
        return "None"
    end

    return concatenatedStrings
end



-- Building interface:
-- getCategory
-- getCityScore
-- getConstructionCosts (as [goodName] = stack size)
-- getConstructionTime
-- getDescription
-- getIcon
-- isMovable
-- getName
-- getNumberOfWorkplaces
-- getSize (as "X x Y")
-- getStorage
local function buildViewParameters(id, buildingInterface, subtitlePrefix)

    local frame = mw.getCurrentFrame()

    local viewParameters = {}
    viewParameters[PARAM_TITLE] = buildingInterface.getName(id)
    viewParameters[PARAM_SUBTITLE] = subtitlePrefix .. " (" .. buildingInterface.getCategory(id) .. ")"
    viewParameters[PARAM_DESCRIPTION] = buildingInterface.getDescription(id)
    viewParameters[PARAM_SPECIALIZATION] = renderSpecializations(id)
    viewParameters[PARAM_ICON_FILENAME] = buildingInterface.getIcon(id)
    viewParameters[PARAM_MOVABLE] = buildingInterface.isMovable(id) and "true"
    viewParameters[PARAM_WORKPLACES] = buildingInterface.getNumberOfWorkplaces(id)
    viewParameters[PARAM_RECIPES] = frame:expandTemplate{ title = "Recipe", args = { ["building"] = buildingInterface.getName(id), ["display"] = "list", }, }
    viewParameters[PARAM_STORAGE] = buildingInterface.getStorage(id)
    viewParameters[PARAM_CONSTRUCTION_COST] = frame:expandTemplate{ title = "Construction", args = buildingInterface.getConstructionCosts(id) }
    viewParameters[PARAM_CITY_SCORE] = buildingInterface.getCityScore(id)
    viewParameters[PARAM_CONSTRUCTION_TIME] = buildingInterface.getConstructionTime(id)
    viewParameters[PARAM_CONSTRUCTION_SIZE] = buildingInterface.getSize(id)
    viewParameters[PARAM_ID] = id

    return viewParameters
end



local function tryWorkshopsData(name)

    WorkshopsData = require("Module:WorkshopsData")

    local id = WorkshopsData.getWorkshopID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, WorkshopsData, "Production Building")
    end
end

local function tryInstitutionsData(name)

    InstitutionsData = require("Module:InstitutionsData")

    local id = InstitutionsData.getInstitutionID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, InstitutionsData, "Service Building")
    end
end

local function tryFarmsData(name)

    FarmsData = require("Module:FarmsData")

    local id = FarmsData.getFarmID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, FarmsData, "Farm")
    end
end

local function tryCampsData(name)

    CampsData = require("Module:CampsData")

    local id = CampsData.getCampID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, CampsData, "Gathering Camp")
    end
end

local function tryCollectorsData(name)

    CollectorsData = require("Module:CollectorsData")

    local id = CollectorsData.getCollectorID(name)
    if not id then
        return false
    else
        return buildViewParameters(id, CollectorsData, "Extraction Building")
    end

end


---findBoxType
--- Handles data only, does not interface with the Buildingbox view.
---@param name string the name of the building about which to retrieve data
---@return table the essential data about the building extracted
local function findBoxType(name)

    -- Lazy-load of external data, since it's expensive. Start with the most likely so that most pages load as fast as possible.
    local viewParameters = tryWorkshopsData(name)
    if not viewParameters then
        viewParameters = tryInstitutionsData(name)
        if not viewParameters then
            viewParameters = tryFarmsData(name)
            if not viewParameters then
                viewParameters = tryCollectorsData(name)
                if not viewParameters then
                    viewParameters = tryCampsData(name)
                    if not viewParameters then
                        return("No building found with name: " .. name .. ".")
                    end
                end
            end
        end
    end

    return viewParameters
end

--endregion



--region Public methods

---main
--- For calling from Template:Buildingbox. After handling the frame, forwards control to the primary method, findBoxType, then calls the view template with the compiled box data. Does not interface with any data modules.
---
---@param frame table the calling template's context
---@return string wiki markup, constructed with the template view
function Buildingbox.main(frame)

    local name = frame.args[ARG_NAME]
    if not name then
        error("You must specify the name of the building. Please see the template documentation for how to use the parameters.")
    end

    local viewParameters = findBoxType(name)

    -- Return the message if it's a string, otherwise proceed because it's a table.
    if type(viewParameters) == "string" then
        return viewParameters
    end

    return frame:expandTemplate{ title = ViewTemplate, args = viewParameters }
end

--endregion

return Buildingbox