Модуль:FetchData: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
 
(Не показано 11 проміжних версій цього користувача)
Рядок 86: Рядок 86:
local function parse_row_cells(row)
local function parse_row_cells(row)
     local cells = {}
     local cells = {}
     row = mw.ustring.gsub(row, "^%s*|%s*", "")
      
     for cell in mw.ustring.gmatch(row, "([^|]+)") do
     for line in mw.ustring.gmatch(row, "[^\n]+") do
         local trimmed = mw.text.trim(cell)
         line = mw.text.trim(line)
         if trimmed ~= "" then
       
             table.insert(cells, trimmed)
         if line ~= "|-" and line ~= "" then
             line = mw.ustring.gsub(line, "^|%s*", "")
           
            if line ~= "" then
                table.insert(cells, line)
            end
         end
         end
     end
     end
   
     return cells
     return cells
end
end
Рядок 439: Рядок 445:
      
      
     return {headers = headers, cells = cells}
     return {headers = headers, cells = cells}
end
-- ================================================
-- PLAYER IMAGE (автовибір аватара)
-- ================================================
function p.player_image(frame)
    local nickname = frame.args.nickname or frame.args[1] or mw.title.getCurrentTitle().text
    local player_file = "Player_" .. nickname .. ".png"
    local placeholder = "MCC_Placeholder.png"
   
    local title = mw.title.new("File:" .. player_file)
   
    local file_to_use
    if title and title.exists then
        file_to_use = player_file
    else
        file_to_use = placeholder
    end
   
    return string.format("[[File:%s|none|alt=Фотографія гравця|center|360px]]", file_to_use)
end
end


Рядок 593: Рядок 620:


-- ================================================
-- ================================================
-- FETCHDATA5 (записи ігор) - ОНОВЛЕНО З ЧАСОМ
-- FETCHDATA5 (записи ігор) - З РОЛЛЮ ГРАВЦЯ
-- ================================================
-- ================================================


local function get_tournament_link_games(short_name, full_name)
local function get_tournament_link_games(short_name, full_name)
    if not short_name or short_name == "" then
        return "Невідомо"
    end
   
     if short_name == "Фанова гра" then
     if short_name == "Фанова гра" then
         return "Фанова гра"
         return "Фанова гра"
     elseif short_name == "Score Battle" then
     end
         return "[[Score Open Battle I|Score Battle]]"
   
     elseif short_name and short_name ~= "" and full_name and full_name ~= "" then
    if full_name then
         full_name = clean_wikilinks(full_name)
    end
   
     if full_name and full_name ~= "" and full_name ~= short_name then
         return "[[" .. full_name .. "|" .. short_name .. "]]"
         return "[[" .. full_name .. "|" .. short_name .. "]]"
     else
     else
         return short_name or full_name or "Невідомо"
         return "[[" .. short_name .. "]]"
     end
     end
end
local function parse_games_table_rows(table_content)
    local rows = {}
   
    for row in mw.ustring.gmatch(table_content, "|-\n([^\n]+)") do
        if not mw.ustring.match(row, "^%s*!") then
            table.insert(rows, row)
        end
    end
   
    return rows
end
local function parse_games_row_cells(row)
    local cells = {}
   
    row = mw.ustring.gsub(row, "^%s*|%s*", "")
   
    for cell in mw.ustring.gmatch(row .. "||", "(.-)%s*||%s*") do
        cell = mw.text.trim(cell)
        table.insert(cells, cell)
    end
   
    return cells
end
end


local function get_player_role(player_name, cells)
local function get_player_role(player_name, cells)
     -- ОНОВЛЕНО: після додавання колонки "Час", гравці тепер в позиціях 6-15
     -- Колонки 6-11: мирні
     for i = 6, 11 do -- 6 мирних
     for i = 6, 11 do
         if cells[i] and clean_wikilinks(cells[i]) == player_name then
         if cells[i] and clean_wikilinks(cells[i]) == player_name then
             return "Мирний"
             return "Мир"
         end
         end
     end
     end
      
      
     if cells[12] and clean_wikilinks(cells[12]) == player_name then -- Шериф
    -- Колонка 12: шериф
         return "Шериф"
     if cells[12] and clean_wikilinks(cells[12]) == player_name then
         return "Шер"
     end
     end
      
      
     for i = 13, 14 do -- 2 мафії
    -- Колонки 13-14: мафія
     for i = 13, 14 do
         if cells[i] and clean_wikilinks(cells[i]) == player_name then
         if cells[i] and clean_wikilinks(cells[i]) == player_name then
             return "Мафія"
             return "Маф"
         end
         end
     end
     end
      
      
     if cells[15] and clean_wikilinks(cells[15]) == player_name then -- Дон
    -- Колонка 15: дон
     if cells[15] and clean_wikilinks(cells[15]) == player_name then
         return "Дон"
         return "Дон"
     end
     end
      
      
     return "Невідомо"
     return ""
end
end


Рядок 639: Рядок 702:
      
      
     if game_result == "Місто" or game_result == "Мирні" then
     if game_result == "Місто" or game_result == "Мирні" then
         return (role == "Мирний" or role == "Шериф") and "Перемога" or "Поразка"
         return (role == "Мир" or role == "Шер") and "Перемога" or "Поразка"
     end
     end
      
      
     if game_result == "Мафія" then
     if game_result == "Мафія" then
         return (role == "Мафія" or role == "Дон") and "Перемога" or "Поразка"
         return (role == "Маф" or role == "Дон") and "Перемога" or "Поразка"
     end
     end
      
      
Рядок 653: Рядок 716:
     if not table_content then return nil end
     if not table_content then return nil end
      
      
     local rows = parse_table_rows(table_content)
     local rows = parse_games_table_rows(table_content)
     local games = {}
     local games = {}
      
      
     for _, row in ipairs(rows) do
     for _, row in ipairs(rows) do
         local cells = parse_row_cells(row)
         local cells = parse_games_row_cells(row)
          
          
         local player_in_game = false
         if #cells >= 17 then
        -- ОНОВЛЕНО: гравці тепер в колонках 6-15
            local player_in_game = false
        for i = 6, 15 do
            for i = 6, 15 do
            if cells[i] and clean_wikilinks(cells[i]) == player_name then
                if cells[i] and clean_wikilinks(cells[i]) == player_name then
                player_in_game = true
                    player_in_game = true
                 break
                    break
                 end
             end
             end
        end
       
        if player_in_game and #cells >= 17 then
            local role = get_player_role(player_name, cells)
            local result = get_player_result(role, cells[16])
              
              
            table.insert(games, {
          if player_in_game then
                 tournament = clean_wikilinks(cells[4]) or "", -- Турнір (колонка 4)
                local role = get_player_role(player_name, cells)
                 short = cells[3] or "", -- Скорочення (колонка 3)
                 local result = get_player_result(role, cells[16])
                time = cells[5] or "", -- ЧАС (НОВА КОЛОНКА 5!)
               
                role = role,
                -- Конвертуємо час з "37 хв 26 с" в "37:26"
                result = result,
                local time_raw = cells[5] or ""
                link = cells[17] or "" -- Посилання (колонка 17)
                local minutes, seconds = mw.ustring.match(time_raw, "(%d+)%s*хв%s*(%d+)%s*с")
             })
                local time_formatted = time_raw
                if minutes and seconds then
                    time_formatted = minutes .. ":" .. string.format("%02d", tonumber(seconds))
                 end
               
                table.insert(games, {
                    short = cells[3] or "",
                    tournament = cells[4] or "",
                    time = time_formatted,
                    role = role,
                    result = result,
                    link = cells[17] or ""
                })
             end
         end
         end
     end
     end
Рядок 707: Рядок 779:
      
      
     local headerRow = htmlTable:tag('tr')
     local headerRow = htmlTable:tag('tr')
     headerRow:tag('th'):wikitext('Турнір')
     headerRow:tag('th'):wikitext('Подія')
    headerRow:tag('th'):wikitext('Час') -- НОВА КОЛОНКА!
     headerRow:tag('th'):wikitext('Роль')
     headerRow:tag('th'):wikitext('Роль')
     headerRow:tag('th'):wikitext('Результат')
     headerRow:tag('th'):wikitext('Час')
    headerRow:tag('th'):wikitext('🏆')
     headerRow:tag('th'):wikitext('Запис')
     headerRow:tag('th'):wikitext('Запис')
    -- Колір для ролей (білий)
    local role_color = "#fff"
      
      
     for _, game in ipairs(games) do
     for _, game in ipairs(games) do
         local row = htmlTable:tag('tr')
         local row = htmlTable:tag('tr')
          
          
         row:tag('td'):css('text-align', 'center'):css('padding', '8px')
        -- Турнір
         row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
             :wikitext(get_tournament_link_games(game.short, game.tournament))
             :wikitext(get_tournament_link_games(game.short, game.tournament))
          
          
         -- НОВА КОЛОНКА - ЧАС
      -- Роль (білий колір)
         row:tag('td'):css('text-align', 'center'):css('padding', '8px')
         local roleCell = row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
       
        roleCell:tag('span')
            :css('color', '#fff')
            :wikitext(game.role)
       
        -- Час
         row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
             :wikitext(game.time)
             :wikitext(game.time)
          
          
         row:tag('td'):css('text-align', 'center'):css('padding', '8px'):wikitext(game.role)
         -- Результат (з кольором)
        local resultCell = row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
          
          
        local resultCell = row:tag('td'):css('text-align', 'center'):css('padding', '8px')
         if game.result == "Перемога" then
         if game.result == "Перемога" then
             resultCell:tag('span'):css('color', '#4caf50'):css('font-weight', 'normal'):wikitext('Перемога')
             resultCell:tag('span')
        elseif game.result == "Поразка" then
                :css('color', '#4caf50')
             resultCell:tag('span'):css('color', 'indianred'):css('font-weight', 'normal'):wikitext('Поразка')
                :wikitext('В')
      elseif game.result == "Поразка" then
             resultCell:tag('span')
                :css('color', 'indianred')
                :wikitext('П')
         else
         else
             resultCell:wikitext(game.result)
             resultCell:wikitext(game.result)
         end
         end
          
          
         local linkCell = row:tag('td'):css('text-align', 'center'):css('padding', '8px')
        -- Кнопка перегляду
         local linkCell = row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
       
         if game.link and game.link ~= "" then
         if game.link and game.link ~= "" then
             linkCell:wikitext('<span class="game-record-btn">[' .. game.link .. ' ▶︎]</span>')
             linkCell:wikitext('<span class="game-record-btn">[' .. game.link .. ' ▶︎]</span>')