|
|
| (не показаны 403 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {}
| |
|
| |
|
| -- Функция для загрузки данных исследований из JSON-файла
| |
| local function loadResearchData()
| |
| return mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/Песочница.json"):getContent())
| |
| end
| |
|
| |
| -- Функция для поиска исследований по дисциплине
| |
| local function findResearchByDiscipline(dataCache, discipline)
| |
| local results = {}
| |
| for _, research in ipairs(dataCache) do
| |
| if research.discipline == discipline then
| |
| table.insert(results, research)
| |
| end
| |
| end
| |
| return results
| |
| end
| |
|
| |
| -- Функция для поиска исследования по ID
| |
| local function findResearchById(dataCache, id)
| |
| for _, research in ipairs(dataCache) do
| |
| if research.id == id then
| |
| return research
| |
| end
| |
| end
| |
| return nil
| |
| 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 idOrDiscipline = frame.args.id or ""
| |
|
| |
| if disciplineMapping[idOrDiscipline] then
| |
| -- Если это дисциплина, выводим все исследования данной группы
| |
| local researches = findResearchByDiscipline(dataCache, idOrDiscipline)
| |
| local out = cssLink .. '<div class="research-group">'
| |
|
| |
| for _, tech in ipairs(researches) do
| |
| local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование"
| |
| local tierColor = tierColors[tech.tier] or "#FFFFFF"
| |
| local iconPath = tech.icon.sprite
| |
|
| |
| out = out .. '<div class="research" id="' .. tech.discipline .. '">'
| |
| out = out .. '<div class="research__images">{{#invoke:Entity Sprite|main|path=' .. iconPath .. '}}</div>'
| |
| out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>'
| |
| out = out .. '<div class="research__type">'
| |
| out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>'
| |
| out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
| |
| out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
| |
| out = out .. '</div>'
| |
| out = out .. '</div>'
| |
| end
| |
|
| |
| out = out .. '</div>'
| |
| return out
| |
| else
| |
| -- Если это ID, выводим одно исследование
| |
| local tech = findResearchById(dataCache, idOrDiscipline)
| |
| if not tech then
| |
| return cssLink .. '<div style="color:red;">Исследование с ID или дисциплиной "' .. idOrDiscipline .. '" не найдено.</div>'
| |
| end
| |
|
| |
| local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование"
| |
| local tierColor = tierColors[tech.tier] or "#FFFFFF"
| |
| local iconPath = tech.icon.sprite
| |
|
| |
| -- Блок данных
| |
| local out = cssLink .. '<div class="research" id="' .. tech.discipline .. '">'
| |
| out = out .. '<div class="research__images">{{#invoke:Entity Sprite|main|path=' .. iconPath .. '}}</div>'
| |
| out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>'
| |
| out = out .. '<div class="research__type">'
| |
| out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>'
| |
| out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
| |
| out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
| |
| out = out .. '</div>'
| |
| out = out .. '</div>'
| |
|
| |
| return out
| |
| end
| |
| end
| |
|
| |
| return p
| |