Moduł:Dźwięki: Różnice pomiędzy wersjami

Z Minecraft Wiki Polska
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 = {}


local success, data = pcall(mw.loadData, mw.getCurrentFrame():getTitle() .. '/Dane')
-- 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)
local function renderTable(editionName, editionData, displayTitle, icon)
Linia 31: Linia 35:
         for i, row in ipairs(group.zdarzenia) do
         for i, row in ipairs(group.zdarzenia) do
             local tr = root:tag('tr')
             local tr = root:tag('tr')
           
             if i == 1 then
             if i == 1 then
                 local soundCell = tr:tag('td'):attr('rowspan', rowCount):css('text-align', 'center'):css('vertical-align', 'middle')
                 local soundCell = tr:tag('td'):attr('rowspan', rowCount):css('text-align', 'center'):css('vertical-align', 'middle')
Linia 40: Linia 43:
                 end
                 end
             end
             end
           
             tr:tag('td'):wikitext(row.captions or "?"):done()
             tr:tag('td'):wikitext(row.captions or "?"):done()
             tr:tag('td'):wikitext(row.source or ""):done()
             tr:tag('td'):wikitext(row.source or ""):done()
Linia 48: Linia 50:
             tr:tag('td'):wikitext(row.vol or ""):done()
             tr:tag('td'):wikitext(row.vol or ""):done()
             tr:tag('td'):wikitext(row.pitch or ""):done()
             tr:tag('td'):wikitext(row.pitch or ""):done()
             if editionName == 'Java Edition' then
             if editionName == 'Java Edition' then tr:tag('td'):wikitext(row.dist or ""):done() end
                tr:tag('td'):wikitext(row.dist or ""):done()
            end
         end
         end
     end
     end


     local linkLabel = "'''[[" .. editionName .. "]]:'''"
     return '<p>\'\'\'[[' .. editionName .. ']]:\'\'\'</p>' .. tostring(root)
    return '<p>' .. linkLabel .. '</p>' .. tostring(root)
end
end


function p.main(frame)
function p.main(frame)
     -- 1. Pobieramy argumenty (sprawdzamy obie metody naraz)
     -- 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 parentArgs = frame:getParent().args
     local currentArgs = frame.args
     local currentArgs = frame.args
      
      
     -- Wybieramy te, które nie są puste
     -- Szukamy ID w różnych miejscach (z szablonu lub bezpośrednio)
     local id = parentArgs[1] or currentArgs[1]
     local id = parentArgs[1] or currentArgs[1]
     local nazwa = parentArgs[2] or currentArgs[2] or id
     local nazwa = parentArgs[2] or currentArgs[2] or id
     local wersja = string.lower(parentArgs[3] or currentArgs[3] or "")
     local wersja = string.lower(parentArgs[3] or currentArgs[3] or "")


     -- 2. Jeśli ID jest nadal puste (np. w podglądzie modułu), używamy miedzi jako testu
     -- 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
     if not id or id == "" then
         -- Zamiast błędu nil, pokazujemy instrukcję lub domyślny blok
         return '<div style="border:1px solid orange; padding:10px;">' ..
        id = "copper"
              '<strong>Witaj w module dźwięków!</strong><br>' ..
        nazwa = "Miedź (Test)"
              'Aktualnie moduł szuka bazy w: <code>' .. dataPath .. '</code><br>' ..
              'Aby wyświetlić tabelę, użyj: <code>{{#invoke:' .. currentTitle .. '|main|copper}}</code>' ..
              '</div>'
     end
     end


     -- 3. Sprawdzamy czy ID istnieje w bazie
     -- SPRAWDZANIE KLUCZA W BAZIE
     local blockData = data[id]
     local blockData = data[id]
     if not blockData then  
     if not blockData then  
         return '<span class="error">Błąd: Klucz "' .. tostring(id) .. '" nie istnieje w Moduł:Dźwięki/Dane.</span>'  
        -- 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
     end


    -- 4. Generowanie tabel
     local output = ""
     local output = ""
     if wersja == "java" then
     if wersja == "java" then
Linia 88: Linia 99:
         output = renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona)
         output = renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona)
     else
     else
         -- Standardowo obie edycje
         output = renderTable('Java Edition', blockData.java, nazwa, blockData.ikona) ..
        local javaRes = renderTable('Java Edition', blockData.java, nazwa, blockData.ikona)
                renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona)
        local bedrockRes = renderTable('Bedrock Edition', blockData.bedrock, nazwa, blockData.ikona)
        output = javaRes .. bedrockRes
     end
     end



Wersja z 21:05, 3 sty 2026

[ utwórz | historia | odśwież ]Dokumentacja
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