|
|
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
|
| |
|
| -- Функция для загрузки данных плат из JSON-файла | | -- Функция для загрузки данных исследований из JSON-файла |
| local function loadData() | | local function loadResearchData() |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent()) | | return mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/Песочница.json"):getContent()) |
| end | | end |
|
| |
|
| -- Функция для поиска данных по ID | | -- Функция для поиска исследований по дисциплине |
| local function findDataById(dataCache, id) | | local function findResearchByDiscipline(dataCache, discipline) |
| for _, item in ipairs(dataCache) do | | local results = {} |
| if item.id == id then | | for _, research in ipairs(dataCache) do |
| return item | | if research.discipline == discipline then |
| | table.insert(results, research) |
| end | | end |
| end | | end |
| return nil | | return results |
| end | | end |
|
| |
|
| -- Функция для точного округления до ближайшего целого числа | | -- Функция для поиска исследования по ID |
| local function round(num) | | local function findResearchById(dataCache, id) |
| return math.floor(num + 0.5) | | for _, research in ipairs(dataCache) do |
| | if research.id == id then |
| | return research |
| | end |
| | end |
| | return nil |
| end | | end |
|
| |
|
| -- Функция для преобразования значения в проценты | | -- Таблица для перевода названий дисциплин |
| local function formatPercentage(value) | | local disciplineMapping = { |
| return value and round((1 - value) * 100) .. "%" or "-" | | Arsenal = "Арсенал", |
| end
| | Industrial = "Промышленность", |
| | Experimental = "Экспериментальное", |
| | CivilianServices = "Обслуживание персонала" |
| | } |
|
| |
|
| -- Функция для создания строк для таблицы по типу защиты | | -- Таблица для цветов по уровню |
| local function createProtectionRow(class, color, value) | | local tierColors = { |
| return '|class="' .. class .. '" style="font-weight:bold;color: ' .. color .. ';"|' .. value .. '\n' | | [1] = "#54d554", |
| end
| | [2] = "#ed9000", |
| | [3] = "#d72a2a" |
| | } |
|
| |
|
| function p.main(frame) | | function p.main(frame) |
| local dataCache = loadData() | | -- Подключение CSS |
| local id = frame.args.id or "" -- ID предмета
| | local cssLink = frame:extensionTag('templatestyles', '', { |
| local itemData = findDataById(dataCache, id) | | src = 'Шаблон:Research/styles.css' |
| | }) |
|
| |
|
| -- Получаем защитные значения из coefficients, если они присутствуют
| | local dataCache = loadResearchData() |
| local coefficients = itemData and itemData.coefficients
| | local idOrDiscipline = frame.args.id or "" |
| 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 and itemData.ExplosionResistance.damageCoefficient) | |
|
| |
|
| -- Получаем значения sprintModifier, walkModifier, fireProtection | | if disciplineMapping[idOrDiscipline] then |
| local sprintModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.walkModifier
| | -- Если это дисциплина, выводим все исследования данной группы |
| local walkModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.walkModifier
| | local researches = findResearchByDiscipline(dataCache, idOrDiscipline) |
| local fireProtection = itemData and itemData.FireProtection and itemData.FireProtection.reduction
| | local out = cssLink .. '<div class="research-group">' |
| local speedDescription = ""
| |
|
| |
|
| -- Формируем сообщение в зависимости от значений sprintModifier и walkModifier
| | for _, tech in ipairs(researches) do |
| if sprintModifier and walkModifier then
| | local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование" |
| local sprintPercent = round((1 - sprintModifier) * 100)
| | local tierColor = tierColors[tech.tier] or "#FFFFFF" |
| local walkPercent = round((1 - walkModifier) * 100)
| | local iconPath = tech.icon.sprite |
|
| |
|
| speedDescription = "* Понижает скорость " .. (sprintModifier == walkModifier and "передвижения" or "бега и ходьбы") ..
| | out = out .. '<div class="research" id="' .. tech.discipline .. '">' |
| " на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| | out = out .. '<div class="research__images">{{#invoke:Entity Sprite|main|path=' .. iconPath .. '}}</div>' |
| if sprintModifier ~= walkModifier then
| | out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>' |
| speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n" | | out = out .. '<div class="research__type">' |
| | out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>' |
| | out = out .. '<div class="research__technology">' .. disciplineName .. '</div>' |
| | out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>' |
| | out = out .. '</div>' |
| | out = out .. '</div>' |
| end | | end |
| end
| |
|
| |
|
| -- Формируем сообщение для огневой защиты, если значение присутствует
| | out = out .. '</div>' |
| local fireProtectionDescription = fireProtection and
| | return out |
| "* Имеет огневую защиту в <span style=\"color:OrangeRed\">'''" .. round((1 - fireProtection) * 100) .. " %'''</span>\n" or "" | | else |
| | | -- Если это ID, выводим одно исследование |
| -- Описание и местоположение | | local tech = findResearchById(dataCache, idOrDiscipline) |
| local description = (frame.args.description or "") .. '\n' .. speedDescription .. fireProtectionDescription -- Описание
| | if not tech then |
| local location = frame.args.location or "" -- Местонахождение
| | return cssLink .. '<div style="color:red;">Исследование с ID или дисциплиной "' .. idOrDiscipline .. '" не найдено.</div>' |
| local created = frame.args.created or "" -- Создание
| | end |
| | |
| 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 .. '.png|' .. id .. '|Мета=64x64px,link=}}')
| |
| 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'
| |
|
| |
|
| | local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование" |
| | local tierColor = tierColors[tech.tier] or "#FFFFFF" |
| | local iconPath = tech.icon.sprite |
|
| |
|
| -- Проверка класса на "spacesuit-helmet"
| | -- Блок данных |
| if class == "spacesuit-helmet" then
| | local out = cssLink .. '<div class="research" id="' .. tech.discipline .. '">' |
| out = out .. frame:preprocess("{{FrameText|color = #bcceff|border-color = #4c4c61|content = Находится в скафандре}}") | | out = out .. '<div class="research__images">{{#invoke:Entity Sprite|main|path=' .. iconPath .. '}}</div>' |
| -- Местоположение
| | out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>' |
| elseif location ~= "" then
| | out = out .. '<div class="research__type">' |
| out = out .. frame:preprocess('{{SlideMenu|overlay|color=#e1f6ff|title=Список [[File:Examine.svg.192dpi.png|24x24px]]|content=<p></p>\n' .. location .. '}}\n') | | out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>' |
| end
| | out = out .. '<div class="research__technology">' .. disciplineName .. '</div>' |
| | out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>' |
| | out = out .. '</div>' |
| | out = out .. '</div>' |
|
| |
|
| -- Создаётся
| | return out |
| 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 | | end |
|
| |
| out = out .. '|-\n'
| |
|
| |
| return out
| |
| end | | end |
|
| |
|
| return p | | return p |