5441
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 602: | Рядок 602: | ||
-- ================================================ | -- ================================================ | ||
-- 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 | |||
-- Очищаємо full_name від [[ ]] | |||
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 = {} | |||
-- Шукаємо рядки після |- (inline формат: все в одному рядку) | |||
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 | 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-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 "Мирний" | ||
| Рядок 625: | Рядок 663: | ||
end | end | ||
if cells[12] and clean_wikilinks(cells[12]) == player_name then | -- Колонка 12: шериф | ||
if cells[12] and clean_wikilinks(cells[12]) == player_name then | |||
return "Шериф" | 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 "Мафія" | ||
| Рядок 635: | Рядок 675: | ||
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 | ||
| Рядок 662: | Рядок 703: | ||
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) | ||
if #cells >= 17 then | |||
-- Перевіряємо чи гравець у грі (колонки 6-15) | |||
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 | ||
table.insert(games, { | if player_in_game then | ||
local role = get_player_role(player_name, cells) | |||
local result = get_player_result(role, cells[16]) | |||
table.insert(games, { | |||
short = cells[3] or "", | |||
tournament = cells[4] or "", | |||
time = cells[5] or "", | |||
result = result, | |||
link = cells[17] or "" | |||
}) | |||
end | |||
end | end | ||
end | end | ||
| Рядок 717: | Рядок 759: | ||
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('Запис') | ||
| Рядок 725: | Рядок 766: | ||
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') | 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') | |||
:wikitext('Перемога') | |||
elseif game.result == "Поразка" then | elseif game.result == "Поразка" then | ||
resultCell:tag('span'):css('color', 'indianred') | 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>') | ||
| Рядок 759: | Рядок 815: | ||
return games and tostring(#games) or "0" | return games and tostring(#games) or "0" | ||
end | end | ||