FANDOM


local Sale = {}
local lib = require('Module:Funkcje')
local FN = require('Module:Filename')
 
Sale.args = {}
 
function Sale.wyprzedaz(frame)
    local groups
    Sale.args, groups = lib.groupedArguments(lib.arguments(lib.mergeFrames(frame, frame:getParent())))
 
    Sale.width = (tonumber(Sale.args['Szerokość']) or 109) - 2
    Sale.cols = math.max(1, tonumber(Sale.args['Kolumny']) or 6)
    Sale.discount = math.min(100, math.max(0, tonumber(Sale.args['Zniżka']) or 50)) / 100
 
    local keys = lib.getSortedKeys(groups)
 
    local salediv = mw.html.create('div'):addClass('sale'):css('text-align', 'center'):tag('div'):wikitext(Sale.args['Tytuł']):addClass('sale-title'):done()
 
    if Sale.args['Od'] or Sale.args['Do'] then
        local t = getTimespan(Sale.args['Od'], Sale.args['Do'])
        if t then
            salediv:tag('div'):addClass('sale-time'):wikitext(t)
        end
    end
 
    local row
    local counter = 1
    for i,k in ipairs(keys) do
        local box = singleBox(groups[k])
        if box then
            if i%Sale.cols == 1 then
                row = mw.html.create('table'):cssText('width:100%;table-layout:fixed;'):tag('tr')
                salediv:node(row:allDone())
            end
            row:tag('td'):css('vertical-align', 'top'):node(box)
            counter = counter + 1
        end
    end
 
    return salediv
end
function getTimespan(from, to)
    if from == nil and to == nil then
        return nil
    elseif from ~= nil and to ~= nil then
        local fromformat, toformat = 'j xg Y', 'j xg Y'
        local start = os.date('*t', tonumber(mw.getCurrentFrame():preprocess('{{#time:U|' .. from .. '}}')))
        local finish = os.date('*t', tonumber(mw.getCurrentFrame():preprocess('{{#time:U|' .. to .. '}}')))
 
        if start.year == finish.year then
            fromformat = 'j xg'
            if start.month == finish.month then
                fromformat = 'j'
                if start.day == finish.day then
                    return mw.getCurrentFrame():preprocess('{{#iferror:{{#time:j xg Y|' .. from .. '}}|' .. from .. '}}')
                end
            end
        end
 
        return mw.getCurrentFrame():preprocess('{{#iferror:{{#time:' .. fromformat .. '|' .. from .. '}}|' .. from .. '}} – {{#iferror:{{#time:' .. toformat .. '|' .. to .. '}}|' .. to .. '}}')
    else
        from = from or to
        return mw.getCurrentFrame():preprocess('{{#iferror:{{#time:j xg Y|' .. from .. '}}|' .. from .. '}}')
    end
end
function singleBox(args)
    local box = mw.html.create('div'):addClass('sale-skin')
 
    local image = box:tag('div'):addClass('sale-image')
    local label = box:tag('div'):addClass('sale-label')
 
    local skin = mw.ustring.gsub(args['Skórka'] or '', '%s*<%s*[Bb][Rr]%s*/?>%s*', ' ')
    local link, text
 
    if skin ~= '' then
        link = args['link'] or (args['Bohater'] .. '/skórki i ciekawostki#' .. mw.uri.anchorEncode(skin))
        text = args['text'] or args['Skórka'] or ''
    else
        skin = nil
        link = args['link'] or args['Bohater'] or ''
        text = args['text'] or args['Bohater'] or ''
    end
    if link == '*none*' then link = '' end
 
    if link ~= '' then
        label:wikitext('[[' .. link .. '|' .. text .. ']]')
    else
        label:wikitext(text)
    end
 
    local img = image:tag('div')
    local file = FN.loading{
        champion = args['Bohater'],
        skin = skin
    }
    img:wikitext(mw.ustring.format('[[File:%s|%dpx|%s]]', file, Sale.width, skin or args['Bohater']))
 
    if skin == nil then
        local price = tonumber(args['PZ'] or mw.getCurrentFrame():preprocess('{{dane/' .. args['Bohater'] .. '|swp2|pz}}'))
        if price ~= nil then
            local ip = image:tag('div'):addClass('sale-ip-price'):wikitext(math.floor(price))
        end
    end
 
    local full = tonumber(args['RP przed'])
    local disc = tonumber(args['RP po'])
 
    if full ~= nil and disc == nil then
        full = math.floor(full)
        disc = math.floor(full*Sale.discount)
    elseif full == nil and disc ~= nil then
        disc = math.floor(disc)
        full = math.floor(disc/Sale.discount)
    end
 
    if full ~= nil and disc ~= nil then
        local rpn = image:tag('div'):addClass('sale-rp-price-new'):wikitext(disc)
        local rpo = image:tag('div'):addClass('sale-rp-price-old'):wikitext(full)
        local change = priceChange(full, disc)
        if change < 0 then local discount = image:tag('div'):addClass('sale-discount'):wikitext(change .. '%') end
    end
    return box
end
function priceChange(original, new) return math.floor((new/original)*100+0.5) - 100 end
return Sale

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.