6369
редагувань
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| (Не показано 8 проміжних версій цього користувача) | |||
| Рядок 87: | Рядок 87: | ||
local cells = {} | local cells = {} | ||
for line in mw.ustring.gmatch(row, "[^\n]+") do | for line in mw.ustring.gmatch(row, "[^\n]+") do | ||
line = mw.text.trim(line) | line = mw.text.trim(line) | ||
if line ~= "|-" and line ~= "" then | if line ~= "|-" and line ~= "" then | ||
line = mw.ustring.gsub(line, "^|%s*", "") | line = mw.ustring.gsub(line, "^|%s*", "") | ||
| Рядок 448: | Рядок 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 | ||
| Рядок 602: | Рядок 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 "Фанова гра" | ||
end | |||
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 | return "[[" .. short_name .. "]]" | ||
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 | end | ||
return cells | |||
end | end | ||
local function get_player_role(player_name, cells) | local function get_player_role(player_name, cells) | ||
-- | -- Колонки 6-11: мирні | ||
for i = 6, 11 do | 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 | -- Колонки 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 | ||
| Рядок 648: | Рядок 702: | ||
if game_result == "Місто" or game_result == "Мирні" then | if game_result == "Місто" or game_result == "Мирні" then | ||
return (role == " | return (role == "Мир" or role == "Шер") and "Перемога" or "Поразка" | ||
end | end | ||
if game_result == "Мафія" then | if game_result == "Мафія" then | ||
return (role == " | return (role == "Маф" or role == "Дон") and "Перемога" or "Поразка" | ||
end | end | ||
| Рядок 662: | Рядок 716: | ||
if not table_content then return nil end | if not table_content then return nil end | ||
local rows = | 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 = | local cells = parse_games_row_cells(row) | ||
local player_in_game = false | if #cells >= 17 then | ||
local player_in_game = false | |||
for i = 6, 15 do | |||
if cells[i] and clean_wikilinks(cells[i]) == player_name then | |||
player_in_game = true | |||
break | |||
end | |||
end | end | ||
if player_in_game then | |||
local role = get_player_role(player_name, cells) | |||
short = cells[3] or "", | local result = get_player_result(role, cells[16]) | ||
-- Конвертуємо час з "37 хв 26 с" в "37:26" | |||
local time_raw = cells[5] or "" | |||
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 | ||
| Рядок 716: | Рядок 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('Запис') | ||
-- Колір для ролей (білий) | |||
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' | -- Результат (з кольором) | ||
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') | resultCell:tag('span') | ||
:css('color', '#4caf50') | |||
resultCell:tag('span'):css('color', 'indianred') | :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>') | ||