Module:Crafting: Difference between revisions
Jump to navigation
Jump to search
boldly copied from minecraft wiki |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local i18n = { | local i18n = { | ||
moduleArgs = [[Module:ProcessArgs]], | moduleArgs = [[Module:ProcessArgs]], | ||
| Line 10: | Line 9: | ||
p.i18n = i18n | p.i18n = i18n | ||
local slot = require( i18n.moduleSlot ) | local slot = require( i18n.moduleSlot ) | ||
local cArgVals = { 'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3' } | local cArgVals = { 'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3' } | ||
p.cArgVals = cArgVals | p.cArgVals = cArgVals | ||
local function arrangeShapelessRecipe(args) | local function arrangeShapelessRecipe(args) | ||
if args[1] then | if args[1] then | ||
| Line 29: | Line 24: | ||
args.C2 = args[6] | args.C2 = args[6] | ||
if args[8] then | if args[8] then | ||
args.A3 = args[7] | args.A3 = args[7] | ||
args.B3 = args[8] | args.B3 = args[8] | ||
args.C3 = args[9] | args.C3 = args[9] | ||
if args[9] then | if args[9] then | ||
local identical = true | local identical = true | ||
for i = 1, 8 do | for i = 1, 8 do | ||
| Line 50: | Line 40: | ||
end | end | ||
else | else | ||
args.B3 = args[7] | args.B3 = args[7] | ||
end | end | ||
| Line 59: | Line 46: | ||
args.B2 = args[2] | args.B2 = args[2] | ||
if args[5] then | if args[5] then | ||
args.C2 = args[3] | args.C2 = args[3] | ||
args.A3 = args[4] | args.A3 = args[4] | ||
| Line 67: | Line 51: | ||
args.C3 = args[6] | args.C3 = args[6] | ||
elseif args[4] then | elseif args[4] then | ||
args.A3 = args[3] | args.A3 = args[3] | ||
args.B3 = args[4] | args.B3 = args[4] | ||
else | else | ||
args.B3 = args[3] | args.B3 = args[3] | ||
end | end | ||
else | else | ||
args.B2 = args[1] | args.B2 = args[1] | ||
args.shapeless = nil | args.shapeless = nil | ||
end | end | ||
for i = 1, 9 do | for i = 1, 9 do | ||
args[i] = nil | args[i] = nil | ||
| Line 95: | Line 67: | ||
end | end | ||
function p.table( f ) | function p.table( f ) | ||
local args = f | local args = f | ||
if f == mw.getCurrentFrame() then | if f == mw.getCurrentFrame() then | ||
| Line 105: | Line 75: | ||
end | end | ||
arrangeShapelessRecipe(args) | arrangeShapelessRecipe(args) | ||
-- | local container = mw.html.create('div'):addClass('mc-crafting-wrapper') | ||
local | local grid = container:tag('div'):addClass('mc-grid') | ||
return | for _, slotName in ipairs(cArgVals) do | ||
local cell = grid:tag('div'):addClass('mc-cell') | |||
if args[slotName] and args[slotName] ~= "" then | |||
cell:wikitext(slot.slot{args[slotName]}) | |||
end | |||
end | |||
container:tag('div'):addClass('mc-arrow'):wikitext('→') | |||
local result = container:tag('div'):addClass('mc-result') | |||
if args['Output'] and args['Output'] ~= "" then | |||
result:wikitext(slot.slot{args['Output']}) | |||
end | |||
return tostring(container) | |||
end | end | ||
return p | return p | ||
Latest revision as of 00:55, 26 April 2026
Documentation for this module may be created at Module:Crafting/doc
local p = {}
local i18n = {
moduleArgs = [[Module:ProcessArgs]],
moduleRecipe = [[Module:Recipe table]],
moduleSlot = [[Module:Inventory slot]],
type = 'Crafting'
}
p.i18n = i18n
local slot = require( i18n.moduleSlot )
local cArgVals = { 'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3' }
p.cArgVals = cArgVals
local function arrangeShapelessRecipe(args)
if args[1] then
args.shapeless = 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
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.shapeless = 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
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
args.B3 = args[3]
end
else
args.B2 = args[1]
args.shapeless = nil
end
for i = 1, 9 do
args[i] = nil
end
end
end
function p.table( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( i18n.moduleArgs ).merge( true )
else
f = mw.getCurrentFrame()
end
arrangeShapelessRecipe(args)
local container = mw.html.create('div'):addClass('mc-crafting-wrapper')
local grid = container:tag('div'):addClass('mc-grid')
for _, slotName in ipairs(cArgVals) do
local cell = grid:tag('div'):addClass('mc-cell')
if args[slotName] and args[slotName] ~= "" then
cell:wikitext(slot.slot{args[slotName]})
end
end
container:tag('div'):addClass('mc-arrow'):wikitext('→')
local result = container:tag('div'):addClass('mc-result')
if args['Output'] and args['Output'] ~= "" then
result:wikitext(slot.slot{args['Output']})
end
return tostring(container)
end
return p