Vai al contenuto

Modulo:StileAttacco: differenze tra le versioni

Da BridgePedia.
Create Lua module for lead style table
 
Intestazioni esplicite
 
(2 versioni intermedie di uno stesso utente non sono mostrate)
Riga 19: Riga 19:
      
      
     if not args then
     if not args then
         return '<div style="color:red">DEBUG: nessun lead_holding_1 trovato</div>'
         return ''
    end
   
    -- Debug: show raw value of lead_holding_1
    local raw1 = args['lead_holding_1'] or 'NIL'
    local rawLen = #raw1
    local rawBytes = {}
    for i = 1, math.min(rawLen, 50) do
        table.insert(rawBytes, string.byte(raw1, i))
     end
     end
      
      
Riga 47: Riga 39:
      
      
     if #rows == 0 then
     if #rows == 0 then
         return '<div style="color:orange">DEBUG: raw1=[' .. raw1 .. '] len=' .. rawLen .. ' bytes=[' .. table.concat(rawBytes, ',') .. '] rows=0</div>'
         return ''
     end
     end
      
      
Riga 56: Riga 48:
      
      
     local headerRow = html:tag('tr')
     local headerRow = html:tag('tr')
     headerRow:tag('th'):css('width', '30%'):wikitext('Possesso')
     headerRow:tag('th'):css('width', '25%'):wikitext('Possesso')
     headerRow:tag('th'):css('width', '20%'):wikitext('vs Atout')
     headerRow:tag('th'):css('width', '20%'):wikitext('Attacco vs Atout')
     headerRow:tag('th'):css('width', '20%'):wikitext('vs SA')
     headerRow:tag('th'):css('width', '20%'):wikitext('Attacco vs SA')
     headerRow:tag('th'):css('width', '30%'):wikitext('Comp.')
     headerRow:tag('th'):css('width', '35%'):wikitext('Su attacco del compagno')
      
      
     for _, row in ipairs(rows) do
     for _, row in ipairs(rows) do

Versione attuale delle 06:39, 12 mar 2026

La documentazione per questo modulo può essere creata in Modulo:StileAttacco/man

local p = {}

function p.tabella(frame)
    local parentFrame = frame:getParent()
    
    local args = nil
    if parentFrame then
        local val = parentFrame.args['lead_holding_1']
        if val and val ~= '' then
            args = parentFrame.args
        end
    end
    if not args then
        local val = frame.args['lead_holding_1']
        if val and val ~= '' then
            args = frame.args
        end
    end
    
    if not args then
        return ''
    end
    
    local rows = {}
    for i = 1, 99 do
        local val = args['lead_holding_' .. i]
        if not val or val == '' then
            break
        end
        local parts = {}
        for part in (val .. ';'):gmatch('([^;]*);') do
            table.insert(parts, mw.text.trim(part))
        end
        while #parts < 4 do
            table.insert(parts, '')
        end
        table.insert(rows, parts)
    end
    
    if #rows == 0 then
        return ''
    end
    
    local html = mw.html.create('table')
        :addClass('wikitable')
        :css('width', '100%')
        :css('margin-top', '8px')
    
    local headerRow = html:tag('tr')
    headerRow:tag('th'):css('width', '25%'):wikitext('Possesso')
    headerRow:tag('th'):css('width', '20%'):wikitext('Attacco vs Atout')
    headerRow:tag('th'):css('width', '20%'):wikitext('Attacco vs SA')
    headerRow:tag('th'):css('width', '35%'):wikitext('Su attacco del compagno')
    
    for _, row in ipairs(rows) do
        local tr = html:tag('tr')
        tr:tag('td'):css('font-weight', 'bold'):wikitext(row[1])
        tr:tag('td'):css('text-align', 'center'):wikitext(row[2])
        tr:tag('td'):css('text-align', 'center'):wikitext(row[3])
        tr:tag('td'):css('text-align', 'center'):wikitext(row[4])
    end
    
    return tostring(html)
end

return p