Moduł:Dźwięki: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| [wersja przejrzana] | [wersja przejrzana] |
Nie podano opisu zmian |
d Igorczewski6524 przeniósł(-osła) stronę Moduł:SandBox/Igorczewski6524/Dźwięki do Moduł:Dźwięki, bez pozostawienia przekierowania pod starym tytułem: Moduł jest już w zasadzie gotowy, muszę tylko dodać resztę danych |
||
| (Nie pokazano 11 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
| Linia 1: | Linia 1: | ||
local p = {} | local p = {} | ||
-- Funkcja pomocnicza do budowania tabeli | |||
local function renderTable(frame, editionName, editionData, codeName, icon, upcoming) | |||
local function renderTable(editionName, editionData, | if type(editionData) ~= "table" then return "" end | ||
if | |||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
| Linia 13: | Linia 10: | ||
:css('font-size', '0.9em') | :css('font-size', '0.9em') | ||
local iconWiki = (icon and icon ~= "") and ('[[ | -- Nagłówek główny w formacie: Dźwięki <ikona> <code>kod</code> | ||
root:tag('tr') | local iconWiki = (icon and icon ~= "") and ('[[File:' .. icon .. '|20px|link=]] ') or "" | ||
root:tag('tr'):tag('th') | |||
:attr('colspan', editionName == 'Java Edition' and '9' or '8') | |||
:wikitext("Tabela dźwięków " .. iconWiki) | |||
:tag('code'):wikitext(codeName):done() | |||
-- Nagłówki kolumn | |||
local subHeader = root:tag('tr') | local subHeader = root:tag('tr') | ||
local headers = {" | local headers = {"Dźwięki", "Napisy", "Źródło", "Opis", "Identyfikator", "Klucz tłumaczenia", "Głośność", "Wysokość"} | ||
if editionName == 'Java Edition' then table.insert(headers, " | if editionName == 'Java Edition' then table.insert(headers, "Odległość rozgłosu") end | ||
for _, | for _, hName in ipairs(headers) do | ||
subHeader:tag('th'):wikitext( | local th = subHeader:tag('th'):wikitext(hName) | ||
if (hName == "Napisy" or hName == "Klucz tłumaczenia") and upcoming and upcoming ~= "" then | |||
th:tag('br'):done() | |||
:tag('small'):css('color', '#0645ad'):css('font-weight', 'normal'):wikitext('[upcoming: ' .. upcoming .. ']') | |||
end | |||
end | end | ||
for _, group in | -- Generowanie wierszy | ||
local rowFound = false | |||
for _, group in pairs(editionData) do | |||
if type(group) == "table" and group.zdarzenia then | |||
local eventCount = 0 | |||
for _ in pairs(group.zdarzenia) do eventCount = eventCount + 1 end | |||
if i == 1 then | for i, row in ipairs(group.zdarzenia) do | ||
rowFound = true | |||
local tr = root:tag('tr') | |||
-- KOLUMNA DŹWIĘKI | |||
end | if i == 1 then | ||
local sCell = tr:tag('td'):attr('rowspan', eventCount):css('text-align', 'center'):css('vertical-align', 'middle'):css('min-width', '120px') | |||
if group.pliki then | |||
for _, file in ipairs(group.pliki) do sCell:wikitext('[[File:' .. file .. ']]<br>') end | |||
else sCell:wikitext('—') end | |||
end | |||
-- DANE KOMÓREK | |||
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 "1.0"):done() | |||
tr:tag('td'):wikitext(row.pitch or "1.0"):done() | |||
if editionName == 'Java Edition' then | |||
tr:tag('td'):wikitext(row.dist or "16"):done() | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
if not rowFound then return "" end | |||
return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root) | |||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
if | local pArgs = frame:getParent().args | ||
local fArgs = frame.args | |||
-- 1. Pobieranie ID (nazwa kodowa pliku danych) | |||
local id = mw.text.trim(pArgs[1] or fArgs[1] or "") | |||
if id == "" then return "Błąd: Podaj nazwę kodową dźwięków (np. Copper)." end | |||
local | -- 2. DYNAMICZNA ŚCIEŻKA | ||
local | local dataSubPath = 'Moduł:SandBox/Igorczewski6524/Dźwięki/Dane/' .. id | ||
local success, blockData = pcall(mw.loadData, dataSubPath) | |||
local | |||
if not success then | |||
return '<span class="error">Błąd: Nie znaleziono danych pod nazwą: ' .. dataSubPath .. '</span>' | |||
end | |||
-- 3. Logika rozpoznawania filtra wersji | |||
-- Sprawdzamy drugi parametr - jeśli to "java" lub "bedrock", filtrujemy. | |||
local rawArg2 = mw.text.trim(pArgs[2] or fArgs[2] or ""):lower() | |||
local | local wersja = "" | ||
if | if rawArg2 == "java" or rawArg2 == "bedrock" then | ||
wersja = rawArg2 | |||
end | end | ||
local | -- 4. Generowanie wyniku | ||
local out = "" | |||
if wersja == "java" then | if wersja == "java" then | ||
out = renderTable(frame, 'Java Edition', blockData.java, id, blockData.ikona, blockData.java_upcoming) | |||
elseif wersja == "bedrock" then | elseif wersja == "bedrock" then | ||
out = renderTable(frame, 'Bedrock Edition', blockData.bedrock, id, blockData.ikona, blockData.bedrock_upcoming) | |||
else | else | ||
local | local j = renderTable(frame, 'Java Edition', blockData.java, id, blockData.ikona, blockData.java_upcoming) | ||
local | local b = renderTable(frame, 'Bedrock Edition', blockData.bedrock, id, blockData.ikona, blockData.bedrock_upcoming) | ||
out = j .. b | |||
end | end | ||
return | return out | ||
end | end | ||
return p | return p | ||
Aktualna wersja na dzień 01:01, 5 sty 2026
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
-- Funkcja pomocnicza do budowania tabeli
local function renderTable(frame, editionName, editionData, codeName, icon, upcoming)
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')
-- Nagłówek główny w formacie: Dźwięki <ikona> <code>kod</code>
local iconWiki = (icon and icon ~= "") and ('[[File:' .. icon .. '|20px|link=]] ') or ""
root:tag('tr'):tag('th')
:attr('colspan', editionName == 'Java Edition' and '9' or '8')
:wikitext("Tabela dźwięków " .. iconWiki)
:tag('code'):wikitext(codeName):done()
-- Nagłówki kolumn
local subHeader = root:tag('tr')
local headers = {"Dźwięki", "Napisy", "Źródło", "Opis", "Identyfikator", "Klucz tłumaczenia", "Głośność", "Wysokość"}
if editionName == 'Java Edition' then table.insert(headers, "Odległość rozgłosu") end
for _, hName in ipairs(headers) do
local th = subHeader:tag('th'):wikitext(hName)
if (hName == "Napisy" or hName == "Klucz tłumaczenia") and upcoming and upcoming ~= "" then
th:tag('br'):done()
:tag('small'):css('color', '#0645ad'):css('font-weight', 'normal'):wikitext('[upcoming: ' .. upcoming .. ']')
end
end
-- Generowanie wierszy
local rowFound = false
for _, group in pairs(editionData) do
if type(group) == "table" and group.zdarzenia then
local eventCount = 0
for _ in pairs(group.zdarzenia) do eventCount = eventCount + 1 end
for i, row in ipairs(group.zdarzenia) do
rowFound = true
local tr = root:tag('tr')
-- KOLUMNA DŹWIĘKI
if i == 1 then
local sCell = tr:tag('td'):attr('rowspan', eventCount):css('text-align', 'center'):css('vertical-align', 'middle'):css('min-width', '120px')
if group.pliki then
for _, file in ipairs(group.pliki) do sCell:wikitext('[[File:' .. file .. ']]<br>') end
else sCell:wikitext('—') end
end
-- DANE KOMÓREK
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 "1.0"):done()
tr:tag('td'):wikitext(row.pitch or "1.0"):done()
if editionName == 'Java Edition' then
tr:tag('td'):wikitext(row.dist or "16"):done()
end
end
end
end
if not rowFound then return "" end
return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root)
end
function p.main(frame)
local pArgs = frame:getParent().args
local fArgs = frame.args
-- 1. Pobieranie ID (nazwa kodowa pliku danych)
local id = mw.text.trim(pArgs[1] or fArgs[1] or "")
if id == "" then return "Błąd: Podaj nazwę kodową dźwięków (np. Copper)." end
-- 2. DYNAMICZNA ŚCIEŻKA
local dataSubPath = 'Moduł:SandBox/Igorczewski6524/Dźwięki/Dane/' .. id
local success, blockData = pcall(mw.loadData, dataSubPath)
if not success then
return '<span class="error">Błąd: Nie znaleziono danych pod nazwą: ' .. dataSubPath .. '</span>'
end
-- 3. Logika rozpoznawania filtra wersji
-- Sprawdzamy drugi parametr - jeśli to "java" lub "bedrock", filtrujemy.
local rawArg2 = mw.text.trim(pArgs[2] or fArgs[2] or ""):lower()
local wersja = ""
if rawArg2 == "java" or rawArg2 == "bedrock" then
wersja = rawArg2
end
-- 4. Generowanie wyniku
local out = ""
if wersja == "java" then
out = renderTable(frame, 'Java Edition', blockData.java, id, blockData.ikona, blockData.java_upcoming)
elseif wersja == "bedrock" then
out = renderTable(frame, 'Bedrock Edition', blockData.bedrock, id, blockData.ikona, blockData.bedrock_upcoming)
else
local j = renderTable(frame, 'Java Edition', blockData.java, id, blockData.ikona, blockData.java_upcoming)
local b = renderTable(frame, 'Bedrock Edition', blockData.bedrock, id, blockData.ikona, blockData.bedrock_upcoming)
out = j .. b
end
return out
end
return p