|
|
| (не показано 395 промежуточных версий этого же участника) |
| Строка 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/Песочница.json"):getContent()) | | local name = args[1] or "" |
| end
| | 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 function findResearchByDiscipline(dataCache, discipline) | | local t = mw.title.new("Файл:" .. name .. "." .. ext) |
| local results = {}
| | if t and t.exists then |
| for _, research in ipairs(dataCache) do
| | table.insert(found, "") |
| if research.technology and research.technology.discipline == discipline then | |
| table.insert(results, research.technology) | |
| end | | end |
| end | | end |
| return results
| |
| end
| |
|
| |
| -- Таблица для перевода названий дисциплин
| |
| local disciplineMapping = {
| |
| Arsenal = "Арсенал",
| |
| Industrial = "Промышленность",
| |
| Experimental = "Экспериментальное",
| |
| CivilianServices = "Обслуживание персонала"
| |
| }
| |
|
| |
| -- Таблица для цветов по уровням
| |
| local tierColors = {
| |
| [1] = "#54d554",
| |
| [2] = "#ed9000",
| |
| [3] = "#d72a2a"
| |
| }
| |
|
| |
| function p.main(frame)
| |
| -- Подключение CSS
| |
| local cssLink = frame:extensionTag('templatestyles', '', {
| |
| src = 'Шаблон:Research/styles.css'
| |
| })
| |
|
| |
| local dataCache = loadResearchData()
| |
| local discipline = frame.args[1] or ""
| |
|
| |
| if discipline and discipline ~= "" then
| |
| -- Инициализация строки вывода
| |
| local out = cssLink .. '<div class="research-group">'
| |
|
| |
| -- Получаем список исследований по дисциплине
| |
| local researches = findResearchByDiscipline(dataCache, discipline)
| |
|
| |
|
| if #researches == 0 then
| | for i = 1, max do |
| out = out .. '<div style="color:red;">Нет исследований для дисциплины "' .. discipline .. '"</div>'
| | local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext) |
| | if t and t.exists then |
| | table.insert(found, "-" .. i) |
| end | | end |
| | end |
|
| |
|
| for _, tech in ipairs(researches) do
| | if #found == 0 then |
| local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
| | return "" |
| local tierColor = tierColors[tech.tier] or "#FFFFFF"
| | end |
| local iconPath = tech.icon and tech.icon.sprite or nil
| |
|
| |
|
| -- Формирование строки prerequisites
| | local before = "[[" .. namespace .. ":" .. name |
| local prerequisitesStr = ""
| | local after = "." .. ext .. "|" .. attributes .. "]]" |
| if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
| |
| prerequisitesStr = '<ul>'
| |
| for _, prerequisite in ipairs(tech.technologyPrerequisites) do
| |
| if prerequisite and prerequisite ~= "" then
| |
| prerequisitesStr = prerequisitesStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
| |
| .. prerequisite .. '.png|' .. prerequisite
| |
| .. '|Мета=32x32px,link=}}'
| |
| .. prerequisite .. '</li>'
| |
| end
| |
| end
| |
| prerequisitesStr = prerequisitesStr .. '</ul>'
| |
| end
| |
|
| |
|
| -- Формирование строки unlocks
| | local parts = {} |
| local unlocksStr = ""
| | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") |
| if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
| | for _, suf in ipairs(found) do |
| unlocksStr = '<ul>'
| | table.insert(parts, "<option>" .. suf .. "</option>") |
| for _, recipe in ipairs(tech.recipeUnlocks) do
| | end |
| if recipe and recipe ~= "" then
| | table.insert(parts, "</choose>") |
| unlocksStr = unlocksStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
| |
| .. recipe .. '.png|' .. recipe
| |
| .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
| |
| .. recipe .. '}}</li>'
| |
| end
| |
| end
| |
| unlocksStr = unlocksStr .. '</ul>'
| |
| end
| |
| | |
| -- Формируем вывод с использованием шаблона
| |
| out = out .. mw.getCurrentFrame():preprocess(
| |
| '{{Prototypes/Механика/Исследование' ..
| |
| '|id=' .. tech.id ..
| |
| '|icon=' .. iconPath ..
| |
| '|name=' .. tech.name ..
| |
| '|discipline=' .. tech.discipline ..
| |
| '|tier=' .. tech.tier ..
| |
| '|tierColor=' .. tierColor ..
| |
| '|disciplineName=' .. disciplineName ..
| |
| '|cost=' .. tech.cost ..
| |
| '|prerequisites=' .. prerequisitesStr ..
| |
| '|unlocks=' .. unlocksStr ..
| |
| '}}'
| |
| )
| |
| end
| |
|
| |
|
| out = out
| | 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 |