Модуль:Обработка
Внешний вид
Для документации этого модуля может быть создана страница Модуль:Обработка/doc
-- Экспортируемые функции
local p = {}
p.interface = function(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
-- Контейнер интерфейса
local body = mw.html.create('div')
local recipe = body:tag('span'):addClass('gui-recipe')
-------------------------------------- Используемые функции ---------------------------------------
-- Добавление слота
local slot = require('Модуль:Инвентарный слот').slot
local addSlot = function(args, mod, item, Back_ID, class, style)
return slot{
args[item], ["мод"] = mod, ["класс"] = class, ["Фон ИД"] = Back_ID, ["стиль"] = style
}
end
-- Анимирование текста
local animate = function(txt)
if string.find(txt, ';') then
local result = {}
for text in mw.text.gsplit( txt, '%s*;%s*' ) do
if text ~= '' then
table.insert( result, '<span>' .. text .. '</span>' )
end
end
result[1] = result[1]:gsub( '^<span>', '<span class="animated-active">' )
txt = '<span class="animated">' .. table.concat( result ) .. '</span>'
end
return txt
end
-- Конструктор текста с подсказкой
local help_string = function (HBody, HTitle, HText)
HBody:css('border-bottom','1px dotted')
HBody:css('cursor','help')
HBody:attr('title', HText)
HBody:wikitext(HTitle)
return HBody
end
-- Конструктор строк потребления
local EString = function(EBody_Title, EBody_Help, arg, EBody_Unit)
if not EStrings then
EStrings = body:tag('div'):addClass('gui-energy-lines')
end
local EBody = EStrings:tag('div')
local EBody_Text = EBody:tag('span')
EBody_Text = help_string(EBody_Text, EBody_Title, EBody_Help)
EBody:wikitext(' ' .. animate(arg) .. ' ')
if EBody_Unit then
EBody:wikitext(EBody_Unit)
end
h_size = h_size + 22
return EBody
end
---------------------------------------------------------------------------------------------------
-- Параметры машины
local versions = {
["GregTech 4"] = 'GregTech 4',
["gt4"] = 'GregTech 4',
["GT4"] = 'GregTech 4',
["GregTech 5"] = 'GregTech 5',
["gt5"] = 'GregTech 5',
["GT5"] = 'GregTech 5',
["GregTech 5 Unofficial"] = 'GregTech 5 Unofficial',
["gt5u"] = 'GregTech 5 Unofficial',
["GT5U"] = 'GregTech 5 Unofficial',
["GregTech 6"] = 'GregTech 6',
["gt6"] = 'GregTech 6',
["GT6"] = 'GregTech 6',
["IndustrialCraft 2"] = 'IndustrialCraft 2',
["ic2"] = 'IndustrialCraft 2',
["IC2"] = 'IndustrialCraft 2',
["Metallurgy"] = 'Metallurgy',
'&4Неизвестна',
}
local progress = args["Прогресс"]
local machine_list = {}
local machine = {}
local furnace_like = true
local class2 = 'invslot-large'
if progress then
version = args["Версия"] or mw.ustring.match(progress, ':%s*([a-zA-Zа-яА-ЯёЁ 0-9]+)') or args["Мод"]
progress = mw.ustring.match(progress, '([a-zA-Zа-яА-ЯёЁ 0-9]+):') or progress
if version then
if versions[version] then
version = versions[version]
machine_list = mw.loadData('Модуль:Обработка/' .. version)
machine = machine_list[progress]
furnace_like = false
class2 = machine["Out_class"] or ''
else
end
else
version = versions[1]
body:wikitext('[[Категория:Страницы с неизвестной версией машин]]')
end
else
machine = {
["Image"]="[[Файл:Layout_fire.gif|link=|36px|class=pixel-image]]",
["Def_args"] = {["Топливо"] = "v:Любое топливо"}}
progress = 'Печь'
end
local mod = args["Мод"] or machine_list['def_mod']
-- Предопределённые аргументы
if machine["Def_args"] then
for k,v in pairs(machine["Def_args"]) do
args[k] = args[k] or v
end
end
-- Конфигурация ячеек
local machine_code = args["Машина"] or machine[1] or '21110000'
local input_rows = string.sub(machine_code,1,1) * 1
local input_cols = string.sub(machine_code,2,2) * 1
local output_rows = string.sub(machine_code,3,3) * 1
local output_cols = string.sub(machine_code,4,4) * 1
local fluid_input_rows = string.sub(machine_code,5,5) * 1
local fluid_input_cols = string.sub(machine_code,6,6) * 1
local fluid_output_rows = string.sub(machine_code,7,7) * 1
local fluid_output_cols = string.sub(machine_code,8,8) * 1
-- Определитель стиля
local class1 = ''
if class2 == 'invslot-large' then
large = 16
else
large = 0
end
local style = machine_list["Skin"] or 'craft-gui'
if machine["Skin"] then
style = style .. '-' .. machine["Skin"]
class1 = machine["Skin"] .. '_invslot'
end
-- Иконка реакции
local input_pic = 0
if (machine_list["Image"] or machine["Image"]) and machine["Image"] ~= 'None' then
fuelImg = machine["Image"] or machine_list["Image"]
input_pic = 1
elseif args["Расход"] then
fuelImg = '[[Файл:Grid layout ' .. args["Расход"] .. ' (' .. version .. ').png|link=]]'
input_pic = 1
end
-- Переопределение количества получаемых предметов (1-4)
if args["Уровень"] then
output_rows = math.floor (args["Уровень"] / 4) + 1
output_cols = args["Уровень"] / output_rows
end
-- Предопределение или конвертация некоторых аргументов
args["Шанс1"] = args["Шанс1"] or args["Шанс"]
args["Ресурс1"] = args["Ресурс1"] or args["Ресурс"] or args[1]
args["Ресурс2"] = args["Ресурс2"] or args["Топливо"] or args["топливо"]
args["Выход1"] = args["Выход1"] or args["Выход"] or args[2]
args["Опыт"] = args["Опыт"] or args[3]
args["РесурсЖ1"] = args["РесурсЖ1"] or args["РесурсЖ"]
args["РЖК1"] = args["РЖК1"] or args["РЖК"]
args["РЖТ1"] = args["РЖТ1"] or args["РЖТ"]
args["ВыходЖ1"] = args["ВыходЖ1"] or args["ВыходЖ"]
args["ВЖК1"] = args["ВЖК1"] or args["ВЖК"]
args["ВЖТ1"] = args["ВЖТ1"] or args["ВЖТ"]
if args["Выход7"] and progress == 'Просеиватель' and version == 'GregTech 6' then
args["Шанс1"] = '0.01'
args["Шанс2"] = '01'
args["Шанс3"] = '04'
args["Шанс4"] = '15'
args["Шанс5"] = '20'
args["Шанс6"] = '40'
args["Шанс7"] = '50'
end
-- Параметры стрелки прогресса
if machine_list['Параметры'] then
param = machine_list['Параметры']
else
param = {
['sprite_size'] = 140,
['scale'] = 2,
["default_ID"] = 1,
["arrow_width"] = 28,
["arrow_height"] = 24
}
end
local size = param['arrow_width'] -- ширина спрайта в пикселях
local v_size = param['arrow_height'] -- высота спрайта в пикселях
local pos = (machine['arrow_ID'] or param["default_ID"]) - 1 -- положение спрайта в таблице
local sheetWidth = param['sprite_size'] -- ширина таблицы спрайта в пикселях
local tiles = sheetWidth / size -- количество спрайтов в одной строке
local left = pos % tiles * size -- горизонтальная координата спрайта
local top = math.floor(pos / tiles) * v_size -- вертикальная координата спрайта
local scale = param['scale'] -- масштаб спрайта (во сколько раз увеличить или уменьшить размер)
local arrow_width = (machine['arrow_width'] or size) * scale -- ширина спрайта с учётом масштаба
local arrow_height = (machine['arrow_height'] or v_size) * scale -- высота спрайта с учётом масштаба
-- Размеры и отступы шаблона
input_size = math.max(input_cols,fluid_input_cols) * 36
output_size = math.max(output_cols,fluid_output_cols) * (36 + large)
local h_margin = (270 - output_size - input_size - arrow_width) / 2
if (input_rows + fluid_input_rows) > 3 or (output_rows + fluid_output_rows) > 3 then
h_size = 150
else
h_size = 128
end
recipe:css('margin', '0 ' .. math.floor(0.75 * h_margin) .. 'px')
recipe:css('height', h_size .. 'px')
recipe:css('display', 'inline-flex')
if ( fluid_input_rows * fluid_output_rows * input_rows * output_rows ) > 0 then
local max_fluid_rows = math.max(fluid_output_rows,fluid_input_rows)
v_margin_input = (h_size - 36 * (input_rows + max_fluid_rows)) / 2
v_margin_output = (h_size - 36 * (output_rows + max_fluid_rows)) / 2
else
v_margin_input = (h_size - 36 * (input_rows + fluid_input_rows + input_pic)) / (3 - 0 ^ input_rows - 0 ^ fluid_input_rows)
v_margin_output = (h_size - (36 + large) * (output_rows + fluid_output_rows)) / (3 - 0 ^ output_rows - 0 ^ fluid_output_rows)
end
------------------------------------------ Ячейки ресурсов ----------------------------------------
local input = recipe:tag('span'):addClass('gt-input')
input:css('width', input_size .. 'px')
input:css('margin-top', v_margin_input .. 'px')
if input_rows > 0 then
local item_input = input:tag('span')
if fluid_input_cols > input_cols then
item_input:css('margin-left', (fluid_input_cols - input_cols) * 36 .. 'px')
end
num = 0
for i = 1, input_rows do
for j = 1, input_cols do
num = num + 1
if args["Ресурс" .. num] ~= 'none' then
if args["Параметр"] and string.find(args["Ресурс" .. num], 'Интегральная схема') then
args["Ресурс" .. num] = args["Ресурс" .. num] .. "[&7 Параметр: " .. args["Параметр"] .. "/]"
end
if machine['slot_back'] then
s = machine['slot_back']['in' .. num] or machine['slot_back']['in']
else
s = nil
end
item_input:wikitext(addSlot(args, mod, 'Ресурс' .. num,s,class1))
end
end
if (input_pic == 1 and i == 1) then
item_input:wikitext(fuelImg .. '<br>')
end
end
end
if progress == 'Режущий механизм' then
input:wikitext(addSlot(args, mod, 'Диск',nil,'invslot-plain','position:absolute; top:55px; left:116px'))
end
if machine["Mid_input"] then
if machine['slot_back'] then
s = machine['slot_back']['mid']
else
s = nil
end
input:wikitext(addSlot(args, mod, 'РесурсЦ',s,'','position:absolute; top:96px; left:' .. 6 + h_margin + input_size + (arrow_width - 36) / 2 .. 'px'))
end
-------------------------------------- Ячейки жидких ресурсов -------------------------------------
if fluid_input_rows > 0 then
local fluid_input = input:tag('div')
fluid_input:css('text-align', 'right')
if input_pic ~= 1 then
fluid_input:css('margin-top', v_margin_input .. 'px')
end
num = 0
for i = 1, fluid_input_rows do
for j = 1, fluid_input_cols do
num = num + 1
if machine['slot_back'] then
s = machine['slot_back']['fl_in' .. num] or machine['slot_back']['fl_in']
else
s = nil
end
if args["РесурсЖ" .. num] then
c = 0
fl_split = {}
fl_quantity = {}
fl_temp = {}
for text in mw.text.gsplit( args["РЖК" .. num] or '', '%s*;%s*' ) do
if text ~= '' then
table.insert( fl_quantity, '/&9 Объём: ' .. text .. ' мВ/' )
end
end
for text in mw.text.gsplit( args["РЖТ" .. num] or '', '%s*;%s*' ) do
if text ~= '' then
table.insert( fl_temp, '&c Температура: ' .. text .. ' К/' )
end
end
if fl_quantity[1] or fl_temp[1] then
for text in mw.text.gsplit(args["РесурсЖ" .. num] , '%s*;%s*') do
if text ~= '' then
c = c + 1
text = text .. '[' .. (fl_quantity[c] or fl_quantity[1] or '') .. (fl_temp[c] or fl_temp[1] or '') .. ']'
end
table.insert( fl_split, text )
end
args["РесурсЖ" .. num] = table.concat(fl_split , ';')
end
end
fluid_input:wikitext(addSlot(args, mod, 'РесурсЖ' .. num,s,'fluid_invslot'))
end
end
end
---------------------------------------- Стрелка прогресса ----------------------------------------
local arrowtext = '&3' .. progress
if machine[2] then
arrowtext = arrowtext .. '/&9' .. machine[2] --англ. название
end
if version then
arrowtext = arrowtext .. '//&7Модификация:/' .. version
end
local arrow = recipe:tag('span'):addClass('minetip')
arrow:attr('data-minetip-title','Обработчик:')
arrow:attr('data-minetip-text', arrowtext)
arrow:css('margin', 'auto ' .. math.floor(0.25 * h_margin) .. 'px')
if not furnace_like then
arrow:wikitext('[[' .. version .. '/' .. progress .. '|')
local ArrowImg = arrow:tag('span'):addClass('sprite arrow-' .. machine_list["Arrows"])
ArrowImg:css('height', arrow_height .. 'px')
ArrowImg:css('width', arrow_width .. 'px')
ArrowImg:css('background-position', '-' .. left * scale .. 'px -' .. top * scale ..'px')
ArrowImg:css('background-size', sheetWidth * scale .. 'px auto')
arrow:wikitext(']]')
else
if progress ~= 'Печь' and mod then
arrow:wikitext('[[Файл:Grid layout ' .. progress .. ' Progress (' .. mod .. ').png|link=' .. mod .. '/' .. progress .. ']]')
else
arrow:wikitext('[[Файл:Grid_layout_Furnace_Progress.gif|link=Печь]]')
end
arrow:css('width', arrow_width .. 'px')
end
if progress == 'Формовщик металла' and args["Режим"] then
local mode = recipe:tag('div'):addClass('minetip')
mode:css('position', 'absolute')
mode:css('top', '86px')
mode:css('left', '113px')
mode:attr('data-minetip-title','Режим: ' .. args["Режим"])
mode:wikitext('[[Файл:Формовщик металла_(' .. args["Режим"] .. ')_(IndustrialCraft 2).png|link=]]')
end
----------------------------------------- Ячейки продуктов ----------------------------------------
local output = recipe:tag('span'):addClass('gt-output')
output:css('width', output_size .. 'px')
output:css('margin-top', v_margin_output .. 'px')
num = 0
if output_rows > 0 then
local item_output = output:tag('span')
for i = 1, output_rows do
for j = 1, output_cols do
num = num + 1
if machine['slot_back'] then
s = machine['slot_back']['out' .. num] or machine['slot_back']['out']
else
s = nil
end
if args["Шанс" .. num] then
c = 0
pr_split = {}
pr_chance = {}
for text in mw.text.gsplit( args["Шанс" .. num] or '', '%s*;%s*' ) do
if text ~= '' then
table.insert( pr_chance, '[&7 Шанс получения: ' .. text .. '%/]' )
end
end
for text in mw.text.gsplit(args["Выход" .. num] , '%s*;%s*') do
if text ~= '' then
c = c + 1
text = text .. (pr_chance[c] or pr_chance[1] or '')
end
table.insert( pr_split, text )
end
args["Выход" .. num] = table.concat(pr_split , ';')
end
item_output:wikitext(addSlot(args, mod, 'Выход' .. num,s,class1 .. ' ' .. class2))
end
end
end
-- Строка текста под получаемыми ресурсами
if args["Температура"] or args["Опыт"] then
local margin_out_2 = output:tag('div')
margin_out_2:css('margin-top','6px')
if args["Температура"] then
local margin_out_2_text = margin_out_2:tag('span')
margin_out_2_text = help_string(margin_out_2_text, animate(args["Температура"]) .. ' К', 'Необходимая температура печи в кельвинах.')
elseif args["Опыт"] then
margin_out_2:css('font-family', 'Minecraft-ru, sans-serif')
margin_out_2:wikitext(require('Модуль:Спрайт').base{ ['имякласса'] = 'xp-orb-sprite', ['выравн'] = 'text-bottom' })
local margin_out_3_text = margin_out_2:tag('span')
margin_out_3_text = help_string(margin_out_3_text, animate(args["Опыт"]), 'Дробная часть показывает вероятность получения единицы опыта.')
end
end
-------------------------------------- Ячейки жидких продуктов ------------------------------------
if fluid_output_rows > 0 then
local fluid_output = output:tag('div')
fluid_output:css('margin-top', v_margin_output .. 'px')
fluid_output:css('text-align','left')
num = 0
for i = 1, fluid_output_rows do
for j = 1, fluid_output_cols do
num = num + 1
if machine['slot_back'] then
s = machine['slot_back']['fl_out' .. num] or machine['slot_back']['fl_out']
else
s = nil
end
if args["ВыходЖ" .. num] then
c = 0
fl_split = {}
fl_quantity = {}
fl_temp = {}
for text in mw.text.gsplit( args["ВЖК" .. num] or '', '%s*;%s*' ) do
if text ~= '' then
table.insert( fl_quantity, '/&9 Объём: ' .. text .. ' мВ/' )
end
end
for text in mw.text.gsplit( args["ВЖТ" .. num] or '', '%s*;%s*' ) do
if text ~= '' then
table.insert( fl_temp, '&c Температура: ' .. text .. ' К/' )
end
end
if fl_quantity[1] or fl_temp[1] then
for text in mw.text.gsplit(args["ВыходЖ" .. num] , '%s*;%s*') do
if text ~= '' then
c = c + 1
text = text .. '[' .. (fl_quantity[c] or fl_quantity[1] or '') .. (fl_temp[c] or fl_temp[1] or '') .. ']'
end
table.insert( fl_split, text )
end
args["ВыходЖ" .. num] = table.concat(fl_split , ';')
end
end
fluid_output:wikitext(addSlot(args, mod, 'ВыходЖ' .. num,s,'fluid_invslot'))
end
end
end
---------------------------------------- Строки потребления ---------------------------------------
if args["Пар"] then
local vape = EString ('Пар:' , 'Объём пара, требующийся для проведения операции.' , args ["Пар"])
local vapeunit = vape:tag('span')
vapeunit = help_string(vapeunit, 'мВ', 'Милливедро (мВ) — единица объёма условно равная 1/1000 части ведра.')
end
if args["Старт"] then
local start = EString ('Старт:' , 'Энергия, требующаяся на запуск процесса.' , args ["Старт"], '[[IndustrialCraft_2|еЭ]]')
end
if args["Энергия"] then
local energy = EString ('Энергия:' , 'Энергия, затрачиваемая на каждую операцию.' , args ["Энергия"], '[[IndustrialCraft_2|еЭ]]')
end
if args["Потребление"] then
local consumption = EString ('Потребление:' , 'Скорость потребления энергии.' , args ["Потребление"], '[[IndustrialCraft_2|еЭ]]/[[Такт|т]]')
end
if args["Напряжение"] then
local voltage = EString ('Напряжение:' , 'Требуемое для операции напряжение.' , args ["Напряжение"], '[[IndustrialCraft_2|еЭ]]/[[Такт|т]]')
end
if args["Сила тока"] then
local amper = EString ('Сила тока:' , 'Требуемая для операции сила тока.' , args ["Сила тока"])
end
if args["Время"] then
local timer = EString ('Время:' , 'Время, затрачиваемое на операцию.' , args ["Время"], 'сек.')
end
---------------------------------------------------------------------------------------------------
if machine_list["Logo"] and not machine["Logo"] then
local GTlogo = body:tag('div'):addClass('gt-pic')
if machine["Skin"] then
GTlogo:addClass('gt-' .. machine["Skin"] .. '-pic')
else
GTlogo:addClass('gt-' .. machine_list["Logo"] .. '-pic')
end
end
if h_size > 140 then
body:css('height', h_size .. 'px')
end
body:addClass(style .. ' gui')
return tostring(body)
end
return p