5261
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 318: | Рядок 318: | ||
return string.format("<span style='color:%s;'>%s</span>", color, display_text) | return string.format("<span style='color:%s;'>%s</span>", color, display_text) | ||
end | |||
--- Отримує всіх гравців з таблиці "Гравці" в порядку дати приєднання | |||
local function get_all_players() | |||
local title = mw.title.new("Гравці") | |||
if not title or not title.exists then | |||
return nil | |||
end | |||
local content = title:getContent() | |||
if not content then | |||
return nil | |||
end | |||
local table_start = mw.ustring.find(content, "{|") | |||
local table_end = mw.ustring.find(content, "|}", table_start) | |||
if not table_start or not table_end then | |||
return nil | |||
end | |||
local table_content = mw.ustring.sub(content, table_start, table_end + 1) | |||
local players = {} | |||
local rows = {} | |||
for row in mw.ustring.gmatch(table_content, "|-\n(.-)\n|-") do | |||
table.insert(rows, row) | |||
end | |||
local last_row = mw.ustring.match(table_content, "|-\n(.-)%s*|}") | |||
if last_row then | |||
table.insert(rows, last_row) | |||
end | |||
for _, row in ipairs(rows) do | |||
local cells = {} | |||
row = mw.ustring.gsub(row, "^%s*|%s*", "") | |||
for cell in mw.ustring.gmatch(row, "([^|]+)") do | |||
local trimmed = mw.text.trim(cell) | |||
if trimmed ~= "" then | |||
table.insert(cells, trimmed) | |||
end | |||
end | |||
-- Колонка 2 - ім'я гравця | |||
if #cells >= 2 then | |||
local player_name = clean_wikilinks(cells[2]) | |||
if player_name then | |||
table.insert(players, player_name) | |||
end | |||
end | |||
end | |||
return players | |||
end | |||
function p.prev_player(frame) | |||
local name = frame.args.player | |||
local players = get_all_players() | |||
if not players then | |||
return "" | |||
end | |||
for i, player in ipairs(players) do | |||
if player == name then | |||
if i > 1 then | |||
return players[i - 1] | |||
else | |||
return "" -- Перший гравець, немає попереднього | |||
end | |||
end | |||
end | |||
return "" | |||
end | |||
function p.next_player(frame) | |||
local name = frame.args.player | |||
local players = get_all_players() | |||
if not players then | |||
return "" | |||
end | |||
for i, player in ipairs(players) do | |||
if player == name then | |||
if i < #players then | |||
return players[i + 1] | |||
else | |||
return "" -- Останній гравець, немає наступного | |||
end | |||
end | |||
end | |||
return "" | |||
end | end | ||
return p | return p | ||