Модуль:Песочница/Pok: различия между версиями

мНет описания правки
Нет описания правки
 
(не показаны 452 промежуточные версии этого же участника)
Строка 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
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    end
    local ext = (args["ext"] or "png"):gsub("^%.", "")  
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")
 
    local found = {}


-- Функция для поиска данных по ID
    if include_base then
local function findDataById(dataCache, id)
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    for _, item in ipairs(dataCache) do
         if t and t.exists then
         if item.id == id then
             table.insert(found, "")
             return item
         end
         end
     end
     end
    return nil
end


function p.main(frame)
     for i = 1, max do
     local dataCache = loadData()
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
    local id = frame.args.id or "" -- ID предмета
        if t and t.exists then
    local itemData = findDataById(dataCache, id)
            table.insert(found, "-" .. i)
        end
    end


     -- Если данные для ID найдены, используем их, иначе возвращаем дефолтное значение
     if #found == 0 then
    local protBlunt = itemData and itemData.Blunt and (itemData.Blunt * 100) .. "%" or "-"
        return ""
    local protSlash = itemData and itemData.Slash and (itemData.Slash * 100) .. "%" or "-"
     end
    local protPiercing = itemData and itemData.Piercing and (itemData.Piercing * 100) .. "%" or "-"
    local protHeat = itemData and itemData.Heat and (itemData.Heat * 100) .. "%" or "-"
    local protRadiation = itemData and itemData.Radiation and (itemData.Radiation * 100) .. "%" or "-"
    local protCaustic = itemData and itemData.Caustic and (itemData.Caustic * 100) .. "%" or "-"
     local protExplosion = itemData and itemData.ExplosionResistance and (itemData.ExplosionResistance * 100) .. "%" or "-"


     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 description = frame.args.description or "" -- Описание
    local location = frame.args.location 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