Модуль:Песочница/Pok
Версия от 20:14, 28 октября 2024; Pok (обсуждение | вклад) (Новая страница: «local p = {} -- Функция для загрузки данных плат из JSON-файла local function loadData() return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/entity_prototypes_armor.json"):getContent()) end -- Функция для поиска данных по ID local function findDataById(dataCache, id) for _, item in ipairs(dataCache) do if item.id == id then return item end end retu...»)
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
-- Функция для загрузки данных плат из JSON-файла
local function loadData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/entity_prototypes_armor.json"):getContent())
end
-- Функция для поиска данных по ID
local function findDataById(dataCache, id)
for _, item in ipairs(dataCache) do
if item.id == id then
return item
end
end
return nil
end
function p.main(frame)
local dataCache = loadData()
local id = frame.args.id or "" -- ID предмета
local itemData = findDataById(dataCache, id)
-- Если данные для ID найдены, используем их, иначе возвращаем дефолтное значение
local protBlunt = itemData and itemData.Blunt and (itemData.Blunt * 100) .. "%" or "-"
local protSlash = itemData and itemData.Slash and (itemData.Slash * 100) .. "%" or "-"
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 backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки
local class = frame.args.class or "" -- Класс
local description = frame.args.description or "" -- Описание
local location = frame.args.location or "" -- Местонахождение
-- Формирование строк для ячеек таблицы
local out = ""
out = out .. '!class="' .. class .. '" style="background-color: ' .. backgroundColor .. ';"|' .. frame:preprocess('{{Anchor|' .. anchorName .. '}}')
out = out .. frame:preprocess('{{#invoke:Entity Lookup|createimagetooltip|File:' .. id .. '|' .. id .. '|Мета=64x64px}}')
out = out .. '<br>' .. frame:preprocess('{{#invoke:Entity Lookup|getname|' .. id .. '}}') .. '\n'
out = out .. '|class="' .. class .. '" style="font-weight:bold;color: crimson;"|' .. protBlunt .. '\n'
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
end
return p