Difference between revisions of "Module:Events"
From Blaseball Wiki
(Stopgap fix; will need to be updated for new era when that becomes possible) |
|||
(7 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
− | local seasons = | + | local function make_table(frame, season, tables, fields, join, headers) |
+ | local output = {} | ||
+ | local args = { | ||
+ | where = 'Season = ' .. season, | ||
+ | join = join, | ||
+ | orderBy = '_sort', | ||
+ | } | ||
+ | local results = cargo.query( tables, fields, args ) | ||
+ | if #results > 0 then | ||
+ | local intro = frame.args['intro'] | ||
+ | if intro ~= nil then | ||
+ | table.insert(output, intro) | ||
+ | end | ||
+ | table.insert(output, '{| class="wikitable"\n!' .. table.concat(headers, '!!')) | ||
+ | for r = 1, #results do | ||
+ | result = results[r] | ||
+ | local row = {} | ||
+ | for i, f in ipairs(headers) do | ||
+ | table.insert(row, result[f]) | ||
+ | end | ||
+ | table.insert(output, '|-\n|' .. table.concat(row, '||')) | ||
+ | end | ||
+ | table.insert(output, '|}') | ||
+ | end | ||
+ | |||
+ | return table.concat(output, '\n') | ||
+ | end | ||
+ | |||
+ | local function do_query(frame, tables, fields, join, headers) | ||
+ | fields = 'Day=_sort,' .. fields | ||
+ | local season = frame.args[1] | ||
+ | if season == nil then | ||
+ | -- local current_season = mw.title.new('Current Season') | ||
+ | -- local seasons = string.match(current_season.redirectTarget.text, '%d+$') | ||
+ | local seasons = 24 | ||
+ | |||
+ | local output = {} | ||
+ | for i = 1, seasons do | ||
+ | table.insert(output, '===Season ' .. i .. '===') | ||
+ | local result = make_table(frame, i, tables, fields, join, headers) | ||
+ | if result == "" then | ||
+ | result = "None" | ||
+ | end | ||
+ | table.insert(output, result) | ||
+ | end | ||
− | function p. | + | return table.concat(output, '\n') |
− | + | else | |
+ | return make_table(frame, season, tables, fields, join, headers) | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function p.incineration(frame) | ||
local tables = 'IncinerationEvents,Players=Players1,Players=Players2,Teams' | local tables = 'IncinerationEvents,Players=Players1,Players=Players2,Teams' | ||
local fields = [=[ | local fields = [=[ | ||
− | |||
IF(game IS NOT NULL, | IF(game IS NOT NULL, | ||
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | ||
IF(Day IS NULL, 'EL', Day) | IF(Day IS NULL, 'EL', Day) | ||
− | )= | + | )=Day, |
− | CONCAT('[[', Players1.Name, ']]')= | + | CONCAT('[[', Players1.Name, ']]')=Player, |
− | CONCAT('[[', Players2.Name, ']]')= | + | CONCAT('[[', Players2.Name, ']]')=Replaced by, |
− | CONCAT('[[', Teams. | + | CONCAT('[[', Teams._pageName, ']]')=Team |
]=] | ]=] | ||
+ | local join = [[ | ||
+ | IncinerationEvents.OutPlayer=Players1.UUID, | ||
+ | IncinerationEvents.InPlayer=Players2.UUID, | ||
+ | IncinerationEvents.Team=Teams.UUID | ||
+ | ]] | ||
− | + | return do_query(frame, tables, fields, join, { 'Day', 'Player', 'Replaced by', 'Team' }) | |
− | + | end | |
− | + | ||
− | + | function p.feedback(frame) | |
− | + | local tables = 'FeedbackEvents,Players=Players1,Players=Players2,Teams=Teams1,Teams=Teams2' | |
− | + | local fields = [=[ | |
− | + | IF(Game IS NOT NULL, | |
− | + | CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | |
− | + | IF(Day IS NULL, 'EL', Day) | |
− | + | )=Day, | |
− | + | CONCAT('[[', Players1.Name, ']]')=Player A, | |
− | + | CONCAT('[[', Teams1._pageName, ']]')=Team A, | |
− | + | CONCAT('[[', Players2.Name, ']]')=Player B, | |
− | + | CONCAT('[[', Teams2._pageName, ']]')=Team B | |
− | + | ]=] | |
− | + | local join = [[ | |
− | + | FeedbackEvents.PlayerA=Players1.UUID, | |
− | + | FeedbackEvents.PlayerB=Players2.UUID, | |
− | + | FeedbackEvents.TeamA=Teams1.UUID, | |
− | + | FeedbackEvents.TeamB=Teams2.UUID | |
+ | ]] | ||
+ | return do_query(frame, tables, fields, join, { 'Day', 'Player A', 'Team A', 'Player B', 'Team B' }) | ||
+ | end | ||
− | return | + | function p.shuffle(frame) |
+ | local tables = 'ShuffleEvents,Teams' | ||
+ | local fields = [=[ | ||
+ | IF(Game IS NOT NULL, | ||
+ | CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | ||
+ | IF(Day IS NULL, 'EL', Day) | ||
+ | )=Day, | ||
+ | CONCAT('[[', Teams._pageName, ']]')=Team, | ||
+ | ShuffleEvents.Type=Type | ||
+ | ]=] | ||
+ | local join = 'ShuffleEvents.Team=Teams.UUID' | ||
+ | return do_query(frame, tables, fields, join, { 'Day', 'Team', 'Type' }) | ||
end | end | ||
return p | return p |
Latest revision as of 23:10, 10 January 2023
This module generates tables of game events per season.
{{#invoke:Events|<type>}}
- Output tables for all seasons with an <h3>
header for each
{{#invoke:Events|<type>|<season>}}
- Output table for a single season with no header, or output nothing if there are no events for the given season
<type>
can be incinerations
, feedback
, or shuffle
.
local p = {}
local cargo = mw.ext.cargo
local function make_table(frame, season, tables, fields, join, headers)
local output = {}
local args = {
where = 'Season = ' .. season,
join = join,
orderBy = '_sort',
}
local results = cargo.query( tables, fields, args )
if #results > 0 then
local intro = frame.args['intro']
if intro ~= nil then
table.insert(output, intro)
end
table.insert(output, '{| class="wikitable"\n!' .. table.concat(headers, '!!'))
for r = 1, #results do
result = results[r]
local row = {}
for i, f in ipairs(headers) do
table.insert(row, result[f])
end
table.insert(output, '|-\n|' .. table.concat(row, '||'))
end
table.insert(output, '|}')
end
return table.concat(output, '\n')
end
local function do_query(frame, tables, fields, join, headers)
fields = 'Day=_sort,' .. fields
local season = frame.args[1]
if season == nil then
-- local current_season = mw.title.new('Current Season')
-- local seasons = string.match(current_season.redirectTarget.text, '%d+$')
local seasons = 24
local output = {}
for i = 1, seasons do
table.insert(output, '===Season ' .. i .. '===')
local result = make_table(frame, i, tables, fields, join, headers)
if result == "" then
result = "None"
end
table.insert(output, result)
end
return table.concat(output, '\n')
else
return make_table(frame, season, tables, fields, join, headers)
end
end
function p.incineration(frame)
local tables = 'IncinerationEvents,Players=Players1,Players=Players2,Teams'
local fields = [=[
IF(game IS NOT NULL,
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'),
IF(Day IS NULL, 'EL', Day)
)=Day,
CONCAT('[[', Players1.Name, ']]')=Player,
CONCAT('[[', Players2.Name, ']]')=Replaced by,
CONCAT('[[', Teams._pageName, ']]')=Team
]=]
local join = [[
IncinerationEvents.OutPlayer=Players1.UUID,
IncinerationEvents.InPlayer=Players2.UUID,
IncinerationEvents.Team=Teams.UUID
]]
return do_query(frame, tables, fields, join, { 'Day', 'Player', 'Replaced by', 'Team' })
end
function p.feedback(frame)
local tables = 'FeedbackEvents,Players=Players1,Players=Players2,Teams=Teams1,Teams=Teams2'
local fields = [=[
IF(Game IS NOT NULL,
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'),
IF(Day IS NULL, 'EL', Day)
)=Day,
CONCAT('[[', Players1.Name, ']]')=Player A,
CONCAT('[[', Teams1._pageName, ']]')=Team A,
CONCAT('[[', Players2.Name, ']]')=Player B,
CONCAT('[[', Teams2._pageName, ']]')=Team B
]=]
local join = [[
FeedbackEvents.PlayerA=Players1.UUID,
FeedbackEvents.PlayerB=Players2.UUID,
FeedbackEvents.TeamA=Teams1.UUID,
FeedbackEvents.TeamB=Teams2.UUID
]]
return do_query(frame, tables, fields, join, { 'Day', 'Player A', 'Team A', 'Player B', 'Team B' })
end
function p.shuffle(frame)
local tables = 'ShuffleEvents,Teams'
local fields = [=[
IF(Game IS NOT NULL,
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'),
IF(Day IS NULL, 'EL', Day)
)=Day,
CONCAT('[[', Teams._pageName, ']]')=Team,
ShuffleEvents.Type=Type
]=]
local join = 'ShuffleEvents.Team=Teams.UUID'
return do_query(frame, tables, fields, join, { 'Day', 'Team', 'Type' })
end
return p