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. ADRESACJA | -- 1. ADRESACJA - tutaj wpisujemy Twoją pełną ścieżkę | ||
local dataPath = 'Moduł:SandBox/Igorczewski6524/Dźwięki/Dane' | |||
local success, data = pcall(mw.loadData, | local success, data = pcall(mw.loadData, dataPath) | ||
local function renderTable(editionName, editionData, displayTitle, icon) | local function renderTable(editionName, editionData, displayTitle, icon) | ||
if not editionData or type(editionData) ~= "table" or #editionData == 0 then return "" end | -- Jeśli tu wejdziemy i editionData jest puste, funkcja nic nie pokaże | ||
if not editionData or type(editionData) ~= "table" or #editionData == 0 then | |||
return "" | |||
end | |||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
:addClass('wikitable sound-table mw-collapsible mw-collapsed') | :addClass('wikitable sound-table mw-collapsible mw-collapsed') | ||
| Linia 14: | Linia 17: | ||
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') | 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 subHeader = root:tag('tr') | ||
| Linia 50: | Linia 52: | ||
function p.main(frame) | function p.main(frame) | ||
-- | -- RAPORT STARTOWY (zawsze się wyświetli, jeśli moduł w ogóle ruszy) | ||
local report = '<div style="background:#f8f9fa; border:1px solid #ddd; padding:10px; font-size:12px;">' | |||
report = report .. "<strong>Status modułu:</strong> Uruchomiony.<br>" | |||
if not success then | if not success then | ||
return '<span | return report .. '<span style="color:red;">Błąd: Nie znaleziono bazy danych pod adresem: ' .. dataPath .. '</span></div>' | ||
end | end | ||
local parentArgs = frame:getParent().args | local parentArgs = frame:getParent().args | ||
local currentArgs = frame.args | local currentArgs = frame.args | ||
local id = parentArgs[1] or currentArgs[1] | |||
if not id or id == "" then | if not id or id == "" then | ||
return '< | return report .. 'Wpisz ID bloku, np. <code>{{#invoke:SandBox/Igorczewski6524/Dźwięki|main|copper}}</code></div>' | ||
end | end | ||
id = mw.text.trim(id) | id = mw.text.trim(id) | ||
report = report .. "<strong>Szukane ID:</strong> " .. id .. "<br>" | |||
local blockData = data[id] | local blockData = data[id] | ||
if not blockData then | if not blockData then | ||
return '<span | return report .. '<span style="color:red;">Błąd: Klucz "' .. id .. '" nie istnieje w pliku /Dane.</span></div>' | ||
end | end | ||
local | local javaRes = renderTable('Java Edition', blockData.java, parentArgs[2] or id, blockData.ikona) | ||
local bedrockRes = renderTable('Bedrock Edition', blockData.bedrock, parentArgs[2] or id, blockData.ikona) | |||
local finalOutput = javaRes .. bedrockRes | |||
-- Jeśli po renderowaniu nadal nic nie ma, pokaż dlaczego | |||
if finalOutput == "" then | |||
return report .. '<span style="color:orange;">Znaleziono klucz "' .. id .. '", ale sekcje "java" i "bedrock" wewnątrz niego są puste lub źle sformatowane.</span></div>' | |||
end | end | ||
return | |||
-- Jeśli wszystko jest OK, pokaż tabelę (możesz usunąć "report .." jeśli chcesz mieć czysty wygląd) | |||
return report .. "Sukces! Tabela wygenerowana poniżej.</div><br>" .. finalOutput | |||
end | end | ||
return p | return p | ||
Wersja z 21:10, 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. ADRESACJA - tutaj wpisujemy Twoją pełną ś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)
-- Jeśli tu wejdziemy i editionData jest puste, funkcja nic nie pokaże
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)
-- RAPORT STARTOWY (zawsze się wyświetli, jeśli moduł w ogóle ruszy)
local report = '<div style="background:#f8f9fa; border:1px solid #ddd; padding:10px; font-size:12px;">'
report = report .. "<strong>Status modułu:</strong> Uruchomiony.<br>"
if not success then
return report .. '<span style="color:red;">Błąd: Nie znaleziono bazy danych pod adresem: ' .. dataPath .. '</span></div>'
end
local parentArgs = frame:getParent().args
local currentArgs = frame.args
local id = parentArgs[1] or currentArgs[1]
if not id or id == "" then
return report .. 'Wpisz ID bloku, np. <code>{{#invoke:SandBox/Igorczewski6524/Dźwięki|main|copper}}</code></div>'
end
id = mw.text.trim(id)
report = report .. "<strong>Szukane ID:</strong> " .. id .. "<br>"
local blockData = data[id]
if not blockData then
return report .. '<span style="color:red;">Błąd: Klucz "' .. id .. '" nie istnieje w pliku /Dane.</span></div>'
end
local javaRes = renderTable('Java Edition', blockData.java, parentArgs[2] or id, blockData.ikona)
local bedrockRes = renderTable('Bedrock Edition', blockData.bedrock, parentArgs[2] or id, blockData.ikona)
local finalOutput = javaRes .. bedrockRes
-- Jeśli po renderowaniu nadal nic nie ma, pokaż dlaczego
if finalOutput == "" then
return report .. '<span style="color:orange;">Znaleziono klucz "' .. id .. '", ale sekcje "java" i "bedrock" wewnątrz niego są puste lub źle sformatowane.</span></div>'
end
-- Jeśli wszystko jest OK, pokaż tabelę (możesz usunąć "report .." jeśli chcesz mieć czysty wygląd)
return report .. "Sukces! Tabela wygenerowana poniżej.</div><br>" .. finalOutput
end
return p