Модуль:ArmorStats: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
Строка 41: | Строка 41: | ||
-- Вычисляем цвет рамки (чуть темнее заданного цвета) | -- Вычисляем цвет рамки (чуть темнее заданного цвета) | ||
local borderColor = darkenColor(color) | local borderColor = darkenColor(color) | ||
-- Создание HTML с помощью mw.html.create | |||
local div = mw.html.create('div') | |||
div:addClass(divClass) | |||
-- Формирование строк для ячеек таблицы | -- Формирование строк для ячеек таблицы | ||
local | local tableContent = "" | ||
tableContent = tableContent .. '!style="background-color: ' .. color .. ';border-top: 1px solid ' .. borderColor .. ';border-bottom: 1px solid ' .. borderColor .. ';border-left: 2px solid ' .. borderColor .. ';"|' .. anchor | |||
tableContent = tableContent .. imageTooltip | |||
tableContent = tableContent .. '<br>' .. itemName .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: crimson;background-color: ' .. backgroundColor .. '"|' .. protBlunt .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: indianred;background-color: ' .. backgroundColor .. '"|' .. protSlash .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: darksalmon;background-color: ' .. backgroundColor .. '"|' .. protPiercing .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: orange;background-color: ' .. backgroundColor .. '"|' .. protHeat .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: plum;background-color: ' .. backgroundColor .. '"|' .. protRadiation .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: limegreen;background-color: ' .. backgroundColor .. '"|' .. protCaustic .. '\n' | |||
tableContent = tableContent .. '|style="font-weight:bold;color: tan;background-color: ' .. backgroundColor .. '"|' .. protExplosion .. '\n' | |||
tableContent = tableContent .. '|style="background-color: ' .. backgroundColor .. '"|\n' .. description .. '\n' | |||
tableContent = tableContent .. '|style="background-color: ' .. backgroundColor .. '"|\n' .. location .. '\n|-' | |||
div:wikitext(tableContent) | |||
return | return tostring(div) | ||
end | end | ||
return p | return p |
Версия от 18:35, 8 июля 2024
Для документации этого модуля может быть создана страница Модуль:ArmorStats/doc
local p = {}
-- Функция для изменения яркости цвета (уменьшение на 20%)
local function darkenColor(color)
-- Уменьшаем каждую компоненту RGB на 20%
local r = math.floor(tonumber(color:sub(2, 3), 16) * 0.8)
local g = math.floor(tonumber(color:sub(4, 5), 16) * 0.8)
local b = math.floor(tonumber(color:sub(6, 7), 16) * 0.8)
-- Собираем новый цвет
return string.format("#%02x%02x%02x", r, g, b)
end
function p.templateCells(frame)
local anchorName = frame.args.anchorName or "" -- Название якоря
local image = frame.args.image or "" -- Путь к изображению предмета
local itemId = frame.args.itemId or "" -- ID предмета
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 "" -- Местонахождение
-- Вызов функции из модуля Entity Lookup для создания image tooltip
local imageTooltip = frame:preprocess('{{#invoke:Entity Lookup|createimagetooltip|File:' .. image .. '|' .. itemId .. '|Мета=64x64px}}')
-- Вызов функции из модуля Entity Lookup для получения имени элемента
local itemName = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. itemId .. '}}')
-- Обработка шаблона Anchor с помощью frame:preprocess
local anchor = frame:preprocess('{{Anchor|' .. anchorName .. '}}')
-- Вычисляем цвет рамки (чуть темнее заданного цвета)
local borderColor = darkenColor(color)
-- Создание HTML с помощью mw.html.create
local div = mw.html.create('div')
div:addClass(divClass)
-- Формирование строк для ячеек таблицы
local tableContent = ""
tableContent = tableContent .. '!style="background-color: ' .. color .. ';border-top: 1px solid ' .. borderColor .. ';border-bottom: 1px solid ' .. borderColor .. ';border-left: 2px solid ' .. borderColor .. ';"|' .. anchor
tableContent = tableContent .. imageTooltip
tableContent = tableContent .. '<br>' .. itemName .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: crimson;background-color: ' .. backgroundColor .. '"|' .. protBlunt .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: indianred;background-color: ' .. backgroundColor .. '"|' .. protSlash .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: darksalmon;background-color: ' .. backgroundColor .. '"|' .. protPiercing .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: orange;background-color: ' .. backgroundColor .. '"|' .. protHeat .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: plum;background-color: ' .. backgroundColor .. '"|' .. protRadiation .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: limegreen;background-color: ' .. backgroundColor .. '"|' .. protCaustic .. '\n'
tableContent = tableContent .. '|style="font-weight:bold;color: tan;background-color: ' .. backgroundColor .. '"|' .. protExplosion .. '\n'
tableContent = tableContent .. '|style="background-color: ' .. backgroundColor .. '"|\n' .. description .. '\n'
tableContent = tableContent .. '|style="background-color: ' .. backgroundColor .. '"|\n' .. location .. '\n|-'
div:wikitext(tableContent)
return tostring(div)
end
return p