|
|
| (не показаны 443 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
| | local getArgs = require('Module:Arguments').getArgs |
|
| |
|
| -- Функция для загрузки данных плат из JSON-файла
| | function p.main(frame) |
| local function loadData() | | local args = getArgs(frame, { removeBlanks = false }) |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent()) | | local name = args[1] or "" |
| end
| | local attributes = args[2] or "" |
| | | if name == "" then |
| -- Функция для поиска данных по ID
| | return "<span class=\"error\">Ошибка: не указано имя файла.</span>" |
| local function findDataById(dataCache, id) | |
| for _, item in ipairs(dataCache) do | |
| if item.id == id then
| |
| return item
| |
| end
| |
| end | | end |
| return nil | | local ext = (args["ext"] or "png"):gsub("^%.", "") |
| end
| | local namespace = args["namespace"] or "Файл" |
| | | local max = tonumber(args["max"]) or 50 |
| -- Функция для точного округления до ближайшего целого числа
| | local include_base = (args["base"] ~= "no") |
| local function round(num) | |
| return math.floor(num + 0.5)
| |
| end
| |
| | |
| -- Функция для преобразования значения в проценты
| |
| local function formatPercentage(value) | |
| return value and round((1 - value) * 100) .. "%" or "-"
| |
| end
| |
| | |
| function p.main(frame)
| |
| local dataCache = loadData() | |
| local id = frame.args.id or "" -- ID предмета | |
| local itemData = findDataById(dataCache, id)
| |
|
| |
|
| local protBlunt = formatPercentage(itemData and itemData.Blunt) | | local found = {} |
| local protSlash = formatPercentage(itemData and itemData.Slash)
| |
| local protPiercing = formatPercentage(itemData and itemData.Piercing)
| |
| local protHeat = formatPercentage(itemData and itemData.Heat)
| |
| local protRadiation = formatPercentage(itemData and itemData.Radiation)
| |
| local protCaustic = formatPercentage(itemData and itemData.Caustic)
| |
| local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance)
| |
|
| |
|
| -- Получаем значения sprintModifier, walkModifier, fireProtection, и temperatureProtection
| | if include_base then |
| local sprintModifier = itemData and itemData.sprintModifier
| | local t = mw.title.new("Файл:" .. name .. "." .. ext) |
| local walkModifier = itemData and itemData.walkModifier
| | if t and t.exists then |
| local fireProtection = itemData and itemData.FireProtection
| | table.insert(found, "") |
| 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)
| |
|
| |
| if sprintModifier == walkModifier then
| |
| speedDescription = "* Понижает скорость передвижения на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| else | |
| speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n" | |
| end | | end |
| end | | end |
|
| |
|
| -- Формируем сообщение для огневой защиты, если значение присутствует | | for i = 1, max do |
| local fireProtectionDescription = ""
| | local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext) |
| if fireProtection then
| | if t and t.exists then |
| local fireProtectionPercent = round((1 - fireProtection) * 100)
| | table.insert(found, "-" .. i) |
| fireProtectionDescription = "* Имеет огневую защиту в <span style=\"color:OrangeRed\">'''" .. fireProtectionPercent .. " %'''</span>\n"
| | end |
| end | | end |
|
| |
|
| -- Формируем сообщение для сопротивления к критическим температурам, если значение присутствует | | if #found == 0 then |
| local temperatureProtectionDescription = ""
| | return "" |
| if temperatureProtection then
| |
| temperatureProtectionDescription = "* Имеет значительное сопротивление к критическим температурам\n" | |
| end | | end |
|
| |
|
| -- Описание и местоположение | | local before = "[[" .. namespace .. ":" .. name |
| local description = (frame.args.description or "") .. '\n' .. speedDescription -- Описание
| | local after = "." .. ext .. "|" .. attributes .. "]]" |
| local location = frame.args.location or "" -- Местонахождение
| |
| local created = frame.args.created or "" -- Создание
| |
|
| |
|
| local anchorName = frame.args.anchorName or "" -- Название якоря | | local parts = {} |
| local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки
| | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") |
| local class = frame.args.class or "" -- Класс
| | for _, suf in ipairs(found) do |
| | | table.insert(parts, "<option>" .. suf .. "</option>") |
| -- Формирование строк для ячеек таблицы
| | end |
| local out = ""
| | table.insert(parts, "</choose>") |
| 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'
| |
| if 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 == "" then
| |
| out = out .. frame:preprocess('{{FrameText|color=#82d1c4|content=Нет гарантированных мест спавна}}\n')
| |
| end
| |
|
| |
| out = out .. '|-\n'
| |
|
| |
|
| return out | | return frame:preprocess(table.concat(parts, "\n")) |
| end | | end |
|
| |
|
| return p | | return p |
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame, { removeBlanks = false })
local name = args[1] or ""
local attributes = args[2] or ""
if name == "" then
return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
end
local ext = (args["ext"] or "png"):gsub("^%.", "")
local namespace = args["namespace"] or "Файл"
local max = tonumber(args["max"]) or 50
local include_base = (args["base"] ~= "no")
local found = {}
if include_base then
local t = mw.title.new("Файл:" .. name .. "." .. ext)
if t and t.exists then
table.insert(found, "")
end
end
for i = 1, max do
local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
if t and t.exists then
table.insert(found, "-" .. i)
end
end
if #found == 0 then
return ""
end
local before = "[[" .. namespace .. ":" .. name
local after = "." .. ext .. "|" .. attributes .. "]]"
local parts = {}
table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
for _, suf in ipairs(found) do
table.insert(parts, "<option>" .. suf .. "</option>")
end
table.insert(parts, "</choose>")
return frame:preprocess(table.concat(parts, "\n"))
end
return p