Модуль:Песочница/Pok: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 3: | Строка 3: | ||
-- Функция для загрузки данных плат из JSON-файла | -- Функция для загрузки данных плат из JSON-файла | ||
local function loadData() | local function loadData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/ | return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent()) | ||
end | end | ||
| Строка 29: | Строка 29: | ||
local protCaustic = itemData and itemData.Caustic and (itemData.Caustic * 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 protExplosion = itemData and itemData.ExplosionResistance and (itemData.ExplosionResistance * 100) .. "%" or "-" | ||
-- Получаем значения sprintModifier и walkModifier | |||
local sprintModifier = itemData and itemData.sprintModifier | |||
local walkModifier = itemData and itemData.walkModifier | |||
local speedDescription = "" | |||
-- Формируем сообщение в зависимости от значений sprintModifier и walkModifier | |||
if sprintModifier and walkModifier then | |||
if sprintModifier == walkModifier then | |||
speedDescription = "* Понижает скорость передвижения на <span style=\"color:yellow\">'''" .. (sprintModifier * 100) .. " %'''</span>\n" | |||
else | |||
speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. (sprintModifier * 100) .. " %'''</span>\n" | |||
speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. (walkModifier * 100) .. " %'''</span>\n" | |||
end | |||
end | |||
-- Описание и местоположение | |||
local description = speedDescription .. (frame.args.description or "") | |||
local location = frame.args.location or "" | |||
local anchorName = frame.args.anchorName or "" -- Название якоря | local anchorName = frame.args.anchorName or "" -- Название якоря | ||
local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки | local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки | ||
local class = frame.args.class or "" -- Класс | local class = frame.args.class or "" -- Класс | ||
-- Формирование строк для ячеек таблицы | -- Формирование строк для ячеек таблицы | ||
Версия от 20:22, 28 октября 2024
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
-- Функция для загрузки данных плат из JSON-файла
local function loadData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.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 "-"
-- Получаем значения sprintModifier и walkModifier
local sprintModifier = itemData and itemData.sprintModifier
local walkModifier = itemData and itemData.walkModifier
local speedDescription = ""
-- Формируем сообщение в зависимости от значений sprintModifier и walkModifier
if sprintModifier and walkModifier then
if sprintModifier == walkModifier then
speedDescription = "* Понижает скорость передвижения на <span style=\"color:yellow\">'''" .. (sprintModifier * 100) .. " %'''</span>\n"
else
speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. (sprintModifier * 100) .. " %'''</span>\n"
speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. (walkModifier * 100) .. " %'''</span>\n"
end
end
-- Описание и местоположение
local description = speedDescription .. (frame.args.description or "")
local location = frame.args.location or ""
local anchorName = frame.args.anchorName or "" -- Название якоря
local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки
local class = frame.args.class 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