Difference between revisions of "Module:Events"

From Blaseball Wiki

(Fix scattered team names)
Line 62: Line 62:
 
         CONCAT('[[', Players1.Name, ']]')=Player,
 
         CONCAT('[[', Players1.Name, ']]')=Player,
 
         CONCAT('[[', Players2.Name, ']]')=Replaced by,
 
         CONCAT('[[', Players2.Name, ']]')=Replaced by,
         CONCAT('[[', Teams.Name, ']]')=Team
+
         CONCAT('[[', Teams._pageName, ']]')=Team
 
     ]=]
 
     ]=]
 
     local join = [[
 
     local join = [[
Line 81: Line 81:
 
         )=Day,
 
         )=Day,
 
         CONCAT('[[', Players1.Name, ']]')=Player A,
 
         CONCAT('[[', Players1.Name, ']]')=Player A,
         CONCAT('[[', Teams1.Name, ']]')=Team A,
+
         CONCAT('[[', Teams1._pageName, ']]')=Team A,
 
         CONCAT('[[', Players2.Name, ']]')=Player B,
 
         CONCAT('[[', Players2.Name, ']]')=Player B,
         CONCAT('[[', Teams2.Name, ']]')=Team B
+
         CONCAT('[[', Teams2._pageName, ']]')=Team B
 
     ]=]
 
     ]=]
 
     local join = [[
 
     local join = [[
Line 101: Line 101:
 
           IF(Day IS NULL, 'EL', Day)
 
           IF(Day IS NULL, 'EL', Day)
 
         )=Day,
 
         )=Day,
         CONCAT('[[', Teams.Name, ']]')=Team,
+
         CONCAT('[[', Teams._pageName, ']]')=Team,
 
         ShuffleEvents.Type=Type
 
         ShuffleEvents.Type=Type
 
     ]=]
 
     ]=]

Revision as of 00:37, 14 August 2021

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 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