Module:Event bonus cards: Difference between revisions

From Sekaipedia
Content added Content deleted
No edit summary
mNo edit summary
Line 96: Line 96:
local results = cargoQuery(table.concat(wheres, ' AND '))
local results = cargoQuery(table.concat(wheres, ' AND '))
return mw.text.jsonEncode(vsMapping) ..
return table.concat(wheres, ' AND ') ..
'<br>' ..
'<br>' ..
mw.text.jsonEncode(wheres) ..
'<br>' ..
'<br>' ..
mw.text.jsonEncode(results)
mw.text.jsonEncode(results)

Revision as of 03:45, 18 April 2022

To generate {{Event bonus cards}}, invoke using the main function.


local getArgs = require('Module:Arguments').getArgs
local utils   = require('Module:Utilities')
local cargo        = mw.ext.cargo
local VariablesLua = mw.ext.VariablesLua

local p = {}

local function cargoQuery(where)
	local tables = 'Cards'
	local fields = [[
		_pageName,
		rarity,
		thumbnail,
		thumbnail_trained,
		card_name,
		card_character
	]]
	local args = {
        where = where,
        orderBy = 'Cards.rarity DESC, Cards.card_id DESC',
        groupBy = 'Cards._pageID'
    }
    
    return cargo.query( tables, fields, args )
end

local function getVSMapping()
	local virtualSingers = {
		'Hatsune Miku',
		'Kagamine Rin',
		'Kagamine Len',
		'Megurine Luka',
		'MEIKO',
		'KAITO'
	}
	local units = { 
		'Leo/need',
		'MORE MORE JUMP!',
		'Vivid BAD SQUAD',
		'Wonderlands×Showtime',
		'25-ji, Nightcord de.'
	}
	
	local mapping = {}
	
	for _, character in ipairs(virtualSingers) do
		for _, unit in ipairs(units) do
			local key = string.format(
				'%s (%s)',
				character,
				unit
			)
			
			mapping[key] = {
				['character'] = character,
				['support unit'] = unit
			}
		end
	end
	
	return mapping
end

function p.main(frame)
	local args = getArgs(frame)
	
	local characters = args['characters'] or VariablesLua.var('characters')
	local characterList = {}
	
	local attribute  = args['attribute'] or VariablesLua.var('attribute')
	
	if characters then
		characterList = utils.splitWithDelim(';')(characters)
	end
	
	local vsMapping = getVSMapping()
	
	local wheres = {}
	
	for _,character in ipairs(characterList) do
		local vals = vsMapping[character] or
			{
				['character'] = character,
				['support unit'] = ''
			}
		
		local where = string.format(
			"(Cards.card_character = '%s' AND Cards.support_unit = '%s')",
			vals['character'],
			vals['support unit']
		)
		
		table.insert(wheres, where)
	end
	
	local results = cargoQuery(table.concat(wheres, ' AND '))
	
	return table.concat(wheres, ' AND ') .. 
		'<br>' ..
		'<br>' .. 
		mw.text.jsonEncode(results)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.