|
|
| (не показано 426 промежуточных версий этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
| | local getArgs = require('Module:Arguments').getArgs |
|
| |
|
| -- Функция для загрузки данных исследований из JSON-файла
| | function p.main(frame) |
| local function loadResearchData()
| | local args = getArgs(frame, { removeBlanks = false }) |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research_prototypes.json"):getContent())
| | local name = args[1] or "" |
| end
| | local attributes = args[2] or "" |
| | | if name == "" then |
| -- Функция для поиска исследований по дисциплине
| | return "<span class=\"error\">Ошибка: не указано имя файла.</span>" |
| local function findResearchByDiscipline(dataCache, discipline) | | end |
| local results = {}
| | local ext = (args["ext"] or "png"):gsub("^%.", "") |
| for _, research in ipairs(dataCache) do
| | local namespace = args["namespace"] or "Файл" |
| if research.technology and research.technology.discipline == discipline then
| | local max = tonumber(args["max"]) or 50 |
| table.insert(results, research.technology)
| | local include_base = (args["base"] ~= "no") |
| end
| |
| end
| |
| return results
| |
| end | |
| | |
| -- Таблица для перевода названий дисциплин
| |
| local disciplineMapping = { | |
| Arsenal = "Арсенал",
| |
| Industrial = "Промышленность",
| |
| Experimental = "Экспериментальное",
| |
| CivilianServices = "Обслуживание персонала"
| |
| }
| |
|
| |
|
| -- Таблица для цветов по уровню
| | local found = {} |
| local tierColors = { | |
| [1] = "#54d554",
| |
| [2] = "#ed9000",
| |
| [3] = "#d72a2a"
| |
| } | |
|
| |
|
| function p.main(frame)
| | if include_base then |
| -- Подключение CSS
| | local t = mw.title.new("Файл:" .. name .. "." .. ext) |
| local cssLink = frame:extensionTag('templatestyles', '', {
| | if t and t.exists then |
| src = 'Шаблон:Research/styles.css'
| | table.insert(found, "") |
| })
| | end |
| | end |
|
| |
|
| local dataCache = loadResearchData()
| | for i = 1, max do |
| local discipline = frame.args[1] or ""
| | local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext) |
| | if t and t.exists then |
| | table.insert(found, "-" .. i) |
| | end |
| | end |
|
| |
|
| if discipline then
| | if #found == 0 then |
| -- Если это дисциплина, выводим все исследования данной группы
| | return "" |
| local researches = findResearchByDiscipline(dataCache, discipline)
| | end |
| local out = cssLink .. '<div class="research-group">'
| |
|
| |
|
| for _, tech in ipairs(researches) do
| | local before = "[[" .. namespace .. ":" .. name |
| local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование"
| | local after = "." .. ext .. "|" .. attributes .. "]]" |
| local tierColor = tierColors[tech.tier] or "#FFFFFF"
| |
| local iconPath = tech.icon.sprite
| |
|
| |
|
| out = out .. '<div class="research" id="' .. tech.discipline .. '">'
| | local parts = {} |
| out = out .. '<div class="research__images">{{#invoke:Entity Sprite|main|path|' .. iconPath .. '}}</div>'
| | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") |
| out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>'
| | for _, suf in ipairs(found) do |
| out = out .. '<div class="research__type">'
| | table.insert(parts, "<option>" .. suf .. "</option>") |
| out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>'
| | end |
| out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
| | table.insert(parts, "</choose>") |
| out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
| |
| out = out .. '</div>'
| |
| out = out .. '</div>'
| |
| end
| |
|
| |
|
| out = out .. '</div>'
| | return frame:preprocess(table.concat(parts, "\n")) |
| return out
| |
| else
| |
| return cssLink .. '<div style="color:red;">Дисциплина "' .. discipline .. '" не найдена.</div>'
| |
| end
| |
| end | | end |
|
| |
|
| return p | | return p |