Lostpedia

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Tagi/opis

local p = {}
local lang = mw.language.getContentLanguage()
local getArgs = require('Dev:Arguments').getArgs

p.postacie = mw.loadData('Moduł:Tagi/postacie')
p.odcinki = mw.loadData('Moduł:Tagi/odcinki')
p.wystapienie = {
    retro = '[[Kategoria:Postacie z retrospekcji]]',
    futuro = '[[Kategoria:Postacie z futurospekcji]]',
    alt = '[[Kategoria:Postacie z równoległej linii czasowej]]',
}
function p._decodeEp(code, pair)
    code = mw.ustring.lower(tostring(code))
    local res = mw.text.split(code, 'x')
    if #res >= 2 then
        local s = tonumber(res[1]) or res[1]
        local e = tonumber(res[2]) or res[2]
        if type(e) == 'string' then
            local res = mw.text.split(e, '/')
            for i,v in ipairs(res) do
                v = mw.text.trim(v)
                res[i] = tonumber(v) or v
            end
            if pair then
                e = res
            else
                e = table.concat(res, '/')
            end
        end
        return {s, e}
    end
    return nil
end
function p._getEp(s, e)
    if not p.odcinki[s] or not p.odcinki[s][e] then return nil end
    local ep = p.odcinki[s][e]
    if type(ep) == 'table' then
        mw.log(ep[2])
        return ep[1], ep[2]
    end
    return tostring(ep)
end
function p._getEpDetails(args)
    local func = p._details[args[2]]
    if not func then return nil end
    return func(args)
end
function p._dataListToText(list, separator, conjunction)
    local newlist = {}
    if list then
        for i, v in ipairs(list) do
            mw.log(i, v)
            newlist[i] = v
        end
    end
    return mw.text.listToText(newlist, separator, conjunction)
end
p._details = {
    [1] = function(args)
        local s, e = unpack(args[1])
        return mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).title_pl
    end,
    [2] = function(args)
        local s, e = unpack(args[1])
        local list = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).centric
        return p._dataListToText(list, args[3], args[4] or args[3])
    end,
    [3] = function(args)
        local s, e = unpack(args[1])
        local ts = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).abc
        return lang:formatDate(args[3] or 'j xg Y', ts)
    end,
    [4] = function(args)
        local s, e = unpack(args[1])
        local ts = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).tvp
        return lang:formatDate(args[3] or 'j xg Y', ts)
    end,
    [5] = function(args)
        local s, e = unpack(args[1])
        local ts = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).axn
        return lang:formatDate(args[3] or 'j xg Y', ts)
    end,
    [6] = function(args)
        local s, e = unpack(args[1])
        local list = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).directors
        return p._dataListToText(list, args[3], args[4] or args[3])
    end,
    [7] = function(args)
        local s, e = unpack(args[1])
        local list = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).writers
        return p._dataListToText(list, args[3], args[4] or args[3])
    end,
    [8] = function(args)
        local s, e = unpack(args[1])
        local list = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).guests
        return p._dataListToText(list, args[3], args[4] or args[3])
    end,
    [9] = function(args)
        return (p._getEp(unpack(args[1])))
    end,
    [10] = function(args)
        local s, e = unpack(args[1])
        local list = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).stars
        return p._dataListToText(list, args[3], args[4] or args[3])
    end,
    [11] = function(args)
        local s, e = unpack(args[1])
        local list = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).costars
        return p._dataListToText(list, args[3], args[4] or args[3])
    end,
    [12] = function(args)
        local s, e = unpack(args[1])
        return mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).days
    end,
    [13] = function(args)
        local s, e = unpack(args[1])
        return mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e)).image
    end,
    [14] = function(args)
        local s, e = unpack(args[1])
        local episode = mw.loadData('Moduł:Tagi/odcinki/' .. tostring(s) .. '/' .. tostring(e))
        return episode.article or episode.title
    end,
}


function p.ep_prev(frame)
    local s, e = unpack(p._decodeEp(frame.args[1], true))
    if type(e) == 'table' then e = e[1] end
    
    if type(e) == 'string' and s == 6 and e:lower() == 'ep' then return '6x17/18' end
    local new_e = e-1
    if new_e < 1 then
        if s == 1 then
            return nil
        elseif s == 2 then
            return '1x24/25'
        elseif s == 3 then
            return '2x23/24'
        elseif s == 4 then
            return '3x22/23'
        elseif s == 5 then
            return '4x13/14'
        elseif s == 6 then
            return '5x16/17'
        end
    elseif s == 6 and new_e == 2 then
        return '6x01/02'
    end
    return tostring(s)..'x'..mw.ustring.format('%02d', new_e)
end
function p.ep_next(frame)
    local s, e = unpack(p._decodeEp(frame.args[1], true))
    if type(e) == 'table' then e = e[#e] end
    if type(e) == 'string' then return nil end
    
    local new_e = e+1
    if s == 1 and new_e == 24 then
        return '1x24/25'
    elseif s == 1 and new_e > 25 then
        return '2x01'
    elseif s == 2 and new_e == 23 then
        return '2x23/24'
    elseif s == 2 and new_e > 24 then
        return '3x01'
    elseif s == 3 and new_e == 22 then
        return '3x22/23'
    elseif s == 3 and new_e > 23 then
        return '4x01'
    elseif s == 4 and new_e == 13 then
        return '4x13/14'
    elseif s == 4 and new_e > 14 then
        return '5x01'
    elseif s == 5 and new_e == 16 then
        return '5x16/17'
    elseif s == 5 and new_e > 17 then
        return '6x01/02'
    elseif s == 6 and new_e == 17 then
        return '6x17/18'
    elseif s == 6 and new_e > 18 then
        return '6xEP'
    end
    return tostring(s)..'x'..mw.ustring.format('%02d', new_e)
end

function p.ep(frame)
    return (p._ep(getArgs(frame, {
        removeBlanks = true,
    	valueFunc = function (key, value)
    	    if key == 'link' then
    	        value = mw.text.trim(tostring(value or 1))
    		    if tonumber(value) == 0 or value == '' or value == 'no' or value == 'nie' then
    		        return nil
    		    end
    		    return 1
    		elseif key == 2 then
    		    local trimmed = mw.text.trim(tostring(value))
    		    if not value or trimmed == '' then return nil end
    		    local v = mw.ustring.lower(trimmed)
    		    local f = ({
		            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
		            ['pl'] = 1,
		            ['centryczne'] = 2,
		            ['abc'] = 3,
		            ['tvp'] = 4,
		            ['axn'] = 5,
		            ['reżyseria'] = 6,
		            ['scenariusz'] = 7,
		            ['gościnnie'] = 8,
		            ['en'] = 9,
		            ['obsada'] = 10,
		            ['pozostali'] = 11,
		            ['dni'] = 12,
		            ['obraz'] = 13,
		            ['art'] = 14,
		        })[tonumber(v) or v]
    			return f or trimmed
    		end
    	    if value then
        		value = tostring(value)
        		if key == 1 then
        			return p._decodeEp(value)
        		elseif key == 3 or key == 4 then
            		if mw.text.trim(value) == '' then return nil end
        		    return value
        		end
        		local value = mw.text.trim(value)
        		if value == '' then return nil end
        		return value
        	end
    		return nil
    	end,
    	readOnly = true
    })) or '')
end
function p._ep(args)
    if not args[1] then return nil end
    if args[2] and type(args[2]) == 'number' and args[2] > 0 then return p._getEpDetails(args) end
        
    local text = args[2]
    if type(text) == 'number' and text <= 0 then text = nil end
        
    local title, link = p._getEp(unpack(args[1]))
    
    local prefix, suffix = args[3], args[4]
    
    local comp = {}
    
    if prefix then table.insert(comp, prefix) end
    if args.link then
        table.insert(comp, '[[')
        
        if link or text then table.insert(comp, (link or title) .. '|') end
        table.insert(comp, text or title)
        
        table.insert(comp, ']]')
    else
        table.insert(comp, link or title)
    end
    if suffix then table.insert(comp, suffix) end
    
    return table.concat(comp, '')
end

return p
-- [[Kategoria:Moduły]]