|
|
| (не показаны 422 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
|
| |
|
| -- Функция для загрузки данных плат из JSON-файла
| | local function trim(s) |
| local function loadData() | | if not s then return s end |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent()) | | return (s:gsub('^%s*(.-)%s*$', '%1')) |
| end | | end |
|
| |
|
| -- Функция для поиска данных по ID
| | local function strip_trailing_digits(s) |
| local function findDataById(dataCache, id) | | return s:gsub('%d+$', '') |
| for _, item in ipairs(dataCache) do | |
| if item.id == id then
| |
| return item
| |
| end
| |
| end
| |
| return nil
| |
| end | | end |
|
| |
|
| -- Функция для точного округления до ближайшего целого числа
| | local function split_first_underscore(k) |
| local function round(num) | | local a, b = k:match('^([^_]+)_(.+)$') |
| return math.floor(num + 0.5) | | return a, b |
| end | | end |
|
| |
|
| -- Функция для преобразования значения в проценты
| | local function collect_labels_from_args(args) |
| local function formatPercentage(value) | | local meta = {} |
| return value and round((1 - value) * 100) .. "%" or "-" | | local seen = {} |
| | for k, v in pairs(args) do |
| | if type(k) == 'string' and k:find('_', 1, true) then |
| | local base, rem = split_first_underscore(k) |
| | if base and rem then |
| | local label = strip_trailing_digits(rem) |
| | label = trim(label) |
| | if label ~= '' then |
| | meta[base] = meta[base] or {} |
| | if not seen[base] then seen[base] = {} end |
| | if not seen[base][label] then |
| | table.insert(meta[base], label) |
| | seen[base][label] = true |
| | end |
| | end |
| | end |
| | end |
| | end |
| | return meta |
| end | | end |
|
| |
|
| function p.main(frame) | | local function render_from_args(args) |
| local dataCache = loadData() | | local field = args[1] or args.field or args["field"] |
| local id = frame.args.id or "" -- ID предмета
| | local label = args[2] or args.label or args["label"] |
| local itemData = findDataById(dataCache, id) | | field = field and trim(field) or '' |
| | | label = label and trim(label) or '' |
| local protBlunt = formatPercentage(itemData and itemData.Blunt)
| |
| 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
| |
| local sprintModifier = itemData and itemData.sprintModifier
| |
| local walkModifier = itemData and itemData.walkModifier
| |
| local speedDescription = ""
| |
|
| |
|
| -- Формируем сообщение в зависимости от значений sprintModifier и walkModifier | | -- map base -> label -> value |
| if sprintModifier and walkModifier then | | local map = {} |
| local sprintPercent = round((1 - sprintModifier) * 100)
| | for k, v in pairs(args) do |
| local walkPercent = round((1 - walkModifier) * 100)
| | if type(k) == 'string' and k:find('_', 1, true) then |
|
| | local base, rem = split_first_underscore(k) |
| if sprintModifier == walkModifier then
| | if base and rem then |
| speedDescription = "* Понижает скорость передвижения на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| | local lab = strip_trailing_digits(rem) |
| else
| | lab = trim(lab) |
| speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| | map[base] = map[base] or {} |
| speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n" | | local cur = map[base][lab] |
| | if cur then |
| | map[base][lab] = cur .. '\n' .. tostring(v) |
| | else |
| | map[base][lab] = tostring(v) |
| | end |
| | end |
| end | | end |
| end | | end |
|
| |
|
| -- Описание и местоположение | | if field ~= '' and label ~= '' then |
| local description = speedDescription .. (frame.args.description or "") -- Описание
| | local base = map[field] |
| local location = frame.args.location or "" -- Местонахождения
| | if base then return base[label] or '' end |
| local created = frame.args.created or "" -- Создаётя
| | return '' |
| | end |
|
| |
|
| local anchorName = frame.args.anchorName or "" -- Название якоря | | if args[1] and args[2] then |
| local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки
| | local f = trim(args[1]); local l = trim(args[2]) |
| local class = frame.args.class or "" -- Класс
| | local base = map[f] |
| | if base then return base[l] or '' end |
| | end |
|
| |
|
| -- Формирование строк для ячеек таблицы | | return '' |
| local out = ""
| | end |
| 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
| |
|
| |
|
| -- Создаётся
| | function p.main(frame) |
| if created ~= "" then
| | local args = frame.args or {} |
| out = out .. frame:preprocess('{{SlideMenu|overlay|color=#e1f6ff|border-color=#4c4c61|title=Создаётся [[File:hammer.svg.192dpi.png|24x24px]]|content=Создаётся в панели строительства<hr>\n' .. created .. '}}\n')
| | local has_any = false |
| elseif location == "" then
| | for k, _ in pairs(args) do |
| out = out .. frame:preprocess('{{FrameText|color=#82d1c4|content=Нет гарантированных мест спавна}}\n')
| | has_any = true; break |
| end
| | end |
|
| | if not has_any then return collect_labels_from_args(args) end |
| out = out .. '|-\n'
| |
|
| |
|
| return out | | return render_from_args(args) |
| end | | end |
|
| |
|
| return p | | return p |