Модуль:GiftData

Данная группа модулей хранит информацию обо всех подарках героев из Крушителей подземелий. Перечень модулей:

Информация из Модуль:GiftData/doc


local p = {}

local lib     = require('Module:Feature')

function p.get(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	
	local get      = require ('Module:GiftData/getter')
    local gift     = args['gift'] or args[1]
    local datatype = args['datatype'] or args[2]
    local output   = args['output'] or args[3] or nil
    
    local result = get[datatype](gift)
    
    if output ~= nil and type(result) == "table" then
        if output == "csv" then
            return lib.tbl_concat{result}
        elseif output == "custom" then 
            return frame:preprocess(lib.tbl_concat({result, prepend = args['prepend'], append = args['append'], separator = args['separator'], index = args["index"]}))
        elseif output == "template" then 
            return frame:preprocess(lib.tbl_concat{result, prepend = "{{" .. args['t_name'] .. "|", append = "}}", separator = args['separator']})
        end
    elseif result == nil then
        return ""
    else
        return result
    end
end

function p.getGifts(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get       = require ('Module:GiftData/getter')
	local gift      = args['gift'] or args[1]
	local str       = ""
	
	local source = get["source"](gift)

	str = mw.ustring.format('{{Gift|%s|source=%s}}', gift, source)
    
    return frame:preprocess(tostring(str))
end

function p.getGiftPack(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get       = require ('Module:GiftData/getter')
	local gift      = args['gift'] or args[1]
	local gift_data = "gifts_data"
	local count

	local result = get[gift_data](gift)
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
			count = mw.ustring.format('%d', v[2])
		end
    end
    
    return tonumber(count)
end

function p.getGiftType(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get       = require ('Module:GiftData/getter')
	local gift_type = require('Module:ItemData/loot/types')
	local gift      = args['gift'] or args[1]
	local gift_data = "gifts_data"
	local type      = ""

	local result = get[gift_data](gift)
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
			type = mw.ustring.format('%s', gift_type[v[3]])
		end
    end
    
    return tostring(type)
end

function p.getGiftItems(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:GiftData/getter')
	local libItem = require('Module:ItemData')
	local gift    = args['gift'] or args[1]
	local gifts   = "gifts"
	local divNode = mw.html.create('div')
	
	divNode
		:cssText('display: flex; flex-flow: row wrap; justify-content: center;')
		:newline()

	local result = get[gifts](gift)
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
			for k2, v2 in ipairs(v) do
    			divNode
	    			:tag('div')
	    				:addClass('loot-item')
			    		:wikitext(mw.ustring.format('%s', libItem.getItemIcon(v[k2][1], "60px", v[k2][2])))
			    		:done()
		    end
		end
    end
    
    return frame:preprocess(tostring(divNode))
end

function p.getGiftSource(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local libHero     = require('Module:HeroData')
	local get         = require('Module:GiftData/getter')
	local gift        = args['gift'] or args[1]
	local i           = 0
	local str         = ""
	
	local result     = get["source"](gift)
	
	if (result ~= "Добыча") then
		str = str .. mw.ustring.format('<h2>Способ получения</h2>')
	end
	
	if (result == "Подарок") then
		str = str .. mw.ustring.format('<div class="gift" style="width:fit-content; width: -moz-fit-content">')
		if get["hero"](gift) ~= nil then
			i = i + 1
			str = str .. mw.ustring.format('%s', libHero.getHeroIcon(get["hero"](gift), "75px"))
		end
		if i == 0 then
			str = str .. "Нет данных"
		end
		str = str .. mw.ustring.format('</div>')
	end

	return frame:preprocess(tostring(str))	
end

return p