Module:Water Ritual Liquids

From Caves of Qud Wiki
Jump to navigation Jump to search
LiquidFactions
bloodcannibals • Children of Mamon • Glow-Wights
cloning draughtGirsh
oilrobots
slimemollusks
warm statichighly entropic beings
waterapes • arachnids • baetyls • bears • birds • cats • crabs • Cult of the Coiled Lamb • Daughters of Exile • dogs • equines • Fellowship of Wardens • fish • flowers • fungi • goatfolk • hindren of Bey Lah • insects • Issachari tribe • Merchants' Guild • mysterious strangers • newly sentient beings • oozes • roots • Seekers of the Sightless Way • snapjaws • swine • urchins • villagers of Ezra • villagers of Joppa • winged mammals • worms • trees • antelopes • Sultan cult • hermits • cragmensch • dromad merchants • unshelled reptiles • svardym • Farmers' Guild • villagers of Kyakukya • tortoises • frogs • grazing hedonists • mopango • denizens of the Yd Freehold • water barons • baboons • vines • succulents • Putus Templar • pariahs • Chavvah • Mechanimists • Barathrumites • Gyre wights • Naphtaali tribe • trolls • Consortium of Phyta

local util_args = require('Module:Args Utility')
local util_cargo = require('Module:Cargo Utility')
local util_map = require('Module:Map Utility')
local util_html = require('Module:HTML Utility')
local util_table = require('Module:Table Utility')
local util_text = require('Module:Text Utility')
local favilink = require('Module:Favilink')

local COLUMNS = { 'Liquid', 'Factions' }

local h = {}

local p = {}

function p.main(frame)

frame=mw.getCurrentFrame()
        
	local data = h.makeAndRunQuery(nil)
        h.formatRows(data)
	return h.makeOutput(data)
end

function h.makeAndRunQuery(args)
	return util_cargo.queryAndCast(h.makeQuery(args))
end

function h.makeQuery(args)
	local query = {
		tables = { 'Factions=F' },
		fields = h.getFields(),
		where = '(F._pageNamespace="14" OR F._pageNamespace="0") AND IsVisible="1"',
		orderBy = 'WaterRitualLiquid ASC',
		oneToMany = {
			fields = { 'CONCAT("[[:", _pageName, "|", PlainName, "]]")=Factions', 'WaterRitualLiquid' },
			groupBy = { 'WaterRitualLiquid' },
		},
	}
	return query
end

function h.getFields()
	return {
		'WaterRitualLiquid=Liquid'
	}
end

function h.formatRows(data)
	util_map.rowsInPlace(data, h.formatOneRow)
end

function h.formatOneRow(row)
	row.Factions = util_table.concat(row.Factions, ' • ')
        row.Liquid = favilink.modulefavilink(row.Liquid)
end

function h.makeOutput(data)
	local output = mw.html.create()
	local tbl = output:tag('table')
		:addClass('wikitable')
		:addClass('sortable')
	util_html.printHeader(tbl, COLUMNS)
	util_html.printRowsByList(tbl, data, COLUMNS)
	return output
end

return p