Moduł:Dźwięki
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
-- 1. DYNAMICZNE ŁADOWANIE BAZY
-- Używamy getTitle(), aby moduł sam wiedział, że ma szukać pliku /Dane obok siebie
local currentTitle = mw.getCurrentFrame():getTitle()
local dataPath = currentTitle .. '/Dane'
local success, data = pcall(mw.loadData, dataPath)
local function renderTable(editionName, editionData, displayTitle, icon)
if not editionData or type(editionData) ~= "table" or #editionData == 0 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')
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')
local subHeader = root:tag('tr')
local headers = {"Sound", "Closed captions", "Source", "Description", "Identifier", "Translation key", "Volume", "Pitch"}
if editionName == 'Java Edition' then table.insert(headers, "Attenuation distance") end
for _, h in ipairs(headers) do
subHeader:tag('th'):wikitext(h):done()
end
for _, group in ipairs(editionData) do
local rowCount = #group.zdarzenia
for i, row in ipairs(group.zdarzenia) do
local tr = root:tag('tr')
if i == 1 then
local soundCell = tr:tag('td'):attr('rowspan', rowCount):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
tr:tag('td'):wikitext(row.captions or "?"):done()
tr:tag('td'):wikitext(row.source or ""):done()
tr:tag('td'):wikitext(row.desc or ""):done()
tr:tag('td'):tag('code'):wikitext(row.id or ""):done():done()
tr:tag('td'):tag('code'):wikitext(row.key or ""):done():done()
tr:tag('td'):wikitext(row.vol or ""):done()
tr:tag('td'):wikitext(row.pitch or ""):done()
if editionName == 'Java Edition' then tr:tag('td'):wikitext(row.dist or ""):done() end
end
end
return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root)
end
function p.main(frame)
-- DIAGNOSTYKA ŁADOWANIA BAZY
if not success then
return '<span class="error">Błąd krytyczny: Nie mogę załadować bazy danych z: ' .. dataPath .. '. Sprawdź, czy ta strona istnieje!</span>'
end
-- POBIERANIE ARGUMENTÓW (BARDZO ODPORNE)
local parentArgs = frame:getParent().args
local currentArgs = frame.args
-- Szukamy ID w różnych miejscach (z szablonu lub bezpośrednio)
local id = parentArgs[1] or currentArgs[1]
local nazwa = parentArgs[2] or currentArgs[2] or id
local wersja = string.lower(parentArgs[3] or currentArgs[3] or "")
-- CZYŚCIMY ID ZE SPACJI
if id then id = mw.text.trim(id) end
-- FUNKCJA DIAGNOSTYCZNA (jeśli nic nie wpiszesz, pokaże instrukcję)
if not id or id == "" then
return '<div style="border:1px solid orange; padding:10px;">' ..
'<strong>Witaj w module dźwięków!</strong><br>' ..
'Aktualnie moduł szuka bazy w: <code>' .. dataPath .. '</code><br>' ..
'Aby wyświetlić tabelę, użyj: <code>{{#invoke:' .. currentTitle .. '|main|copper}}</code>' ..
'</div>'
end
-- SPRAWDZANIE KLUCZA W BAZIE
local blockData = data[id]
if not blockData then
-- Wyświetlamy dostępne klucze w bazie, aby ułatwić naprawę
local keys = {}
for k, _ in pairs(data) do table.insert(keys, k) end
return '<span class="error">Błąd: Brak klucza "' .. tostring(id) .. '" w bazie. Dostępne klucze to: ' .. table.concat(keys, ", ") .. '</span>'
end
local output = ""
if wersja == "java" then
output = renderTable('Java Edition', blockData.java, nazwa, blockData.ikona)
elseif wersja == "bedrock" then
output = renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona)
else
output = renderTable('Java Edition', blockData.java, nazwa, blockData.ikona) ..
renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona)
end
return output
end
return p