Модуль:ArmorStats: различия между версиями

Материал из Space Station 14 Вики
(ПРОВЕРКА)
мНет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


-- Функция для получения имени предмета
function p.getname(frame, entid)
function p.getname(frame, entid)
     local id = frame.args[1] or entid
     local id = frame.args[1] or entid
Строка 9: Строка 10:
end
end


-- Функция для получения описания предмета
function p.getdesc(frame, entid)
function p.getdesc(frame, entid)
     local id = frame.args[1] or entid
     local id = frame.args[1] or entid
Строка 17: Строка 19:
end
end


-- Функция для создания текстовой подсказки
function p.createtexttooltip(frame)
function p.createtexttooltip(frame)
     local id = frame.args[2]
     local id = frame.args[2]
     local entity = p.getname(frame)
     local entity = p.getname(frame, id)
     local desc = p.getdesc(frame)
     local desc = p.getdesc(frame, id)
     local stats = mw.getCurrentFrame():callParserFunction("Особое", id)
     local stats = mw.getCurrentFrame():callParserFunction("Особое", id)
     local img = frame.args["img"] or "Mousegif.gif"
     local img = frame.args["img"] or "Mousegif.gif"
Строка 32: Строка 35:
end
end


-- Функция для создания изображённой подсказки
function p.createimagetooltip(frame)
function p.createimagetooltip(frame)
     local id = frame.args[2]
     local id = frame.args[2]
     local entity = p.getname(frame)
     local entity = p.getname(frame, id)
     local desc = p.getdesc(frame)
     local desc = p.getdesc(frame, id)
     local stats = mw.getCurrentFrame():callParserFunction("Особое", id)
     local stats = mw.getCurrentFrame():callParserFunction("Особое", id)
     local img = frame.args[1] or "Mousegif.gif"
     local img = frame.args[1] or "Mousegif.gif"
Строка 47: Строка 51:
end
end


-- Функция для генерации ячеек таблицы
function p.templateCells(frame)
function p.templateCells(frame)
     local color = frame.args.color or ""  -- Цвет фона
     local color = frame.args.color or ""  -- Цвет фона

Версия от 11:57, 6 июля 2024

Для документации этого модуля может быть создана страница Модуль:ArmorStats/doc

local p = {}

-- Функция для получения имени предмета
function p.getname(frame, entid)
    local id = frame.args[1] or entid
    if not id then
        return "Не найдено"
    end
    return mw.getCurrentFrame():callParserFunction("#invoke", {"Entity Lookup", "getname", id})
end

-- Функция для получения описания предмета
function p.getdesc(frame, entid)
    local id = frame.args[1] or entid
    if not id then
        return "Не найдено"
    end
    return mw.getCurrentFrame():callParserFunction("#invoke", {"Entity Lookup", "getdesc", id})
end

-- Функция для создания текстовой подсказки
function p.createtexttooltip(frame)
    local id = frame.args[2]
    local entity = p.getname(frame, id)
    local desc = p.getdesc(frame, id)
    local stats = mw.getCurrentFrame():callParserFunction("Особое", id)
    local img = frame.args["img"] or "Mousegif.gif"

    if entity and entity ~= "Не найдено" then
        local tooltipText = "{{Tooltip|" .. frame.args[1] .. "|" .. entity .. "|" .. string.gsub(desc, "\n", "<br>") .. "|" .. stats .. "|img=" .. img .. "}}"
        return mw.getCurrentFrame():preprocess(tooltipText)
    else
        return mw.getCurrentFrame():preprocess("{{Tooltip|" .. frame.args[1] .. "|Не найден|Предмет не найден|img=Mousegif.gif}}")
    end
end

-- Функция для создания изображённой подсказки
function p.createimagetooltip(frame)
    local id = frame.args[2]
    local entity = p.getname(frame, id)
    local desc = p.getdesc(frame, id)
    local stats = mw.getCurrentFrame():callParserFunction("Особое", id)
    local img = frame.args[1] or "Mousegif.gif"

    if entity and entity ~= "Не найдено" then
        local tooltipText = "{{Tooltip|[[Файл:" .. img .. "|64x64px|link=]]|" .. entity .. "|" .. desc .. "|" .. stats .. "|img=" .. img .. "}}"
        return mw.getCurrentFrame():preprocess(tooltipText)
    else
        return mw.getCurrentFrame():preprocess("{{Tooltip|[[Файл:Mousegif.gif|64x64px|left|middle|link=]]|" .. entity .. "|" .. desc .. "|" .. stats .. "}}")
    end
end

-- Функция для генерации ячеек таблицы
function p.templateCells(frame)
    local color = frame.args.color or ""  -- Цвет фона
    local anchorName = frame.args.anchorName or ""  -- Название якоря
    local image = frame.args.image or ""  -- Путь к изображению предмета
    local itemId = frame.args.itemId or ""  -- ID предмета
    
    local protection1 = frame.args.protection1 or "-" -- Ударный
    local protection2 = frame.args.protection2 or "-" -- Режущий
    local protection3 = frame.args.protection3 or "-" -- Колющий
    local protection4 = frame.args.protection4 or "-" -- Высокотемпературный
    local protection5 = frame.args.protection5 or "-" -- Кислотный
    local protection6 = frame.args.protection6 or "-" -- Радиационный
    local protection7 = frame.args.protection7 or "-" -- Взрывной
    
    local description = frame.args.description or "" -- Описание
    local location = frame.args.location or "" -- Местонахождения 

    local out = ""

    -- Формирование строк для ячеек таблицы
    out = out .. '!style="background-color: ' .. color .. ';"|{{Anchor|' .. anchorName .. '}}{{#invoke:Entity Lookup|createimagetooltip|File:' .. image .. '|' .. itemId .. '|Мета=64x64px}}<br>{{#invoke:Entity Lookup|getname|' .. itemId .. '}} \n'
    out = out .. '|style="font-weight:500;color: crimson"|' .. protection1 .. ' \n'
    out = out .. '|style="font-weight:500;color: indianred"|' .. protection2 .. ' \n'
    out = out .. '|style="font-weight:500;color: darksalmon"|' .. protection3 .. ' \n'
    out = out .. '|style="font-weight:500;color: orange"|' .. protection4 .. ' \n'
    out = out .. '|style="font-weight:500;color: plum"|' .. protection5 .. ' \n'
    out = out .. '|style="font-weight:500;color: limegreen"|' .. protection6 .. ' \n'
    out = out .. '|style="font-weight:500;color: tan"|' .. protection7 .. ' \n'
    out = out .. '|\n' .. description .. '\n\n|\n' .. location .. '\n|-\n'

    return out
end

return p