Module:Settlement: Difference between revisions
From DSRPG
Created page with "-- Module:Settlement -- Provides enhanced functionality for settlement 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 = htm..." |
m Dubhghlas moved page Module:Infobox settlement to Module:Settlement without leaving a redirect: Simplification. |
(No difference)
| |
Latest revision as of 02:49, 4 May 2025
Documentation for this module may be created at Module:Settlement/doc
-- Module:Settlement
-- Provides enhanced functionality for settlement 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 'Settlement Name'
local color = args.color or '#bcd'
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
-- Add basic information
addRow('Nickname', args.nickname)
if args.motto then
local row = infobox:tag('div')
:addClass('infoboxRow')
row:tag('div')
:addClass('infoboxLabel')
:wikitext('Motto')
row:tag('div')
:addClass('infoboxData')
:css('font-style', 'italic')
:wikitext(args.motto)
end
-- Location section
addSection('Location')
addRow('Type', args.type)
addRow('Region', args.region)
addRow('Continent', args.continent)
addRow('World', args.world)
addRow('Coordinates', args.coordinates)
-- Government section
addSection('Government')
addRow('Government', args.government)
addRow('Sovereign', args.sovereign)
addRow('Governor', args.governor)
addRow('Founded', args.founded)
-- Demographics section
addSection('Demographics')
addRow('Population', args.population)
addRow('Demographics', args.demographics)
addRow('Social Classes', args.socialclasses)
-- Geography section
addSection('Geography')
addRow('Elevation', args.elevation)
addRow('Geographic<br>Features', args.geography)
addRow('Districts', args.districts)
addRow('Landmarks', args.landmarks)
-- Economy section
addSection('Economy')
addRow('Economy', args.economy)
addRow('Currency', args.currency)
addRow('Main Exports', args.exports)
-- Transportation section
if args.transportation then
addSection('Transportation')
addRow('Transport', args.transportation)
end
-- Culture section
addSection('Culture')
addRow('Major Factions', args.factions)
addRow('Dominant Faith', args.faith)
addRow('Cultural<br>Institutions', args.institutions)
-- Climate section
if args.climate then
addSection('Climate')
addRow('Climate', args.climate)
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 generate a list of settlements based on a category
function p.listFromCategory(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 category = args.category or 'Settlements'
local limit = tonumber(args.limit) or 100
local settlements = mw.site.stats.pagesInCategory(category, 'page')
local html = mw.html.create('div')
:addClass('settlement-list')
local count = 0
for _, settlement in ipairs(settlements) do
if count >= limit then break end
html:tag('div')
:addClass('settlement-item')
:wikitext(string.format('* [[%s]]', settlement.title))
count = count + 1
end
return tostring(html)
end
-- Function to find nearest settlements based on coordinates
function p.findNearest(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 originName = args.origin or frame:preprocess('{{PAGENAME}}')
local limit = tonumber(args.limit) or 5
-- This is a placeholder function that would need to be implemented based on
-- how you store and retrieve geographical coordinates in your wiki
-- For now, we'll just return a message
return "Function to find nearest settlements would be implemented here based on how your wiki stores geographical data."
end
-- Advanced search function for settlements with specific attributes
function p.search(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
-- This is a placeholder function that would need to be implemented based on
-- how you store and search for settlement attributes in your wiki
-- For now, we'll just return a message
return "Settlement search function would be implemented here based on your wiki's data structure."
end
return p