Moduł:Dźwięki: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| [wersja przejrzana] | [wersja przejrzana] |
Nie podano opisu zmian |
Nie podano opisu zmian |
||
| Linia 1: | Linia 1: | ||
local p = {} | local p = {} | ||
-- 1. | -- 1. ŁADOWANIE DANYCH (Ustawione na Twoją ścieżkę) | ||
local dataPath = 'Moduł:SandBox/Igorczewski6524/Dźwięki/Dane' | local dataPath = 'Moduł:SandBox/Igorczewski6524/Dźwięki/Dane' | ||
local success, data = pcall(mw.loadData, dataPath) | local success, data = pcall(mw.loadData, dataPath) | ||
local function renderTable(editionName, editionData, displayTitle, icon) | local function renderTable(editionName, editionData, displayTitle, icon, upcoming) | ||
-- | -- Sprawdzamy czy dane w ogóle istnieją | ||
if | if type(editionData) ~= "table" then return "" end | ||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
| Linia 16: | Linia 14: | ||
:css('font-size', '0.9em') | :css('font-size', '0.9em') | ||
-- Ikona i Tytuł | |||
local iconWiki = (icon and icon ~= "") and ('[[Plik:' .. icon .. '|20px|link=]] ') or "" | local iconWiki = (icon and icon ~= "") and ('[[Plik:' .. icon .. '|20px|link=]] ') or "" | ||
root:tag('tr'):tag('th') | root:tag('tr'):tag('th') | ||
| Linia 21: | Linia 20: | ||
:wikitext(iconWiki .. displayTitle .. ' sound type') | :wikitext(iconWiki .. displayTitle .. ' sound type') | ||
-- Przygotowanie tekstu "upcoming" | |||
local upLabel = "" | |||
if upcoming and upcoming ~= "" then | |||
upLabel = '<br><small style="color:#0645ad; font-weight:normal; white-space:nowrap;">[upcoming: ' .. upcoming .. ']</small>' | |||
end | |||
-- Nagłówki kolumn (ZAWSZE WIDOCZNE) | |||
local subHeader = root:tag('tr') | local subHeader = root:tag('tr') | ||
local headers = {"Sound", "Closed captions", "Source", "Description", "Identifier", "Translation key", "Volume", "Pitch"} | local headers = { | ||
"Sound", | |||
"Closed captions", -- Tutaj dodamy upLabel | |||
"Source", | |||
"Description", | |||
"Identifier", | |||
"Translation key", -- Tutaj dodamy upLabel | |||
"Volume", | |||
"Pitch" | |||
} | |||
if editionName == 'Java Edition' then table.insert(headers, "Attenuation distance") end | if editionName == 'Java Edition' then table.insert(headers, "Attenuation distance") end | ||
for _, | |||
for _, hName in ipairs(headers) do | |||
local th = subHeader:tag('th'):wikitext(hName) | |||
-- Dodajemy dopisek upcoming tylko do konkretnych kolumn, jeśli istnieje | |||
if (hName == "Closed captions" or hName == "Translation key") and upLabel ~= "" then | |||
th:wikitext(upLabel) | |||
end | |||
end | |||
for _, group in | -- Generowanie wierszy | ||
local | local rowFound = false | ||
-- Używamy pairs, bo mw.loadData nie obsługuje poprawnie ipairs/# dla dużych struktur | |||
for _, group in pairs(editionData) do | |||
if type(group) == "table" and group.zdarzenia then | |||
-- Liczymy ręcznie ile jest zdarzeń w grupie dla rowspan | |||
local groupEvents = group.zdarzenia | |||
local eventCount = 0 | |||
for _ in pairs(groupEvents) do eventCount = eventCount + 1 end | |||
for i, row in ipairs(groupEvents) do | |||
rowFound = true | |||
local tr = root:tag('tr') | |||
-- Pierwsza kolumna (Ikony głośników) - tylko dla pierwszego wiersza w grupie | |||
if i == 1 then | |||
local soundCell = tr:tag('td'):attr('rowspan', eventCount):css('text-align', 'center'):css('vertical-align', 'middle') | |||
if group.pliki then | |||
for _, file in ipairs(group.pliki) do | |||
soundCell:wikitext('[[Plik:Sound-icon.png|16px|link=Plik:' .. file .. ']] ') | |||
end | |||
end | end | ||
end | |||
-- Dane komórek | |||
tr:tag('td'):wikitext(row.captions or "?") | |||
tr:tag('td'):wikitext(row.source or "") | |||
tr:tag('td'):wikitext(row.desc or "") | |||
tr:tag('td'):tag('code'):wikitext(row.id or ""):done() | |||
tr:tag('td'):tag('code'):wikitext(row.key or ""):done() | |||
tr:tag('td'):wikitext(row.vol or "") | |||
tr:tag('td'):wikitext(row.pitch or "") | |||
if editionName == 'Java Edition' then | |||
tr:tag('td'):wikitext(row.dist or "") | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
if not rowFound then return "" end | |||
return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root) | return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root) | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
if not success then return '<span class="error">Błąd: Baza danych nie odpowiada.</span>' end | |||
if not success then | |||
local | local pArgs = frame:getParent().args | ||
local | local fArgs = frame.args | ||
local id = | local id = mw.text.trim(pArgs[1] or fArgs[1] or "") | ||
local nazwa = pArgs[2] or fArgs[2] or id | |||
if | if id == "" then return "Podaj ID bloku w wywołaniu." end | ||
local blockData = data[id] | local blockData = data[id] | ||
if not blockData then | if not blockData then return '<span class="error">Brak danych dla ID: ' .. id .. '</span>' end | ||
local | -- Wywołanie renderowania | ||
local | local java = renderTable('Java Edition', blockData.java, nazwa, blockData.ikona, blockData.java_upcoming) | ||
local bedrock = renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona, blockData.bedrock_upcoming) | |||
return java .. bedrock | |||
end | end | ||
return p | return p | ||
Wersja z 21:13, 3 sty 2026
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
-- 1. ŁADOWANIE DANYCH (Ustawione na Twoją ścieżkę)
local dataPath = 'Moduł:SandBox/Igorczewski6524/Dźwięki/Dane'
local success, data = pcall(mw.loadData, dataPath)
local function renderTable(editionName, editionData, displayTitle, icon, upcoming)
-- Sprawdzamy czy dane w ogóle istnieją
if type(editionData) ~= "table" then return "" end
local root = mw.html.create('table')
:addClass('wikitable sound-table mw-collapsible mw-collapsed')
:css('width', '100%')
:css('font-size', '0.9em')
-- Ikona i Tytuł
local iconWiki = (icon and icon ~= "") and ('[[Plik:' .. icon .. '|20px|link=]] ') or ""
root:tag('tr'):tag('th')
:attr('colspan', editionName == 'Java Edition' and '9' or '8')
:wikitext(iconWiki .. displayTitle .. ' sound type')
-- Przygotowanie tekstu "upcoming"
local upLabel = ""
if upcoming and upcoming ~= "" then
upLabel = '<br><small style="color:#0645ad; font-weight:normal; white-space:nowrap;">[upcoming: ' .. upcoming .. ']</small>'
end
-- Nagłówki kolumn (ZAWSZE WIDOCZNE)
local subHeader = root:tag('tr')
local headers = {
"Sound",
"Closed captions", -- Tutaj dodamy upLabel
"Source",
"Description",
"Identifier",
"Translation key", -- Tutaj dodamy upLabel
"Volume",
"Pitch"
}
if editionName == 'Java Edition' then table.insert(headers, "Attenuation distance") end
for _, hName in ipairs(headers) do
local th = subHeader:tag('th'):wikitext(hName)
-- Dodajemy dopisek upcoming tylko do konkretnych kolumn, jeśli istnieje
if (hName == "Closed captions" or hName == "Translation key") and upLabel ~= "" then
th:wikitext(upLabel)
end
end
-- Generowanie wierszy
local rowFound = false
-- Używamy pairs, bo mw.loadData nie obsługuje poprawnie ipairs/# dla dużych struktur
for _, group in pairs(editionData) do
if type(group) == "table" and group.zdarzenia then
-- Liczymy ręcznie ile jest zdarzeń w grupie dla rowspan
local groupEvents = group.zdarzenia
local eventCount = 0
for _ in pairs(groupEvents) do eventCount = eventCount + 1 end
for i, row in ipairs(groupEvents) do
rowFound = true
local tr = root:tag('tr')
-- Pierwsza kolumna (Ikony głośników) - tylko dla pierwszego wiersza w grupie
if i == 1 then
local soundCell = tr:tag('td'):attr('rowspan', eventCount):css('text-align', 'center'):css('vertical-align', 'middle')
if group.pliki then
for _, file in ipairs(group.pliki) do
soundCell:wikitext('[[Plik:Sound-icon.png|16px|link=Plik:' .. file .. ']] ')
end
end
end
-- Dane komórek
tr:tag('td'):wikitext(row.captions or "?")
tr:tag('td'):wikitext(row.source or "")
tr:tag('td'):wikitext(row.desc or "")
tr:tag('td'):tag('code'):wikitext(row.id or ""):done()
tr:tag('td'):tag('code'):wikitext(row.key or ""):done()
tr:tag('td'):wikitext(row.vol or "")
tr:tag('td'):wikitext(row.pitch or "")
if editionName == 'Java Edition' then
tr:tag('td'):wikitext(row.dist or "")
end
end
end
end
if not rowFound then return "" end
return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root)
end
function p.main(frame)
if not success then return '<span class="error">Błąd: Baza danych nie odpowiada.</span>' end
local pArgs = frame:getParent().args
local fArgs = frame.args
local id = mw.text.trim(pArgs[1] or fArgs[1] or "")
local nazwa = pArgs[2] or fArgs[2] or id
if id == "" then return "Podaj ID bloku w wywołaniu." end
local blockData = data[id]
if not blockData then return '<span class="error">Brak danych dla ID: ' .. id .. '</span>' end
-- Wywołanie renderowania
local java = renderTable('Java Edition', blockData.java, nazwa, blockData.ikona, blockData.java_upcoming)
local bedrock = renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona, blockData.bedrock_upcoming)
return java .. bedrock
end
return p