Module:Structure

From DSRPG
Revision as of 13:21, 4 May 2025 by Dubhghlas (talk | contribs) (Created page with "-- Module:Structure -- Provides enhanced functionality for structure infoboxes local p = {} -- Main entry point for the module function p.infobox(frame) local args = frame.args -- If called via #invoke, get the args from the parent frame if not args or not args[1] then args = frame:getParent().args end -- Initialize HTML output local html = mw.html.create() -- Create the main infobox container local infobox = html:...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

-- Module:Structure
-- Provides enhanced functionality for structure infoboxes

local p = {}

-- Main entry point for the module
function p.infobox(frame)
    local args = frame.args
    
    -- If called via #invoke, get the args from the parent frame
    if not args or not args[1] then
        args = frame:getParent().args
    end
    
    -- Initialize HTML output
    local html = mw.html.create()
    
    -- Create the main infobox container
    local infobox = html:tag('div')
        :addClass('infoboxFrame')
    
    -- Add the title
    local name = args.name or 'Structure Name'
    local color = args.color or '#a2b0c6'
    
    infobox:tag('div')
        :addClass('infoboxHeadTitle')
        :css('background-color', color)
        :wikitext(name)
    
    -- Add image if provided
    if args.image then
        local imageDiv = infobox:tag('div')
            :addClass('infoboxImage')
        
        imageDiv:wikitext(string.format('[[File:%s|300px|%s]]', args.image, name))
        
        if args.caption then
            imageDiv:tag('div')
                :addClass('infoboxCaption')
                :wikitext(args.caption)
        end
    end
    
    -- Function to add a simple row
    local function addRow(label, value)
        if value and value ~= '' then
            local row = infobox:tag('div')
                :addClass('infoboxRow')
            
            row:tag('div')
                :addClass('infoboxLabel')
                :wikitext(label)
            
            row:tag('div')
                :addClass('infoboxData')
                :wikitext(value)
        end
    end
    
    -- Function to add a section header
    local function addSection(title)
        infobox:tag('div')
            :addClass('infoboxSubheader')
            :wikitext(title)
    end
    
    -- General Information
    addSection('General Information')
    addRow('Location', args.location)
    addRow('Coordinates', args.coordinates)
    addRow('Status', args.status)
    addRow('Owner', args.owner)
    addRow('Governing Body', args.governing_body)
    addRow('Primary Function', args.primary_function)
    addRow('Established', args.inception)
    addRow('Age', args.age)
    addRow('Public Access', args.open_to_public)
    
    -- Architectural Information
    if args.architect or args.architectural_style or args.material then
        addSection('Architecture')
        addRow('Architect', args.architect)
        addRow('Style', args.architectural_style)
        addRow('Material', args.material)
    end
    
    -- Physical Characteristics
    if args.height or args.width or args.length or args.area or args.floors then
        addSection('Dimensions')
        addRow('Height', args.height)
        addRow('Width', args.width)
        addRow('Length', args.length)
        addRow('Area', args.area)
        addRow('Floors', args.floors)
    end
    
    -- Magical Properties
    if args.magical_properties or args.ley_lines or args.enchantments then
        addSection('Magical Properties')
        addRow('Magic', args.magical_properties)
        addRow('Ley Lines', args.ley_lines)
        addRow('Enchantments', args.enchantments)
    end
    
    -- Historical Information
    if args.historical_status or args.previous_names or args.significant_events then
        addSection('Historical Information')
        addRow('Historical Status', args.historical_status)
        addRow('Previous Names', args.previous_names)
        addRow('Notable Events', args.significant_events)
    end
    
    -- Security Information
    if args.security_level or args.security_measures or args.guards then
        addSection('Security')
        addRow('Security Level', args.security_level)
        addRow('Security Measures', args.security_measures)
        addRow('Guard Force', args.guards)
    end
    
    -- Technological Features
    if args.tech_level or args.power_source or args.special_systems then
        addSection('Technology')
        addRow('Tech Level', args.tech_level)
        addRow('Power Source', args.power_source)
        addRow('Special Systems', args.special_systems)
    end
    
    -- Custom fields
    if args.custom1name then
        addRow(args.custom1name, args.custom1value or '')
    end
    
    if args.custom2name then
        addRow(args.custom2name, args.custom2value or '')
    end
    
    if args.custom3name then
        addRow(args.custom3name, args.custom3value or '')
    end
    
    -- Return the completed HTML
    return tostring(html)
end

-- Function to list structures in the same district
function p.districtsStructures(frame)
    local args = frame.args
    
    -- If called via #invoke, get the args from the parent frame
    if not args or not args[1] then
        args = frame:getParent().args
    end
    
    local district = args.district or ''
    local limit = tonumber(args.limit) or 10
    
    -- This is a placeholder function that would need to be implemented
    -- based on how you organize your wiki categories and structure data
    
    local html = mw.html.create('div')
        :addClass('related-structures')
        :wikitext("=== Notable Structures in " .. district .. " ===\n")
    
    local list = html:tag('ul')
    
    -- This would need to be replaced with actual category or property query
    -- For now, it just returns a message
    list:tag('li')
        :wikitext("This function would list structures in the same district based on your wiki's data structure.")
    
    return tostring(html)
end

-- Function to list structures by the same architect
function p.architectsWorks(frame)
    local args = frame.args
    
    -- If called via #invoke, get the args from the parent frame
    if not args or not args[1] then
        args = frame:getParent().args
    end
    
    local architect = args.architect or ''
    local limit = tonumber(args.limit) or 10
    
    -- This is a placeholder function that would need to be implemented
    -- based on how you organize your wiki categories and structure data
    
    local html = mw.html.create('div')
        :addClass('related-structures')
        :wikitext("=== Other Works by " .. architect .. " ===\n")
    
    local list = html:tag('ul')
    
    -- This would need to be replaced with actual category or property query
    -- For now, it just returns a message
    list:tag('li')
        :wikitext("This function would list other structures designed by the same architect based on your wiki's data structure.")
    
    return tostring(html)
end

-- Function to find structures with similar magical properties
function p.similarMagicStructures(frame)
    local args = frame.args
    
    -- If called via #invoke, get the args from the parent frame
    if not args or not args[1] then
        args = frame:getParent().args
    end
    
    local magicType = args.magic_type or ''
    local limit = tonumber(args.limit) or 5
    
    -- This is a placeholder function that would need to be implemented
    -- based on how you organize your wiki categories and structure data
    
    local html = mw.html.create('div')
        :addClass('related-structures')
        :wikitext("=== Structures with Similar Magical Properties ===\n")
    
    local list = html:tag('ul')
    
    -- This would need to be replaced with actual category or property query
    -- For now, it just returns a message
    list:tag('li')
        :wikitext("This function would find structures with similar magical properties based on your wiki's data structure.")
    
    return tostring(html)
end

-- Function to generate a timeline of a structure's history
function p.timeline(frame)
    local args = frame.args
    
    -- If called via #invoke, get the args from the parent frame
    if not args or not args[1] then
        args = frame:getParent().args
    end
    
    local structure = args.structure or frame:preprocess('{{PAGENAME}}')
    
    -- This is a placeholder function that would need to be implemented
    -- based on how you organize your wiki's history data
    
    local html = mw.html.create('div')
        :addClass('structure-timeline')
        :wikitext("=== Timeline of " .. structure .. " ===\n")
    
    -- This would need to be replaced with actual timeline generation code
    -- For now, it just returns a message
    html:tag('p')
        :wikitext("This function would generate a timeline of the structure's history based on your wiki's data structure.")
    
    return tostring(html)
end

return p