Модуль:UnitData: различия между версиями
Нет описания правки |
Нет описания правки |
||
Строка 51: | Строка 51: | ||
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end | local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end | ||
local get | local get = require ('Module:UnitData/getter') | ||
local | local recipe_data = require ('Module:RecipeData/data') | ||
local loot_data = require ('Module:ItemData/loot') | local loot_data = require ('Module:ItemData/loot') | ||
local boss_data = require ('Module:BossData/data') | local boss_data = require ('Module:BossData/data') | ||
local item_data = require ('Module:ItemData/data') | local item_data = require ('Module:ItemData/data') | ||
local unit | local unit = args['unit'] or args[1] | ||
local source | local source = "source" | ||
local str | local str = mw.ustring.format('<h2>Способ получения</h2>') | ||
local i = 0 | |||
local result | local result = get[source](unit) | ||
local data | local data = recipe_data[unit] | ||
if (result == "Крафт") then | if (result == "Крафт") then | ||
if (data) == | str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">') | ||
if data ~= nil then | |||
for k, v in ipairs(data) do | |||
i = i + 1 | |||
str = str .. mw.ustring.format('{{RecipeImage|%s|%d}}', unit, k) | |||
end | |||
end | end | ||
if i == 0 then | |||
str = str .. "Нет данных" | |||
str = str .. | |||
end | end | ||
str = str .. mw.ustring.format('</div>') | str = str .. mw.ustring.format('</div></div>') | ||
elseif (result == "Сундук") then | elseif (result == "Сундук") then | ||
str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') | str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') | ||
for k, v in ipairs(loot_data) do | for k, v in ipairs(loot_data) do | ||
for k1, v1 in ipairs(v) do | for k1, v1 in ipairs(v) do | ||
if (v[k1][1] == | if (v[k1][1] == unit) then | ||
for k2, v2 in pairs(item_data) do | for k2, v2 in pairs(item_data) do | ||
for k3, v3 in pairs(item_data[k2]["loot"]) do | for k3, v3 in pairs(item_data[k2]["loot"]) do | ||
Строка 92: | Строка 96: | ||
for k, v in pairs(boss_data) do | for k, v in pairs(boss_data) do | ||
for k2, v2 in pairs(boss_data[k]["loot"]) do | for k2, v2 in pairs(boss_data[k]["loot"]) do | ||
if (v2[1] == | if (v2[1] == unit) then | ||
str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) | str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) | ||
end | end | ||
Строка 99: | Строка 103: | ||
str = str .. mw.ustring.format('</div>') | str = str .. mw.ustring.format('</div>') | ||
elseif (result == "Крафт/Сундук") then | elseif (result == "Крафт/Сундук") then | ||
str = str .. mw.ustring.format('<div class="recipes">') | str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">') | ||
for k, v in ipairs(data) do | if data ~= nil then | ||
for k, v in ipairs(data) do | |||
i = i + 1 | |||
str = str .. mw.ustring.format('{{RecipeImage|%s|%d}}', unit, k) | |||
end | |||
end | |||
if i == 0 then | |||
str = str .. "Нет данных" | |||
end | end | ||
str = str .. mw.ustring.format('</div>') | str = str .. mw.ustring.format('</div></div>') | ||
str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') | str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') | ||
for k, v in ipairs(loot_data) do | for k, v in ipairs(loot_data) do | ||
Строка 122: | Строка 132: | ||
str = str .. mw.ustring.format('<div class="recipes">') | str = str .. mw.ustring.format('<div class="recipes">') | ||
for k, v in ipairs(data) do | for k, v in ipairs(data) do | ||
str = str .. mw.ustring.format('{{rp|%s|%d}}', | str = str .. mw.ustring.format('{{rp|%s|%d}}', unit, k) | ||
end | end | ||
str = str .. mw.ustring.format('</div>') | str = str .. mw.ustring.format('</div>') | ||
Строка 138: | Строка 148: | ||
for k, v in ipairs(loot_data) do | for k, v in ipairs(loot_data) do | ||
for k1, v1 in ipairs(v) do | for k1, v1 in ipairs(v) do | ||
if (v[k1][1] == | if (v[k1][1] == unit) then | ||
for k2, v2 in pairs(item_data) do | for k2, v2 in pairs(item_data) do | ||
for k3, v3 in pairs(item_data[k2]["loot"]) do | for k3, v3 in pairs(item_data[k2]["loot"]) do | ||
Строка 153: | Строка 163: | ||
for k, v in pairs(boss_data) do | for k, v in pairs(boss_data) do | ||
for k2, v2 in pairs(boss_data[k]["loot"]) do | for k2, v2 in pairs(boss_data[k]["loot"]) do | ||
if (v2[1] == | if (v2[1] == unit) then | ||
str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) | str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) | ||
end | end |
Версия от 09:04, 13 ноября 2022
Данная группа модулей хранит информацию обо всех юнитах из Крушителей подземелий. Перечень модулей:
- Модуль:UnitData - основные функции
- Модуль:UnitData/data - массив данных о юнитах
- Модуль:UnitData/getter - сборщик данных о юнитах
Информация из Модуль:UnitData/doc
local p = {} local lib = require('Module:Feature') local libItem = require('Module:ItemData') 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:UnitData/getter') local unit = args['unit'] or args[1] local datatype = args['datatype'] or args[2] local output = args['output'] or args[3] or nil local result = get[datatype](unit) 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.getUnitAbility(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local get = require ('Module:UnitData/getter') local unit = args['unit'] or args[1] local ability = "abilities" local str = "" local result = get[ability](unit) for k, v in ipairs(result) do if tonumber(args['index']) == k then str = mw.ustring.format('%s/%s/%s/%s', v[1], v[2], v[3], v[4]) end end return str end function p.getUnitSource(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local get = require ('Module:UnitData/getter') local recipe_data = require ('Module:RecipeData/data') local loot_data = require ('Module:ItemData/loot') local boss_data = require ('Module:BossData/data') local item_data = require ('Module:ItemData/data') local unit = args['unit'] or args[1] local source = "source" local str = mw.ustring.format('<h2>Способ получения</h2>') local i = 0 local result = get[source](unit) local data = recipe_data[unit] if (result == "Крафт") then str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">') if data ~= nil then for k, v in ipairs(data) do i = i + 1 str = str .. mw.ustring.format('{{RecipeImage|%s|%d}}', unit, k) end end if i == 0 then str = str .. "Нет данных" end str = str .. mw.ustring.format('</div></div>') elseif (result == "Сундук") then str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') for k, v in ipairs(loot_data) do for k1, v1 in ipairs(v) do if (v[k1][1] == unit) then for k2, v2 in pairs(item_data) do for k3, v3 in pairs(item_data[k2]["loot"]) do if (v3[1] == k) then str = str .. mw.ustring.format('%s', libItem.getItemIcon(k2, "100px")) end end end end end end str = str .. mw.ustring.format('</div>') elseif (result == "Босс") then str = str .. mw.ustring.format('<div class="bosses" style="width:fit-content; width: -moz-fit-content">') for k, v in pairs(boss_data) do for k2, v2 in pairs(boss_data[k]["loot"]) do if (v2[1] == unit) then str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) end end end str = str .. mw.ustring.format('</div>') elseif (result == "Крафт/Сундук") then str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">') if data ~= nil then for k, v in ipairs(data) do i = i + 1 str = str .. mw.ustring.format('{{RecipeImage|%s|%d}}', unit, k) end end if i == 0 then str = str .. "Нет данных" end str = str .. mw.ustring.format('</div></div>') str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') for k, v in ipairs(loot_data) do for k1, v1 in ipairs(v) do if (v[k1][1] == item) then for k2, v2 in pairs(item_data) do for k3, v3 in pairs(item_data[k2]["loot"]) do if (v3[1] == k) then str = str .. mw.ustring.format('%s', libItem.getItemIcon(k2, "100px")) end end end end end end str = str .. mw.ustring.format('</div>') elseif (result == "Крафт/Босс") then str = str .. mw.ustring.format('<div class="recipes">') for k, v in ipairs(data) do str = str .. mw.ustring.format('{{rp|%s|%d}}', unit, k) end str = str .. mw.ustring.format('</div>') str = str .. mw.ustring.format('<div class="bosses" style="width:fit-content; width: -moz-fit-content">') for k, v in pairs(boss_data) do for k2, v2 in pairs(boss_data[k]["loot"]) do if (v2[1] == item) then str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) end end end str = str .. mw.ustring.format('</div>') elseif (result == "Сундук/Босс") then str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">') for k, v in ipairs(loot_data) do for k1, v1 in ipairs(v) do if (v[k1][1] == unit) then for k2, v2 in pairs(item_data) do for k3, v3 in pairs(item_data[k2]["loot"]) do if (v3[1] == k) then str = str .. mw.ustring.format('%s', libItem.getItemIcon(k2, "100px")) end end end end end end str = str .. mw.ustring.format('</div>') str = str .. mw.ustring.format('<div class="bosses" style="width:fit-content; width: -moz-fit-content">') for k, v in pairs(boss_data) do for k2, v2 in pairs(boss_data[k]["loot"]) do if (v2[1] == unit) then str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k) end end end str = str .. mw.ustring.format('</div>') elseif (result == "Магазин") then str = str .. mw.ustring.format('<div class="shop" style="width:fit-content; width: -moz-fit-content">') str = str .. mw.ustring.format('[[Файл:icon_shop.png|x100px|ссылка=Магазин]]', "Магазин") str = str .. mw.ustring.format('</div>') end return frame:preprocess(tostring(str)) end function p.getIconUnit(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local unit_data = require ('Module:UnitData/data') local rarity_data = require ('Module:ItemData/rarities') local rarity, icon, size, count = "" if args['size'] == nil then size = "30px" else size = args['size'] end if args['count'] == nil then count = "" else count = args['count'] end if args['link'] == nil then link = "" else link = args['link'] end if args['caption'] == nil then caption = "" else caption = args['caption'] end if lib.lookup(unit_data, args['unit']) then icon = unit_data[args['unit']]["icon"] else return args['unit'] end if rarity_data[unit_data[args['unit']]["rarity"]] and rarity_data[unit_data[args['unit']]["rarity"]] ~= nil then rarity = rarity_data[unit_data[args['unit']]["rarity"]] else rarity = "обычный" end return frame:preprocess(mw.ustring.format('{{ii|%s|%s|%s|size=%s|count=%s|link=%s|caption=%s}}', args['unit'], icon, rarity, size, count, link, caption)) end function p.getAllianceIcon(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local icons_data = require ('Module:IconData/alliances') local alliance = args['alliance'] or args[1] local size = args['size'] or args[2] local icon = "" local str = "" if icons_data[alliance] ~= nil then icon = icons_data[alliance] else return "-" end str = mw.ustring.format('[[Файл:%s|%s|link=:Категория:%s (альянс)]]', icon, size, alliance) return frame:preprocess(tostring(str)) end function p.getUnitIcon(unit, size, count, link) local unit_data = require ('Module:UnitData/data') local rarity_data = require ('Module:ItemData/rarities') local rarity, icon = "" if size == nil then size = "30px" end if count == nil then count = "" end if link == nil then link = "" end if lib.lookup(unit_data, unit) then icon = unit_data[unit]["icon"] else return unit end if rarity_data[unit_data[unit]["rarity"]] and rarity_data[unit_data[unit]["rarity"]] ~= nil then rarity = rarity_data[unit_data[unit]["rarity"]] else rarity = "обычный" end return mw.ustring.format('{{ui|%s|%s|%s|size=%s|count=%s|link=%s}}', unit, icon, rarity, size, count, link) end return p