Модуль:GiftData: различия между версиями
м (Защитил страницу Модуль:GiftData ([Редактирование=Разрешено только администраторам] (бессрочно) [Переименование=Разрешено только администраторам] (бессрочно))) |
Нет описания правки |
||
| Строка 7: | Строка 7: | ||
local get = require ('Module:GiftData/getter') | local get = require ('Module:GiftData/getter') | ||
local | local gift = args['gift'] or args[1] | ||
local datatype = args['datatype'] or args[2] | local datatype = args['datatype'] or args[2] | ||
local output = args['output'] or args[3] or nil | local output = args['output'] or args[3] or nil | ||
local result = get[datatype]( | local result = get[datatype](gift) | ||
if output ~= nil and type(result) == "table" then | if output ~= nil and type(result) == "table" then | ||
Версия от 05:20, 14 июня 2023
Данная группа модулей хранит информацию обо всех подарках героев из Крушителей подземелий. Перечень модулей:
- Модуль:GiftData - основные функции
- Модуль:GiftData/data - массив данных о подарках
- Модуль:GiftData/getter - сборщик данных о подарках
- Модуль:GiftData/gifts - массив данных с содержимым подарков
- Модуль:GiftData/categories - массив данных с категориями подарков
Информация из Модуль: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 = "gift_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 = "gift_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 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', p.getItemIcon(v[k2][1], "60px", v[k2][2])))
:done()
end
end
end
return frame:preprocess(tostring(divNode))
end
return p