Module:Characters

From Umamusume Wiki
Jump to navigation Jump to search

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

local p = {}
local cargo = mw.ext.cargo

function p.list(frame)
	local query = {
		limit = '1000',
		orderBy = 'Characters.name_en ASC',
	}
	if frame.args[1] == 'horsegirls' then
		query.where = 'Characters.type="horsegirl" AND Characters.media IS NULL'
	elseif frame.args[1] == 'other' then
		query.where = 'NOT Characters.type="horsegirl" AND Characters.media IS NULL'
	elseif frame.args[1] == 'cinderellagray' then
		query.where = 'Characters.media="cinderellagray"'
	elseif frame.args[1] == 'starblossom' then
		query.where = 'Characters.media="starblossom"'
	elseif frame.args[1] == 'anime' then
		query.where = 'Characters.media="anime"'
	end
	local fields = {'_pageName','name_en','icon','color_main','color_sub'}
	local characters = cargo.query('Characters',
		table.concat(fields, ','), query)
	
	local root = mw.html.create('div'):cssText('display:flex; flex-flow:row wrap; gap: 10px;')
	for _, ch in ipairs(characters) do
		if ch.icon then
			local template = frame:expandTemplate{
				title='Character Icon',
				args={
					icon=ch.icon,
					name_en=ch.name_en,
					color_main=ch.color_main,
					color_sub=ch.color_sub,
					link=ch._pageName
				}
			}
			root:wikitext(mw.text.trim(template))
		end
	end
	return root
end

function p.profile(frame)
	local charName = frame.args[1]
	if not charName then return end
	local query = {
		limit = '1',
		where = 'name_en="' .. charName .. '"',
	}
	local fields = {'strengths','weaknesses','ears','tail','family',
		'my_rule','phone_background','before_a_race','good_subject',
		'secret_pride','frequent_purchase','secret1','secret2'}
	local characters = cargo.query('Characters',
		table.concat(fields, ','), query)

	local ch = characters[1]
	if not ch then return end
	local template = frame:expandTemplate{
		title='Character Profile/table',
		args={
			strengths=ch.strengths,
			weaknesses=ch.weaknesses,
			ears=ch.ears,
			tail=ch.tail,
			family=ch.family,
			my_rule=ch.my_rule,
			phone_background=ch.phone_background,
			before_a_race=ch.before_a_race,
			good_subject=ch.good_subject,
			secret_pride=ch.secret_pride,
			frequent_purchase=ch.frequent_purchase,
			secret1=ch.secret1,
			secret2=ch.secret2,
		}
	}
	return template
end

return p