Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:MatchDay: Difference between revisions

From eSportsAmaze
Created page with "local p = {} local cargo = mw.ext.cargo function p.store(frame) local args = frame:getParent().args local tournament = args.tournament or mw.title.getCurrentTitle().text local date = args.date or "" local stage = args.stage or "" if date == "" then return "Error: Date is required." end -- 1. Look up the Game Type from Tournaments Table local game = "BGMI" -- Default fallback local match_type = "BR" if cargo and cargo.query..."
 
No edit summary
Line 3: Line 3:


function p.store(frame)
function p.store(frame)
    local args = frame:getParent().args
local args = frame:getParent().args
    local tournament = args.tournament or mw.title.getCurrentTitle().text
    local date = args.date or ""
    local stage = args.stage or ""
   
    if date == "" then return "Error: Date is required." end


    -- 1. Look up the Game Type from Tournaments Table
-- SMART TOURNAMENT NAME EXTRACTION
    local game = "BGMI" -- Default fallback
local pageTitle = mw.title.getCurrentTitle().text
    local match_type = "BR"
local tournament = args.tournament
   
    if cargo and cargo.query then
        local tData = cargo.query("Tournaments", "game", { where = "name='" .. tournament:gsub("'", "\\'") .. "'", limit = 1 })
        if tData and #tData > 0 and tData[1].game then
            game = tData[1].game
            local gLower = game:lower()
            if gLower:find("pokemon") or gLower:find("mlbb") or gLower:find("honor of kings") then
                match_type = "MOBA"
            end
        end
    end


    -- 2. Build the Match Data JSON
if not tournament or tournament == "" then
    local matches = {}
local parts = mw.text.split(pageTitle, '/')
    for i = 1, 15 do
-- If path is like "BGMI/Tournaments/BGIS_2026/Matches", grab the 3rd part
        local mTime = args['m'..i..'_time']
if parts[2] == "Tournaments" and parts[3] then
        if mTime and mTime ~= "" then
tournament = parts[3]
            local match = { time = mTime }
else
           
-- Fallback to the base page name if it's not in a standard folder structure
            -- If Battle Royale
tournament = mw.title.getCurrentTitle().baseText
            if match_type == "BR" then
end
                match.map = args['m'..i..'_map'] or "TBD"
end
                match.group = args['m'..i..'_group'] or ""
            -- If MOBA
            else
                match.t1 = args['m'..i..'_t1'] or "TBD"
                match.t2 = args['m'..i..'_t2'] or "TBD"
                match.group = args['m'..i..'_group'] or ""
            end
           
            table.insert(matches, match)
        end
    end
   
    -- Convert Lua table to JSON string for storage
    local json_data = mw.text.jsonEncode(matches)


    -- 3. Store in Cargo
local date = args.date or ""
    if cargo and cargo.store then
local stage = args.stage or ""
        cargo.store("Tournament_Schedule", {
            tournament = tournament,
            game = game,
            match_type = match_type,
            date = date,
            stage = stage,
            day_data = json_data
        })
    end


    -- 4. Temporary Visual Output (So you know it worked before we build the calendar UI)
if date == "" then return "Error: Date is required." end
    return "<div style='display:none;'>Schedule saved for " .. date .. " (" .. match_type .. ")</div>"
 
-- 1. Look up the Game Type from Tournaments Table
local game = "BGMI" -- Default fallback
local match_type = "BR"
 
if cargo and cargo.query then
-- Match exact tournament name to find the game
local tData = cargo.query("Tournaments", "game", { where = "name='" .. tournament:gsub("'", "\\'") .. "'", limit = 1 })
if tData and #tData > 0 and tData[1].game then
game = tData[1].game
local gLower = game:lower()
if gLower:find("pokemon") or gLower:find("mlbb") or gLower:find("honor of kings") then
match_type = "MOBA"
end
end
end
 
-- 2. Build the Match Data JSON
local matches = {}
for i = 1, 15 do
local mTime = args['m'..i..'_time']
if mTime and mTime ~= "" then
local match = { time = mTime }
 
-- If Battle Royale
if match_type == "BR" then
match.map = args['m'..i..'_map'] or "TBD"
match.group = args['m'..i..'_group'] or ""
-- If MOBA
else
match.t1 = args['m'..i..'_t1'] or "TBD"
match.t2 = args['m'..i..'_t2'] or "TBD"
match.group = args['m'..i..'_group'] or ""
end
 
table.insert(matches, match)
end
end
 
local json_data = mw.text.jsonEncode(matches)
 
-- 3. Store in Cargo
if cargo and cargo.store then
cargo.store("Tournament_Schedule", {
tournament = tournament,
game = game,
match_type = match_type,
date = date,
stage = stage,
day_data = json_data
})
end
 
return "<div style='display:none;'>Schedule saved for " .. date .. " (" .. match_type .. ")</div>"
end
end


return p
return p

Revision as of 01:09, 23 February 2026

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

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

function p.store(frame)
local args = frame:getParent().args

-- SMART TOURNAMENT NAME EXTRACTION
local pageTitle = mw.title.getCurrentTitle().text
local tournament = args.tournament

if not tournament or tournament == "" then
local parts = mw.text.split(pageTitle, '/')
-- If path is like "BGMI/Tournaments/BGIS_2026/Matches", grab the 3rd part
if parts[2] == "Tournaments" and parts[3] then
tournament = parts[3]
else
-- Fallback to the base page name if it's not in a standard folder structure
tournament = mw.title.getCurrentTitle().baseText
end
end

local date = args.date or ""
local stage = args.stage or ""

if date == "" then return "Error: Date is required." end

-- 1. Look up the Game Type from Tournaments Table
local game = "BGMI" -- Default fallback
local match_type = "BR"

if cargo and cargo.query then
-- Match exact tournament name to find the game
local tData = cargo.query("Tournaments", "game", { where = "name='" .. tournament:gsub("'", "\\'") .. "'", limit = 1 })
if tData and #tData > 0 and tData[1].game then
game = tData[1].game
local gLower = game:lower()
if gLower:find("pokemon") or gLower:find("mlbb") or gLower:find("honor of kings") then
match_type = "MOBA"
end
end
end

-- 2. Build the Match Data JSON
local matches = {}
for i = 1, 15 do
local mTime = args['m'..i..'_time']
if mTime and mTime ~= "" then
local match = { time = mTime }

-- If Battle Royale
if match_type == "BR" then
match.map = args['m'..i..'_map'] or "TBD"
match.group = args['m'..i..'_group'] or ""
-- If MOBA
else
match.t1 = args['m'..i..'_t1'] or "TBD"
match.t2 = args['m'..i..'_t2'] or "TBD"
match.group = args['m'..i..'_group'] or ""
end

table.insert(matches, match)
end
end

local json_data = mw.text.jsonEncode(matches)

-- 3. Store in Cargo
if cargo and cargo.store then
cargo.store("Tournament_Schedule", {
tournament = tournament,
game = game,
match_type = match_type,
date = date,
stage = stage,
day_data = json_data
})
end

return "<div style='display:none;'>Schedule saved for " .. date .. " (" .. match_type .. ")</div>"
end

return p