|
|
| (не показано 450 промежуточных версий этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
| | local getArgs = require('Module:Arguments').getArgs |
|
| |
|
| -- Функция для загрузки данных плат из JSON-файла
| | function p.main(frame) |
| local function loadData() | | local args = getArgs(frame, { removeBlanks = false }) |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent()) | | local name = args[1] or "" |
| end
| | local attributes = args[2] or "" |
| | | if name == "" then |
| -- Функция для поиска данных по ID
| | return "<span class=\"error\">Ошибка: не указано имя файла.</span>" |
| local function findDataById(dataCache, id) | |
| for _, item in ipairs(dataCache) do | |
| if item.id == id then
| |
| return item
| |
| end
| |
| end | | end |
| return nil | | local ext = (args["ext"] or "png"):gsub("^%.", "") |
| end
| | local namespace = args["namespace"] or "Файл" |
| | local max = tonumber(args["max"]) or 50 |
| | local include_base = (args["base"] ~= "no") |
|
| |
|
| function p.main(frame)
| | local found = {} |
| local dataCache = loadData() | |
| local id = frame.args.id or "" -- ID предмета
| |
| local itemData = findDataById(dataCache, id)
| |
|
| |
|
| -- Если данные для ID найдены, используем их, иначе возвращаем дефолтное значение | | if include_base then |
| local function formatPercentage(value)
| | local t = mw.title.new("Файл:" .. name .. "." .. ext) |
| return value and math.floor((1 - value) * 100) .. "%" or "-" | | if t and t.exists then |
| | table.insert(found, "") |
| | end |
| end | | end |
|
| |
| local protBlunt = formatPercentage(itemData and itemData.Blunt)
| |
| local protSlash = formatPercentage(itemData and itemData.Slash)
| |
| local protPiercing = formatPercentage(itemData and itemData.Piercing)
| |
| local protHeat = formatPercentage(itemData and itemData.Heat)
| |
| local protRadiation = formatPercentage(itemData and itemData.Radiation)
| |
| local protCaustic = formatPercentage(itemData and itemData.Caustic)
| |
| local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance)
| |
|
| |
| -- Получаем значения sprintModifier и walkModifier
| |
| local sprintModifier = itemData and itemData.sprintModifier
| |
| local walkModifier = itemData and itemData.walkModifier
| |
| local speedDescription = ""
| |
|
| |
|
| -- Формируем сообщение в зависимости от значений sprintModifier и walkModifier | | for i = 1, max do |
| if sprintModifier and walkModifier then
| | local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext) |
| local sprintPercent = math.floor((1 - sprintModifier) * 100)
| | if t and t.exists then |
| local walkPercent = math.floor((1 - walkModifier) * 100) | | table.insert(found, "-" .. i) |
|
| |
| if sprintModifier == walkModifier then
| |
| speedDescription = "* Понижает скорость передвижения на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| else
| |
| speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n" | |
| end | | end |
| end | | end |
|
| |
|
| -- Описание и местоположение | | if #found == 0 then |
| local description = speedDescription .. (frame.args.description or "")
| | return "" |
| local location = frame.args.location or "" | | end |
|
| |
|
| local anchorName = frame.args.anchorName or "" -- Название якоря | | local before = "[[" .. namespace .. ":" .. name |
| local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки | | local after = "." .. ext .. "|" .. attributes .. "]]" |
| local class = frame.args.class or "" -- Класс
| |
|
| |
|
| -- Формирование строк для ячеек таблицы
| | local parts = {} |
| local out = "" | | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") |
| out = out .. '!class="' .. class .. '" style="background-color: ' .. backgroundColor .. ';"|' .. frame:preprocess('{{Anchor|' .. anchorName .. '}}')
| | for _, suf in ipairs(found) do |
| out = out .. frame:preprocess('{{#invoke:Entity Lookup|createimagetooltip|File:' .. id .. '|' .. id .. '|Мета=64x64px}}') | | table.insert(parts, "<option>" .. suf .. "</option>") |
| out = out .. '<br>' .. frame:preprocess('{{#invoke:Entity Lookup|getname|' .. id .. '}}') .. '\n'
| | end |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: crimson;"|' .. protBlunt .. '\n'
| | table.insert(parts, "</choose>") |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: indianred;"|' .. protSlash .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: darksalmon;"|' .. protPiercing .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: orange;"|' .. protHeat .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: plum;"|' .. protCaustic .. '\n' | |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: limegreen;"|' .. protRadiation .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: tan;"|' .. protExplosion .. '\n'
| |
| out = out .. '|class="' .. class .. '" style=""|\n' .. description .. '\n' | |
| out = out .. '|class="' .. class .. '" style=""|\n' .. location .. '\n|-' | |
|
| |
|
| return out | | return frame:preprocess(table.concat(parts, "\n")) |
| end | | end |
|
| |
|
| return p | | return p |