|
|
| (не показаны 284 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
| | | local getArgs = require('Module:Arguments').getArgs |
| -- Функция для загрузки данных исследований из JSON-файла
| |
| local function loadResearchData() | |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent())
| |
| end
| |
| | |
| -- Таблица для перевода названий дисциплин
| |
| local disciplineMapping = {
| |
| Arsenal = "Арсенал",
| |
| Industrial = "Промышленность",
| |
| Experimental = "Экспериментальное",
| |
| CivilianServices = "Обслуживание персонала"
| |
| }
| |
| | |
| -- Таблица для цветов по уровням
| |
| local tierColors = {
| |
| [1] = "#54d554",
| |
| [2] = "#ed9000",
| |
| [3] = "#d72a2a"
| |
| }
| |
|
| |
|
| function p.main(frame) | | function p.main(frame) |
| local dataCache = loadResearchData() | | local args = getArgs(frame, { removeBlanks = false }) |
| local input = frame.args[1] or "" | | local name = args[1] or "" |
| local manualIcon = frame.args[2] or "" | | local attributes = args[2] or "" |
| local out = ""
| | if name == "" then |
| | | return "<span class=\"error\">Ошибка: не указано имя файла.</span>" |
| if input == "" then | |
| return '<div style="color:red;">Не указан идентификатор исследования или дисциплина.</div>' | |
| end | | 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 disciplineMapping[input] then
| |
| local found = false
| |
| for _, research in ipairs(dataCache) do
| |
| if research.technology and research.technology.discipline == input then
| |
| found = true
| |
| local tech = research.technology
| |
| local iconPath = "{{#invoke:Entity Sprite|main|path|" .. (tech.icon and tech.icon.sprite or "") .. "}}"
| |
| local tierColor = tierColors[tech.tier] or "#FFFFFF"
| |
| local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
| |
|
| |
|
| -- Формирование строки необходимых исследований (prerequisites)
| | if include_base then |
| local prerequisites = ""
| | local t = mw.title.new("Файл:" .. name .. "." .. ext) |
| if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
| | if t and t.exists then |
| prerequisites = '<ul>'
| | table.insert(found, "") |
| for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
| | end |
| if prerequisiteId and prerequisiteId ~= "" then
| | end |
| local prerequisiteName = ""
| |
| for _, r in ipairs(dataCache) do
| |
| if r.technology and r.technology.id == prerequisiteId then
| |
| prerequisiteName = r.technology.name
| |
| break
| |
| end
| |
| end
| |
| if prerequisiteName ~= "" then
| |
| prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|' .. prerequisiteName .. '}}</li>'
| |
| end
| |
| end
| |
| end
| |
| prerequisites = prerequisites .. '</ul>'
| |
| end
| |
| | |
| -- Формирование строки открываемых исследований (unlocks)
| |
| local unlocks = ""
| |
| if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
| |
| unlocks = '<ul>'
| |
| for _, recipe in ipairs(tech.recipeUnlocks) do
| |
| if recipe and recipe ~= "" then
| |
| unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
| |
| .. recipe .. '.png|' .. recipe
| |
| .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
| |
| .. recipe .. '}}</li>'
| |
| end
| |
| end
| |
| unlocks = unlocks .. '</ul>'
| |
| end
| |
| | |
| local templateArgs = {
| |
| id = tech.id,
| |
| icon = iconPath,
| |
| name = tech.name,
| |
| discipline = tech.discipline,
| |
| tier = tech.tier,
| |
| tierColor = tierColor,
| |
| disciplineName = disciplineName,
| |
| cost = tech.cost,
| |
| unlocks = unlocks
| |
| }
| |
| if prerequisites ~= "" then
| |
| templateArgs.prerequisites = prerequisites
| |
| end
| |
|
| |
|
| out = out .. frame:expandTemplate({
| | for i = 1, max do |
| title = 'Prototypes/Механика/Исследование',
| | local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext) |
| args = templateArgs
| | if t and t.exists then |
| })
| | table.insert(found, "-" .. i) |
| end
| |
| end | |
| if not found then
| |
| out = out .. '<div style="color:red;">Не найдено исследований для дисциплины "' .. input .. '".</div>'
| |
| end
| |
| return mw.getCurrentFrame():preprocess(out)
| |
| else
| |
| -- Режим поиска по ID исследования
| |
| local tech = nil
| |
| for _, research in ipairs(dataCache) do | |
| if research.technology and research.technology.id == input then
| |
| tech = research.technology
| |
| break
| |
| end
| |
| end | | end |
| | end |
|
| |
|
| if not tech then
| | if #found == 0 then |
| out = out .. '<div style="color:red;">Исследование с ID "' .. input .. '" не найдено.</div>'
| | return "" |
| else | | end |
| local tierColor = tierColors[tech.tier] or "#FFFFFF"
| |
| local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
| |
| -- Если иконка задана вручную, используем её, иначе берём из tech.icon.sprite
| |
| local iconPath = manualIcon ~= "" and manualIcon or (tech.icon and tech.icon.sprite or nil)
| |
|
| |
|
| local prerequisites = ""
| | local before = "[[" .. namespace .. ":" .. name |
| if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
| | local after = "." .. ext .. "|" .. attributes .. "]]" |
| prerequisites = '<ul>'
| |
| for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
| |
| if prerequisiteId and prerequisiteId ~= "" then
| |
| local prerequisiteName = ""
| |
| for _, research in ipairs(dataCache) do
| |
| if research.technology and research.technology.id == prerequisiteId then
| |
| prerequisiteName = research.technology.name
| |
| break
| |
| end
| |
| end
| |
| if prerequisiteName ~= "" then
| |
| prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|' .. prerequisiteName .. '}}</li>'
| |
| end
| |
| end
| |
| end
| |
| prerequisites = prerequisites .. '</ul>'
| |
| end
| |
|
| |
|
| local unlocks = ""
| | local parts = {} |
| if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
| | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") |
| unlocks = '<ul>'
| | for _, suf in ipairs(found) do |
| for _, recipe in ipairs(tech.recipeUnlocks) do
| | table.insert(parts, "<option>" .. suf .. "</option>") |
| if recipe and recipe ~= "" then
| | end |
| unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
| | table.insert(parts, "</choose>") |
| .. recipe .. '.png|' .. recipe
| |
| .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
| |
| .. recipe .. '}}</li>'
| |
| end
| |
| end
| |
| unlocks = unlocks .. '</ul>'
| |
| end
| |
| | |
| local templateArgs = {
| |
| id = tech.id,
| |
| icon = iconPath,
| |
| name = tech.name,
| |
| discipline = tech.discipline,
| |
| tier = tech.tier,
| |
| tierColor = tierColor,
| |
| disciplineName = disciplineName,
| |
| cost = tech.cost,
| |
| unlocks = unlocks
| |
| }
| |
| if prerequisites ~= "" then
| |
| templateArgs.prerequisites = prerequisites
| |
| end
| |
|
| |
|
| out = out .. frame:expandTemplate({
| | return frame:preprocess(table.concat(parts, "\n")) |
| title = 'Prototypes/Механика/Исследование',
| |
| args = templateArgs
| |
| })
| |
| end
| |
| return mw.getCurrentFrame():preprocess(out)
| |
| end
| |
| end | | end |
|
| |
|
| return p | | return p |