Difference between revisions of "Module:Villagers"

From Foundation - Wiki
Jump to navigation Jump to search
(Created page with "local p = {} local b = mw.loadData('Module:Buildings') local a = require('Module:Arguments') local com = require('Module:Common') function p.jobs(frame) local args = a.getArgs(frame) if args[1] then local rank = com.firstUpper(args[1]) local jobs = {} for k, v in pairs(book) do if v.rank then jobs[k] = true end end table.sort(jobs) if #jobs > 0 then local cols = { 'column-count', (args[2] or 3) } local jobList = mw.html.create('di...")
 
 
(11 intermediate revisions by the same user not shown)
Line 7: Line 7:
local args = a.getArgs(frame)
local args = a.getArgs(frame)
if args[1] then
if args[1] then
local rank = com.firstUpper(args[1])
local rank = com.fUpper(args[1])
local jobs = {}
local jobs = {}
for k, v in pairs(book) do
 
if v.rank then
for k, v in pairs(b) do
if v.rank == rank then
jobs[k] = true
jobs[k] = true
end
end
end
end
 
table.sort(jobs)
table.sort(jobs)
if #jobs > 0 then
mw.log(#jobs)
local cols = {
local cols = {
'column-count', (args[2] or 3)
['column-count'] = (args[2] or 3)
}
}
local jobList = mw.html.create('div')
local jobList = mw.html.create('div')
jobList:addClass('job-list')
jobList:addClass('job-list')
:css(cols)
:css(cols)
:tag('ul')
:tag('ul')
for k, v in pairs(jobs) do
local jobName = mw.html.create('li')
jobName:wikitext('[[' .. com.fUpper(k) .. ']]' .. ((b[k].job and '- ' .. b[k].job) or ''))
jobList:node(jobName)
end
for k, v in pairs(jobs) do
return jobList
local jobName = mw.html.create('li')
jobName:wikitext('[[' .. k .. ']]')
jobList:node(jobName)
end
return jobList
end
end
end
return ''
return ''
end
end
 
return p
return p

Latest revision as of 08:51, 24 December 2023

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

local p = {}
local b = mw.loadData('Module:Buildings')
local a = require('Module:Arguments')
local com = require('Module:Common')

function p.jobs(frame)
	local args = a.getArgs(frame)
	if args[1] then
		local rank = com.fUpper(args[1])
		local jobs = {}

		for k, v in pairs(b) do
			if v.rank == rank then
				jobs[k] = true
			end
		end

		table.sort(jobs)
		mw.log(#jobs)
		local cols = {
			['column-count'] = (args[2] or 3)
		}
		local jobList = mw.html.create('div')
		jobList:addClass('job-list')
		:css(cols)
		:tag('ul')
	
		for k, v in pairs(jobs) do
			local jobName = mw.html.create('li')
			jobName:wikitext('[[' .. com.fUpper(k) .. ']]' .. ((b[k].job and '- ' .. b[k].job) or ''))
			jobList:node(jobName)
		end
		
		return jobList
	end
	
	return ''
end
		
return p