|
|
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
|
| |
|
| -- Функция для загрузки данных плат из JSON-файла | | function p.templateCells(frame) |
| local function loadData() | | local anchorName = frame.args.anchorName or "" -- Название якоря |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent())
| | local itemId = frame.args.itemId or "" -- ID предмета |
| end
| | local image = frame.args.image or "" -- Путь к изображению предмета |
| | local color = frame.args.color or "" -- Цвет фона первой ячейки |
| | local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона для всех ячеек, кроме первой |
| | local class = frame.args.class or "" -- Класс |
| | |
| | local protBlunt = frame.args.protBlunt or "-" -- Ударный |
| | local protSlash = frame.args.protSlash or "-" -- Режущий |
| | local protPiercing = frame.args.protPiercing or "-" -- Колющий |
| | local protHeat = frame.args.protHeat or "-" -- Высокотемпературный |
| | local protRadiation = frame.args.protRadiation or "-" -- Кислотный |
| | local protCaustic = frame.args.protCaustic or "-" -- Радиационный |
| | local protExplosion = frame.args.protExplosion or "-" -- Взрывной |
| | |
| | local description = frame.args.description or "" -- Описание |
| | local location = frame.args.location or "" -- Местонахождение |
|
| |
|
| -- Функция для поиска данных по ID | | -- Формирование строк для ячеек таблицы |
| local function findDataById(dataCache, id) | | local out = "" |
| for _, item in ipairs(dataCache) do
| | out = out .. '!class="' .. class .. '" style="background-color: ' .. color .. ';"|' .. frame:preprocess('{{Anchor|' .. anchorName .. '}}') |
| if item.id == id then
| | out = out .. frame:preprocess('{{#invoke:Entity Lookup|createimagetooltip|File:' .. image .. '|' .. itemId .. '|Мета=64x64px}}') |
| return item
| | out = out .. '<br>' .. frame:preprocess('{{#invoke:Entity Lookup|getname|' .. itemId .. '}}') .. '\n' |
| end
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: crimson;background-color: ' .. backgroundColor .. '"|' .. protBlunt .. '\n' |
| end
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: indianred;background-color: ' .. backgroundColor .. '"|' .. protSlash .. '\n' |
| return nil
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: darksalmon;background-color: ' .. backgroundColor .. '"|' .. protPiercing .. '\n' |
| end
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: orange;background-color: ' .. backgroundColor .. '"|' .. protHeat .. '\n' |
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: plum;background-color: ' .. backgroundColor .. '"|' .. protCaustic .. '\n' |
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: limegreen;background-color: ' .. backgroundColor .. '"|' .. protRadiation .. '\n' |
| | out = out .. '|class="' .. class .. '" style="font-weight:bold;color: tan;background-color: ' .. backgroundColor .. '"|' .. protExplosion .. '\n' |
| | out = out .. '|class="' .. class .. '" style="background-color: ' .. backgroundColor .. '"|\n' .. description .. '\n' |
| | out = out .. '|class="' .. class .. '" style="background-color: ' .. backgroundColor .. '"|\n' .. location .. '\n|-' |
|
| |
|
| -- Функция для точного округления до ближайшего целого числа
| | return out |
| local function round(num)
| |
| return math.floor(num + 0.5)
| |
| end
| |
| | |
| -- Функция для преобразования значения в проценты
| |
| local function formatPercentage(value)
| |
| return value and round((1 - value) * 100) .. "%" or "-"
| |
| end
| |
| | |
| -- Функция для создания строк для таблицы по типу защиты
| |
| local function createProtectionRow(class, color, value)
| |
| return '|class="' .. class .. '" style="font-weight:bold;color: ' .. color .. ';"|' .. value .. '\n'
| |
| end
| |
| | |
| function p.main(frame)
| |
| local dataCache = loadData()
| |
| local id = frame.args.id or "" -- ID предмета
| |
| local itemData = findDataById(dataCache, id)
| |
| | |
| -- Получаем защитные значения из coefficients, если они присутствуют
| |
| local coefficients = itemData and itemData.coefficients
| |
| local protBlunt = formatPercentage(coefficients and coefficients.Blunt)
| |
| local protSlash = formatPercentage(coefficients and coefficients.Slash)
| |
| local protPiercing = formatPercentage(coefficients and coefficients.Piercing)
| |
| local protHeat = formatPercentage(coefficients and coefficients.Heat)
| |
| local protRadiation = formatPercentage(coefficients and coefficients.Radiation)
| |
| local protCaustic = formatPercentage(coefficients and coefficients.Caustic)
| |
| local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance)
| |
| | |
| -- Получаем значения sprintModifier, walkModifier, fireProtection, и temperatureProtection
| |
| local sprintModifier = itemData and itemData.sprintModifier
| |
| local walkModifier = itemData and itemData.walkModifier
| |
| local fireProtection = itemData and itemData.FireProtection
| |
| local temperatureProtection = itemData and itemData.TemperatureProtection
| |
| local speedDescription = ""
| |
| | |
| -- Формируем сообщение в зависимости от значений sprintModifier и walkModifier
| |
| if sprintModifier and walkModifier then
| |
| local sprintPercent = round((1 - sprintModifier) * 100)
| |
| local walkPercent = round((1 - walkModifier) * 100)
| |
| | |
| speedDescription = "* Понижает скорость " .. (sprintModifier == walkModifier and "передвижения" or "бега и ходьбы") ..
| |
| " на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| if sprintModifier ~= walkModifier then
| |
| speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n"
| |
| end
| |
| end
| |
| | |
| -- Формируем сообщение для огневой защиты, если значение присутствует
| |
| local fireProtectionDescription = fireProtection and
| |
| "* Имеет огневую защиту в <span style=\"color:OrangeRed\">'''" .. round((1 - fireProtection) * 100) .. " %'''</span>\n" or ""
| |
| | |
| -- Формируем сообщение для сопротивления к критическим температурам, если значение присутствует
| |
| local temperatureProtectionDescription = temperatureProtection and
| |
| "* Имеет значительное сопротивление к критическим температурам\n" or ""
| |
| | |
| -- Описание и местоположение
| |
| local description = (frame.args.description or "") .. '\n' .. speedDescription .. fireProtectionDescription .. temperatureProtectionDescription -- Описание
| |
| local location = frame.args.location or "" -- Местонахождение
| |
| local created = frame.args.created 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 .. createProtectionRow(class, "crimson", protBlunt)
| |
| out = out .. createProtectionRow(class, "indianred", protSlash)
| |
| out = out .. createProtectionRow(class, "darksalmon", protPiercing)
| |
| out = out .. createProtectionRow(class, "orange", protHeat)
| |
| out = out .. createProtectionRow(class, "plum", protCaustic)
| |
| out = out .. createProtectionRow(class, "limegreen", protRadiation)
| |
| out = out .. createProtectionRow(class, "tan", protExplosion)
| |
| | |
| out = out .. '|class="' .. class .. '" style=""|\n' .. description .. '\n'
| |
| out = out .. '|class="' .. class .. '" style=""|\n'
| |
| | |
| | |
| -- Проверка класса на "spacesuit-helmet"
| |
| if class == "spacesuit-helmet" then
| |
| out = out .. frame:preprocess("{{FrameText|color = #bcceff|border-color = #4c4c61|content = Находится в скафандре}}")
| |
| -- Местоположение
| |
| elseif location ~= "" then
| |
| out = out .. frame:preprocess('{{SlideMenu|overlay|color=#e1f6ff|title=Список [[File:Examine.svg.192dpi.png|24x24px]]|content=<p></p>\n' .. location .. '}}\n')
| |
| end
| |
| | |
| -- Создаётся
| |
| if created ~= "" then
| |
| out = out .. frame:preprocess('{{SlideMenu|overlay|color=#e1f6ff|border-color=#4c4c61|title=Создаётся [[File:hammer.svg.192dpi.png|24x24px]]|content=Создаётся в панели строительства<hr>\n' .. created .. '}}\n')
| |
| elseif location == "" and class ~= "spacesuit-helmet" then
| |
| out = out .. frame:preprocess('{{FrameText|color=#82d1c4|content=Нет гарантированных мест спавна}}\n')
| |
| end
| |
| | |
| out = out .. '|-\n'
| |
| | |
| return out
| |
| end | | end |
|
| |
|
| return p | | return p |