Установіть зараз і легко шукайте інформацію у вікі під час гри, наводячи курсор на блок, предмет або сутність і натискаючи англ. H.
|
Модуль:Майстрування
Перейти до навігації
Перейти до пошуку
Цей модуль реалізує {{Майстрування}}
.
Батьківські аргументи автоматично об'єднуються з безпосередньо переданими аргументами (останні перезаписують перші).
Залежності[ред. код]
Див. також[ред. код]
[перегляд] [редагувати] [історія] [оновити]Розташована вище документація включена з Модуль:Майстрування/док.
local p = {}
local i18n = {
moduleArgs = [[Модуль:ProcessArgs]],
moduleRecipe = [[Модуль:Таблиця рецептів]],
moduleSlot = [[Модуль:Інвентарний слот]],
moduleAliases = [[Модуль:Інвентарний слот/Псевдоніми]],
type = 'Майстрування'
}
p.i18n = i18n
local slot = require( i18n.moduleSlot )
local recipeTable = require( i18n.moduleRecipe ).table
local aliases = mw.loadData( i18n.moduleAliases )
local cArgVals = { 'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3' }
p.cArgVals = cArgVals
function p.table( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( i18n.moduleArgs ).merge( true )
else
f = mw.getCurrentFrame()
end
-- Automatic shapeless positioning
if args[1] then
args['безформний'] = 1
if args[7] then
args.A1 = args[1]
args.B1 = args[2]
args.C1 = args[3]
args.A2 = args[4]
args.B2 = args[5]
args.C2 = args[6]
if args[8] then
-- ◼◼◼ ◼◼◼
-- ◼◼◼ OR ◼◼◼
-- ◼◼◼ ◼◼◻
args.A3 = args[7]
args.B3 = args[8]
args.C3 = args[9]
if args[9] then
local identical = true
for i = 1, 8 do
if args[i] ~= args[i + 1] then
identical = false
break
end
end
if identical then
args['безформний'] = nil
end
end
else
-- ◼◼◼
-- ◼◼◼
-- ◻◼◻
args.B3 = args[7]
end
elseif args[2] then
args.A2 = args[1]
args.B2 = args[2]
if args[5] then
-- ◻◻◻ ◻◻◻
-- ◼◼◼ OR ◼◼◼
-- ◼◼◼ ◼◼◻
args.C2 = args[3]
args.A3 = args[4]
args.B3 = args[5]
args.C3 = args[6]
elseif args[4] then
-- ◻◻◻
-- ◼◼◻
-- ◼◼◻
args.A3 = args[3]
args.B3 = args[4]
else
-- ◻◻◻ ◻◻◻
-- ◼◼◻ OR ◼◼◻
-- ◻◼◻ ◻◻◻
args.B3 = args[3]
end
else
-- ◻◻◻
-- ◻◼◻
-- ◻◻◻
args.B2 = args[1]
args['безформний'] = nil
end
for i = 1, 9 do
args[i] = nil
end
end
-- Create recipe table, and list of ingredients
local out, ingredientSets, outputSets = recipeTable( args, {
uiFunc = 'craftingTable',
type = i18n.type,
ingredientArgs = cArgVals,
outputArgs = { 'Вихід' },
} )
local title = mw.title.getCurrentTitle()
if args['ігнорувати'] or args['некат'] == '1' or title.namespace ~= 0 or title.isSubpage then
return out
end
-- SMW
-- Json contains the full frames, the other SMW properties are just item names.
local smw_json = {
["тип"] = args['тип'],
["безформний"] = args['безформний'],
["фіксований"] = args['фіксований'],
["нефіксований"] = args['нефіксований'],
["опис"] = mw.text.unstrip(args['опис'] or ''), --Remove ref tags
["ім\'я"] = args['ім\'я'],
["інгредієнти"] = args['інгредієнти'],
["некат"] = args['некат'],
["A1"] = args.A1,
["A2"] = args.A2,
["A3"] = args.A3,
["B1"] = args.B1,
["B2"] = args.B2,
["B3"] = args.B3,
["C1"] = args.C1,
["C2"] = args.C2,
["C3"] = args.C3,
["Вихід"] = args['Вихід'],
["група"] = args['група']
}
-- Flatten the item sets into a simple list
local function makeNameList(itemSets)
local retTable = {}
local inputRetTable = {}
local usedNames = {}
for _, itemSet in pairs(itemSets) do
for _, item in pairs(itemSet) do
--local name = item.mod .. ":" .. item.name -- use instead of just item.name if mods are covered
if not usedNames[item.name] then
table.insert(retTable, item.name)
table.insert(inputRetTable, item.name)
usedNames[item.name] = true
if aliases[item.name] then
for _, aliasEntry in ipairs(aliases[item.name]) do
if not usedNames[aliasEntry] then
table.insert(retTable, (aliasEntry.name or aliasEntry)) -- Sometimes the alias entry is a table, so try and grab its name from within the table with a fallback to just the entry.
usedNames[aliasEntry] = true
end
end
end
end
end
end
return retTable, inputRetTable
end
local output_names, original_output_names = makeNameList(outputSets)
local ingredient_names, original_ingredient_names = makeNameList(ingredientSets)
local group_names = {}
if args['група'] then
for name in string.gmatch(args['група'], "[^,]+") do
table.insert(group_names, mw.text.trim(name))
end
end
local json = mw.text.jsonEncode(smw_json)
local smw_sub = {}
-- We must have a unique subname since Crafting usage cannot handle when multiple json entries are within one sub object.
local subname = 'ВИХІД_'..mw.ustring.sub(table.concat(original_output_names,'_'),1,50)..'_З_'..mw.ustring.sub(table.concat(original_ingredient_names,'_'),1,50)..'_'..mw.hash.hashValue("md4",json)
local smw_sub = { -- the actual SMW sub-object
['Інгредієнт майстрування'] = ingredient_names,
['Вихід майстрування'] = output_names,
['JSON майстрування'] = json,
['Тип майстрування'] = args['тип']
}
mw.smw.subobject(smw_sub, subname)
return out
end
return p