Content added Content deleted
No edit summary |
(adding cargo back) |
||
(43 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local DatatableBuilder = require('Module:DatatableBuilder') |
|||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
local DisplayFns = require('Module:DisplayFunctions') |
|||
local cargo = mw.ext.cargo |
local cargo = mw.ext.cargo |
||
local VariablesLua = mw.ext.VariablesLua |
local VariablesLua = mw.ext.VariablesLua |
||
local p = {} |
local p = {} |
||
local function formatThumbnails(thumbnail, thumbnailTrained) |
|||
if thumbnail == nil or mw.text.trim(thumbnail) == '' then return end |
|||
local root = mw.html.create('div') |
|||
root:css({ |
|||
['display'] = 'flex', |
|||
['gap'] = '10px' |
|||
}) |
|||
root:wikitext(DisplayFns.image('64px')(thumbnail)) |
|||
if thumbnailTrained ~= nil and mw.text.trim(thumbnailTrained) ~= '' then |
|||
root:wikitext(DisplayFns.image('64px')(thumbnailTrained)) |
|||
end |
|||
return tostring(root) |
|||
end |
|||
local function formatPageLink(page, name) |
|||
if page and name then |
|||
return string.format('[[%s|%s]]', page, name) |
|||
end |
|||
return nil |
|||
end |
|||
local function cargoQuery(where) |
local function cargoQuery(where) |
||
local tables = ' |
local tables = 'cards, card_skills' |
||
local fields = [[ |
local fields = [[ |
||
_pageName, |
cards._pageName = cardPageName, |
||
rarity, |
cards.rarity, |
||
thumbnail, |
cards.thumbnail, |
||
thumbnail_trained, |
cards.thumbnail_trained, |
||
card_name, |
cards.card_name, |
||
card_character |
cards.card_character, |
||
cards.attribute, |
|||
cards.rarity, |
|||
cards.status, |
|||
card_skills.skill_type, |
|||
]] |
]] |
||
local args = { |
local args = { |
||
where = where, |
where = where, |
||
join = 'cards._pageID = card_skills._pageID', |
|||
orderBy = 'cards.rarity DESC, cards.card_id ASC', |
|||
groupBy = 'cards._pageID' |
|||
} |
} |
||
Line 57: | Line 93: | ||
} |
} |
||
end |
end |
||
end |
|||
for _,character in ipairs(virtualSingers) do |
|||
local key = string.format( |
|||
'%s (VIRTUAL SINGER)', |
|||
character |
|||
) |
|||
mapping[key] = { |
|||
['character'] = character, |
|||
['support unit'] = '' |
|||
} |
|||
end |
end |
||
Line 62: | Line 110: | ||
end |
end |
||
local function getWhereFor50Bonus(characters, attribute, maxDateTime, eventId) |
|||
function p.main(frame) |
|||
local |
local maxDate |
||
if maxDateTime then |
|||
maxDate = mw.text.split(maxDateTime, ',')[1] |
|||
end |
|||
local characters = args['characters'] or VariablesLua.var('characters') |
|||
local characterList = {} |
local characterList = {} |
||
local attribute = args['attribute'] or VariablesLua.var('attribute') |
|||
if characters then |
if characters then |
||
characterList = utils.splitWithDelim(';')(characters) |
characterList = utils.splitWithDelim(';')(characters) |
||
Line 80: | Line 127: | ||
for _,character in ipairs(characterList) do |
for _,character in ipairs(characterList) do |
||
local vals = vsMapping[character] or |
local vals = vsMapping[character] or |
||
{ ['character'] = character } |
|||
{ |
|||
['character'] = character, |
|||
['support unit'] = '' |
|||
} |
|||
local where = |
local where = '(' |
||
"(Cards.card_character = '%s' AND Cards.support_unit = '%s')", |
|||
where = where .. string.format( |
|||
vals['character'], |
|||
"cards.card_character = '%s'", |
|||
vals['support unit'] |
|||
vals['character'] |
|||
) |
) |
||
if vals['support unit'] then |
|||
where = where .. string.format( |
|||
" AND cards.support_unit = '%s'", |
|||
vals['support unit'] |
|||
) |
|||
end |
|||
where = where .. ')' |
|||
table.insert(characterWheres, where) |
table.insert(characterWheres, where) |
||
Line 96: | Line 150: | ||
characterWheres = table.concat(characterWheres, ' OR ') |
characterWheres = table.concat(characterWheres, ' OR ') |
||
local |
local wheres = string.format( |
||
" |
"cards.attribute = '%s' AND cards.release_date <= '%s' AND (%s)", |
||
attribute, |
|||
' AND ' .. |
|||
maxDate, |
|||
characterWheres |
characterWheres |
||
) |
) |
||
eventId = tonumber(eventId) |
|||
return mw.text.jsonEncode(results) |
|||
if eventId ~= nil and eventId >= 36 then |
|||
wheres = wheres .. |
|||
string.format( |
|||
" AND NOT (cards.rarity = '4' AND cards.event_id IS NOT NULL AND cards.event_id = %s)", |
|||
eventId |
|||
) |
|||
end |
|||
return wheres |
|||
end |
|||
local function getWhereFor70Bonus(eventId) |
|||
local wheres = string.format( |
|||
"cards.rarity = '4' AND cards.event_id = %s", |
|||
eventId |
|||
) |
|||
return wheres |
|||
end |
|||
local function getTable(data) |
|||
local datatable = DatatableBuilder.new() |
|||
datatable |
|||
:setColumns{ |
|||
{ |
|||
name = 'thumbnails', |
|||
header = 'Thumbnail(s)', |
|||
dataFields = { 'cards.thumbnail', 'cards.thumbnail_trained' }, |
|||
func = formatThumbnails, |
|||
sortable = false, |
|||
}, |
|||
{ |
|||
name = 'name', |
|||
header = 'Card name', |
|||
dataFields = { 'cardPageName', 'cards.card_name' }, |
|||
func = formatPageLink, |
|||
css = { |
|||
['min-width'] = '200px' |
|||
} |
|||
}, |
|||
{ |
|||
name = 'rarity', |
|||
header = 'Rarity', |
|||
dataFields = { 'cards.rarity' } |
|||
}, |
|||
{ |
|||
name = 'status', |
|||
header = 'Status', |
|||
dataFields = { 'cards.status' } |
|||
}, |
|||
{ |
|||
name = 'skill', |
|||
header = 'Skill', |
|||
dataFields = { 'card_skills.skill_type' } |
|||
}, |
|||
} |
|||
:setData( data ) |
|||
return datatable |
|||
end |
|||
function p.main(frame) |
|||
local args = getArgs(frame) |
|||
local bonus = args['bonus'] |
|||
local characters = args['characters'] or VariablesLua.var('characters') |
|||
local attribute = args['attribute'] or VariablesLua.var('attribute') |
|||
local maxDate = args['max date'] or VariablesLua.var('start date') |
|||
local eventId = args['event id'] or VariablesLua.var('event id') |
|||
local wheres |
|||
if bonus == '50%' then |
|||
wheres = getWhereFor50Bonus(characters, attribute, maxDate, eventId) |
|||
elseif bonus == '70%' then |
|||
wheres = getWhereFor70Bonus(eventId) |
|||
else |
|||
error('A bonus must be provided') |
|||
end |
|||
local results = cargoQuery(wheres) |
|||
return getTable(results):tostring() |
|||
end |
end |
||
Latest revision as of 06:17, 3 May 2023
This module depends on the following other modules: |
This module uses the following Cargo tables: |
To generate {{Event bonus cards}}, invoke using the main function.
local getArgs = require('Module:Arguments').getArgs
local DatatableBuilder = require('Module:DatatableBuilder')
local utils = require('Module:Utilities')
local DisplayFns = require('Module:DisplayFunctions')
local cargo = mw.ext.cargo
local VariablesLua = mw.ext.VariablesLua
local p = {}
local function formatThumbnails(thumbnail, thumbnailTrained)
if thumbnail == nil or mw.text.trim(thumbnail) == '' then return end
local root = mw.html.create('div')
root:css({
['display'] = 'flex',
['gap'] = '10px'
})
root:wikitext(DisplayFns.image('64px')(thumbnail))
if thumbnailTrained ~= nil and mw.text.trim(thumbnailTrained) ~= '' then
root:wikitext(DisplayFns.image('64px')(thumbnailTrained))
end
return tostring(root)
end
local function formatPageLink(page, name)
if page and name then
return string.format('[[%s|%s]]', page, name)
end
return nil
end
local function cargoQuery(where)
local tables = 'cards, card_skills'
local fields = [[
cards._pageName = cardPageName,
cards.rarity,
cards.thumbnail,
cards.thumbnail_trained,
cards.card_name,
cards.card_character,
cards.attribute,
cards.rarity,
cards.status,
card_skills.skill_type,
]]
local args = {
where = where,
join = 'cards._pageID = card_skills._pageID',
orderBy = 'cards.rarity DESC, cards.card_id ASC',
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
for _,character in ipairs(virtualSingers) do
local key = string.format(
'%s (VIRTUAL SINGER)',
character
)
mapping[key] = {
['character'] = character,
['support unit'] = ''
}
end
return mapping
end
local function getWhereFor50Bonus(characters, attribute, maxDateTime, eventId)
local maxDate
if maxDateTime then
maxDate = mw.text.split(maxDateTime, ',')[1]
end
local characterList = {}
if characters then
characterList = utils.splitWithDelim(';')(characters)
end
local vsMapping = getVSMapping()
local characterWheres = {}
for _,character in ipairs(characterList) do
local vals = vsMapping[character] or
{ ['character'] = character }
local where = '('
where = where .. string.format(
"cards.card_character = '%s'",
vals['character']
)
if vals['support unit'] then
where = where .. string.format(
" AND cards.support_unit = '%s'",
vals['support unit']
)
end
where = where .. ')'
table.insert(characterWheres, where)
end
characterWheres = table.concat(characterWheres, ' OR ')
local wheres = string.format(
"cards.attribute = '%s' AND cards.release_date <= '%s' AND (%s)",
attribute,
maxDate,
characterWheres
)
eventId = tonumber(eventId)
if eventId ~= nil and eventId >= 36 then
wheres = wheres ..
string.format(
" AND NOT (cards.rarity = '4' AND cards.event_id IS NOT NULL AND cards.event_id = %s)",
eventId
)
end
return wheres
end
local function getWhereFor70Bonus(eventId)
local wheres = string.format(
"cards.rarity = '4' AND cards.event_id = %s",
eventId
)
return wheres
end
local function getTable(data)
local datatable = DatatableBuilder.new()
datatable
:setColumns{
{
name = 'thumbnails',
header = 'Thumbnail(s)',
dataFields = { 'cards.thumbnail', 'cards.thumbnail_trained' },
func = formatThumbnails,
sortable = false,
},
{
name = 'name',
header = 'Card name',
dataFields = { 'cardPageName', 'cards.card_name' },
func = formatPageLink,
css = {
['min-width'] = '200px'
}
},
{
name = 'rarity',
header = 'Rarity',
dataFields = { 'cards.rarity' }
},
{
name = 'status',
header = 'Status',
dataFields = { 'cards.status' }
},
{
name = 'skill',
header = 'Skill',
dataFields = { 'card_skills.skill_type' }
},
}
:setData( data )
return datatable
end
function p.main(frame)
local args = getArgs(frame)
local bonus = args['bonus']
local characters = args['characters'] or VariablesLua.var('characters')
local attribute = args['attribute'] or VariablesLua.var('attribute')
local maxDate = args['max date'] or VariablesLua.var('start date')
local eventId = args['event id'] or VariablesLua.var('event id')
local wheres
if bonus == '50%' then
wheres = getWhereFor50Bonus(characters, attribute, maxDate, eventId)
elseif bonus == '70%' then
wheres = getWhereFor70Bonus(eventId)
else
error('A bonus must be provided')
end
local results = cargoQuery(wheres)
return getTable(results):tostring()
end
return p