Terraria Wiki
Terraria Wiki
1 577
páginas
mSem resumo de edição
mSem resumo de edição
Linha 107: Linha 107:
 
-- normalize ingredient name input, Lead Bar=>¦Lead Bar¦, Iron/Lead Bar => ¦Iron Bar¦Lead Bar¦, Lead/Iron Bar => ¦Iron Bar¦Lead Bar¦ ....
 
-- normalize ingredient name input, Lead Bar=>¦Lead Bar¦, Iron/Lead Bar => ¦Iron Bar¦Lead Bar¦, Lead/Iron Bar => ¦Iron Bar¦Lead Bar¦ ....
 
local normalize = function(name)
 
local normalize = function(name)
local result = '¦'
+
local Resultado = '¦'
 
for k, v in ipairs(split(name)) do
 
for k, v in ipairs(split(name)) do
result = result .. itemname(v) .. '¦'
+
Resultado = Resultado .. itemname(v) .. '¦'
 
end
 
end
return result
+
return Resultado
 
end
 
end
   
Linha 212: Linha 212:
 
end
 
end
 
constraints['station'] = str
 
constraints['station'] = str
-- result = ? and result != ?
+
-- Resultado = ? and Resultado != ?
local _result = trim(args['result'] or '')
+
local _Resultado = trim(args['Resultado'] or '')
local _resultnot = trim(args['resultnot'] or '')
+
local _Resultadonot = trim(args['Resultadonot'] or '')
 
local str = ''
 
local str = ''
if _result ~= '' then
+
if _Resultado ~= '' then
for _, v in ipairs(explode('/', _result)) do
+
for _, v in ipairs(explode('/', _Resultado)) do
 
if str ~= '' then
 
if str ~= '' then
 
str = str .. ' OR '
 
str = str .. ' OR '
 
end
 
end
 
if mw.ustring.sub(v, 1, 5) == 'LIKE ' then
 
if mw.ustring.sub(v, 1, 5) == 'LIKE ' then
str = str .. "result LIKE " .. enclose(trim(mw.ustring.sub(v, 6)))
+
str = str .. "Resultado LIKE " .. enclose(trim(mw.ustring.sub(v, 6)))
 
else
 
else
str = str .. 'result=' .. enclose(v)
+
str = str .. 'Resultado=' .. enclose(v)
 
end
 
end
 
end
 
end
 
end
 
end
if _resultnot ~= '' then
+
if _Resultadonot ~= '' then
 
if str ~= '' then
 
if str ~= '' then
 
str = '(' .. str .. ')'
 
str = '(' .. str .. ')'
 
end
 
end
for _, v in ipairs(explode('/', _resultnot)) do
+
for _, v in ipairs(explode('/', _Resultadonot)) do
 
if str ~= '' then
 
if str ~= '' then
 
str = str .. ' AND '
 
str = str .. ' AND '
 
end
 
end
 
if mw.ustring.sub(v, 1, 5) == 'LIKE ' then
 
if mw.ustring.sub(v, 1, 5) == 'LIKE ' then
str = str .. "result NOT LIKE " .. enclose(trim(mw.ustring.sub(v, 6)))
+
str = str .. "Resultado NOT LIKE " .. enclose(trim(mw.ustring.sub(v, 6)))
 
else
 
else
str = str .. 'result <> ' .. enclose(v)
+
str = str .. 'Resultado <> ' .. enclose(v)
 
end
 
end
 
end
 
end
 
end
 
end
 
if str ~= '' then
 
if str ~= '' then
constraints['result'] = str
+
constraints['Resultado'] = str
 
end
 
end
 
-- ingredient = ?
 
-- ingredient = ?
Linha 280: Linha 280:
 
where = constraints['station']
 
where = constraints['station']
 
end
 
end
if constraints['result'] then
+
if constraints['Resultado'] then
 
if where ~= '' then
 
if where ~= '' then
 
where = where .. ' AND '
 
where = where .. ' AND '
 
end
 
end
where = where .. '(' .. constraints['result'] .. ')'
+
where = where .. '(' .. constraints['Resultado'] .. ')'
 
end
 
end
 
if constraints['ingredient'] then
 
if constraints['ingredient'] then
Linha 301: Linha 301:
 
end
 
end
   
local resultCell = function(row, showResultId, needLink, noVersion)
+
local ResultadoCell = function(row, showResultadoId, needLink, noVersion)
local result, resultid, resultimage, resulttext, amount, version = row['result'], row['resultid'], row['resultimage'], row['resulttext'], row['amount'], row['version']
+
local Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version = row['Resultado'], row['Resultadoid'], row['Resultadoimage'], row['Resultadotext'], row['amount'], row['version']
 
local str = ''
 
local str = ''
 
local args = {anchor = 'y', nolink = not needLink, class='multi-line'}
 
local args = {anchor = 'y', nolink = not needLink, class='multi-line'}
if showResultId then
+
if showResultadoId then
args['id'] = resultid
+
args['id'] = Resultadoid
 
end
 
end
if resultimage then
+
if Resultadoimage then
args['image'] = resultimage
+
args['image'] = Resultadoimage
 
end
 
end
if resulttext then
+
if Resultadotext then
args[2] = resulttext
+
args[2] = Resultadotext
 
end
 
end
str = str .. itemLink(result, args)
+
str = str .. itemLink(Resultado, args)
 
if amount ~= '1' then
 
if amount ~= '1' then
 
str = str .. ' <span class="note-text">('..amount..')</span>'
 
str = str .. ' <span class="note-text">('..amount..')</span>'
Linha 532: Linha 532:
 
_field = 'col-A-' .. _i
 
_field = 'col-A-' .. _i
 
end
 
end
str = str .. '<th class="result">' .. (getArg('header-result') or 'Result') .. '</th>'
+
str = str .. '<th class="Resultado">' .. (getArg('header-Resultado') or 'Resultado') .. '</th>'
 
_i = 1
 
_i = 1
 
_field = 'col-B-1'
 
_field = 'col-B-1'
Linha 607: Linha 607:
 
end
 
end
   
local tableRow = function(str, row, current_station, station_count, rows_count, showResultId, withStation, needCate, needLink, needGroup, current_result, result_count, current_result_ext, result_ext_count)
+
local tableRow = function(str, row, current_station, station_count, rows_count, showResultadoId, withStation, needCate, needLink, needGroup, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count)
local str_w = '' -- before result col
+
local str_w = '' -- before Resultado col
local str_x = '' -- between result and Ingredientes cols
+
local str_x = '' -- between Resultado and Ingredientes cols
 
local str_y = '' -- between Ingredientes and station cols
 
local str_y = '' -- between Ingredientes and station cols
 
local str_z = '' -- after station
 
local str_z = '' -- after station
local str_resultCell = ''
+
local str_ResultadoCell = ''
   
local result_index = getArg('result-index-#'..rows_count) or getArg('result-index-'..row['result']..'-'..row['version']) or getArg('result-index-'..row['result'])
+
local Resultado_index = getArg('Resultado-index-#'..rows_count) or getArg('Resultado-index-'..row['Resultado']..'-'..row['version']) or getArg('Resultado-index-'..row['Resultado'])
   
 
str = str .. '<tr data-rowid="'..tostring(rows_count)..'">'
 
str = str .. '<tr data-rowid="'..tostring(rows_count)..'">'
   
 
if needGroup then
 
if needGroup then
local result = row['result']..'|'..row['resultid']..'|'..row['resultimage']..'|'..row['resulttext']..'|'..row['amount']..'|'..row['version']
+
local Resultado = row['Resultado']..'|'..row['Resultadoid']..'|'..row['Resultadoimage']..'|'..row['Resultadotext']..'|'..row['amount']..'|'..row['version']
-- grouping result col
+
-- grouping Resultado col
if current_result == result then -- is same group ??
+
if current_Resultado == Resultado then -- is same group ??
result_count = result_count + 1
+
Resultado_count = Resultado_count + 1
 
else
 
else
 
--new group:
 
--new group:
 
-- rowspan value for prev group, if needed.
 
-- rowspan value for prev group, if needed.
if result_count then
+
if Resultado_count then
str = str:gsub("yyyrowspanyyy", tostring(result_count))
+
str = str:gsub("yyyrowspanyyy", tostring(Resultado_count))
 
end
 
end
 
-- begin this group
 
-- begin this group
  +
current_Resultado = Resultado
current_result = result
 
result_count = 1
+
Resultado_count = 1
str_resultCell = '<td class="result" rowspan="yyyrowspanyyy">'.. resultCell(row, showResultId, needLink).. '</td>'
+
str_ResultadoCell = '<td class="Resultado" rowspan="yyyrowspanyyy">'.. ResultadoCell(row, showResultadoId, needLink).. '</td>'
 
end
 
end
 
-- grouping ext cols
 
-- grouping ext cols
if result_index and (current_result_ext == result_index) then -- is same group ??
+
if Resultado_index and (current_Resultado_ext == Resultado_index) then -- is same group ??
result_ext_count = result_ext_count + 1
+
Resultado_ext_count = Resultado_ext_count + 1
 
else
 
else
 
--new group:
 
--new group:
 
-- rowspan value for prev group, if needed.
 
-- rowspan value for prev group, if needed.
if result_ext_count then
+
if Resultado_ext_count then
str = str:gsub("zzzrowspanzzz", tostring(result_ext_count))
+
str = str:gsub("zzzrowspanzzz", tostring(Resultado_ext_count))
 
end
 
end
 
-- begin this group
 
-- begin this group
  +
current_Resultado_ext = Resultado_index
current_result_ext = result_index
 
result_ext_count = 1
+
Resultado_ext_count = 1
 
if extCols_A then
 
if extCols_A then
 
for _, v in ipairs(extCols_A) do
 
for _, v in ipairs(extCols_A) do
if result_index then
+
if Resultado_index then
str_w = str_w .. '<td rowspan="zzzrowspanzzz">' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_w = str_w .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_w = str_w .. '<td rowspan="zzzrowspanzzz"></td>'
 
str_w = str_w .. '<td rowspan="zzzrowspanzzz"></td>'
Linha 657: Linha 657:
 
if extCols_B then
 
if extCols_B then
 
for _, v in ipairs(extCols_B) do
 
for _, v in ipairs(extCols_B) do
if result_index then
+
if Resultado_index then
str_x = str_x .. '<td rowspan="zzzrowspanzzz">' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_x = str_x .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_x = str_x .. '<td rowspan="zzzrowspanzzz"></td>'
 
str_x = str_x .. '<td rowspan="zzzrowspanzzz"></td>'
Linha 666: Linha 666:
 
if extCols_C then
 
if extCols_C then
 
for _, v in ipairs(extCols_C) do
 
for _, v in ipairs(extCols_C) do
if result_index then
+
if Resultado_index then
str_y = str_y .. '<td rowspan="zzzrowspanzzz">' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_y = str_y .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_y = str_y .. '<td rowspan="zzzrowspanzzz"></td>'
 
str_y = str_y .. '<td rowspan="zzzrowspanzzz"></td>'
Linha 675: Linha 675:
 
if extCols_D then
 
if extCols_D then
 
for _, v in ipairs(extCols_D) do
 
for _, v in ipairs(extCols_D) do
if result_index then
+
if Resultado_index then
str_z = str_z .. '<td rowspan="zzzrowspanzzz">' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_z = str_z .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_z = str_z .. '<td rowspan="zzzrowspanzzz"></td>'
 
str_z = str_z .. '<td rowspan="zzzrowspanzzz"></td>'
Linha 686: Linha 686:
 
if extCols_A then
 
if extCols_A then
 
for _, v in ipairs(extCols_A) do
 
for _, v in ipairs(extCols_A) do
if result_index then
+
if Resultado_index then
str_w = str_w .. '<td>' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_w = str_w .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_w = str_w .. '<td></td>'
 
str_w = str_w .. '<td></td>'
Linha 695: Linha 695:
 
if extCols_B then
 
if extCols_B then
 
for _, v in ipairs(extCols_B) do
 
for _, v in ipairs(extCols_B) do
if result_index then
+
if Resultado_index then
str_x = str_x .. '<td>' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_x = str_x .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_x = str_x .. '<td></td>'
 
str_x = str_x .. '<td></td>'
Linha 704: Linha 704:
 
if extCols_C then
 
if extCols_C then
 
for _, v in ipairs(extCols_C) do
 
for _, v in ipairs(extCols_C) do
if result_index then
+
if Resultado_index then
str_y = str_y .. '<td>' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_y = str_y .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_y = str_y .. '<td></td>'
 
str_y = str_y .. '<td></td>'
Linha 713: Linha 713:
 
if extCols_D then
 
if extCols_D then
 
for _, v in ipairs(extCols_D) do
 
for _, v in ipairs(extCols_D) do
if result_index then
+
if Resultado_index then
str_z = str_z .. '<td>' .. (getArg(result_index .. '-row-' .. v) or '') .. '</td>'
+
str_z = str_z .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
 
else
 
else
 
str_z = str_z .. '<td></td>'
 
str_z = str_z .. '<td></td>'
Linha 720: Linha 720:
 
end
 
end
 
end
 
end
str_resultCell = '<td class="result">'.. resultCell(row, showResultId, needLink).. '</td>'
+
str_ResultadoCell = '<td class="Resultado">'.. ResultadoCell(row, showResultadoId, needLink).. '</td>'
 
end
 
end
   
str = str .. str_w .. str_resultCell .. str_x .. '<td class="Ingredientes">' .. IngredientesCell(row['args']).. '</td>' .. str_y
+
str = str .. str_w .. str_ResultadoCell .. str_x .. '<td class="Ingredientes">' .. IngredientesCell(row['args']).. '</td>' .. str_y
   
 
if withStation then
 
if withStation then
Linha 764: Linha 764:
   
 
str = str .. str_z ..'</tr>'
 
str = str .. str_z ..'</tr>'
return str, current_station, station_count, current_result, result_count, current_result_ext, result_ext_count
+
return str, current_station, station_count, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count
 
end
 
end
   
Linha 796: Linha 796:
 
end
 
end
 
end
 
end
temp = getArg(p..'col-result')
+
temp = getArg(p..'col-Resultado')
 
if temp then
 
if temp then
 
valid = true
 
valid = true
str = str .. '<td class="result">' .. temp .. '</td>'
+
str = str .. '<td class="Resultado">' .. temp .. '</td>'
 
else
 
else
str = str .. '<td class="result"></td>'
+
str = str .. '<td class="Resultado"></td>'
 
end
 
end
 
if extCols_B then
 
if extCols_B then
Linha 887: Linha 887:
   
   
local tableBody = function(result, showResultId, withStation, needGroup, needCate, needLink, rootpagename, title, expectedrows)
+
local tableBody = function(Resultado, showResultadoId, withStation, needGroup, needCate, needLink, rootpagename, title, expectedrows)
 
local str = tableStart(title, withStation)
 
local str = tableStart(title, withStation)
 
-- top ext rows:
 
-- top ext rows:
Linha 895: Linha 895:
 
local station_count
 
local station_count
 
local rows_count = 0
 
local rows_count = 0
local current_result
+
local current_Resultado
local result_count
+
local Resultado_count
local current_result_ext
+
local current_Resultado_ext
local result_ext_count
+
local Resultado_ext_count
for _, row in ipairs(result) do
+
for _, row in ipairs(Resultado) do
 
rows_count = rows_count + 1
 
rows_count = rows_count + 1
 
-- table row:
 
-- table row:
str, current_station, station_count, current_result, result_count, current_result_ext, result_ext_count = tableRow(str, row, current_station, station_count, rows_count, showResultId, withStation, needCate, needLink, needGroup, current_result, result_count, current_result_ext, result_ext_count)
+
str, current_station, station_count, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count = tableRow(str, row, current_station, station_count, rows_count, showResultadoId, withStation, needCate, needLink, needGroup, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count)
 
-- cate:
 
-- cate:
 
if needCate then
 
if needCate then
if needCate == 2 or rootpagename == row['result'] then
+
if needCate == 2 or rootpagename == row['Resultado'] then
 
addCate(row['station'])
 
addCate(row['station'])
 
end
 
end
 
end
 
end
 
end
 
end
-- rowspan value for last station group and result group
+
-- rowspan value for last station group and Resultado group
 
if station_count then
 
if station_count then
 
str = str:gsub("xxxrowspanxxx", tostring(station_count))
 
str = str:gsub("xxxrowspanxxx", tostring(station_count))
 
end
 
end
 
if needGroup then
 
if needGroup then
str = str:gsub("yyyrowspanyyy", tostring(result_count))
+
str = str:gsub("yyyrowspanyyy", tostring(Resultado_count))
str = str:gsub("zzzrowspanzzz", tostring(result_ext_count))
+
str = str:gsub("zzzrowspanzzz", tostring(Resultado_ext_count))
 
end
 
end
 
-- ext rows:
 
-- ext rows:
Linha 970: Linha 970:
 
--store
 
--store
 
frame:callParserFunction('#cargo_store:_table=Recipes',{
 
frame:callParserFunction('#cargo_store:_table=Recipes',{
result = trim(args['result'] or ''),
+
Resultado = trim(args['Resultado'] or ''),
resultid = trim(args['resultid'] or ''),
+
Resultadoid = trim(args['Resultadoid'] or ''),
resultimage = trim(args['image'] or ''),
+
Resultadoimage = trim(args['image'] or ''),
resulttext = trim(args['text'] or ''),
+
Resultadotext = trim(args['text'] or ''),
 
amount = trim(args['amount'] or ''),
 
amount = trim(args['amount'] or ''),
 
version = version,
 
version = version,
Linha 996: Linha 996:
 
end
 
end
   
-- no constraint no result.
+
-- no constraint no Resultado.
 
if where == '' then
 
if where == '' then
 
return '<span style="color:red;font-weight:bold;">Recipes: No constraint</span>'
 
return '<span style="color:red;font-weight:bold;">Recipes: No constraint</span>'
Linha 1 007: Linha 1 007:
 
needGroup = false
 
needGroup = false
 
end
 
end
local showResultId = false
+
local showResultadoId = false
if trim(args['showresultid'] or '') ~= '' then
+
if trim(args['showResultadoid'] or '') ~= '' then
showResultId = true
+
showResultadoId = true
 
end
 
end
 
local _title = trim(args['title'] or '')
 
local _title = trim(args['title'] or '')
Linha 1 023: Linha 1 023:
 
-- no station
 
-- no station
 
-- query, still need contain station field for cate.
 
-- query, still need contain station field for cate.
local result = mw.ext.cargo.query('Recipes', 'result, resultid, resultimage, resulttext, amount, version, station, args', {
+
local Resultado = mw.ext.cargo.query('Recipes', 'Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version, station, args', {
 
where = where,
 
where = where,
groupBy = "resultid, result, amount, version, ings",
+
groupBy = "Resultadoid, Resultado, amount, version, ings",
orderBy = "result, amount DESC, version", -- Don't order by station
+
orderBy = "Resultado, amount DESC, version", -- Don't order by station
 
limit = 2000,
 
limit = 2000,
 
})
 
})
return tableBody(result, showResultId, false, needGroup, needCate, needLink, rootpagename, _title, _expectedrows)
+
return tableBody(Resultado, showResultadoId, false, needGroup, needCate, needLink, rootpagename, _title, _expectedrows)
 
else
 
else
 
-- with station
 
-- with station
 
-- query
 
-- query
local result = mw.ext.cargo.query('Recipes', 'result, resultid, resultimage, resulttext, amount, version, station, args', {
+
local Resultado = mw.ext.cargo.query('Recipes', 'Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version, station, args', {
 
where = where,
 
where = where,
groupBy = "resultid, result, amount, ings, version",
+
groupBy = "Resultadoid, Resultado, amount, ings, version",
orderBy = "station, result, amount DESC, version, ings", -- order by station first for station grouping.
+
orderBy = "station, Resultado, amount DESC, version, ings", -- order by station first for station grouping.
 
limit = 2000,
 
limit = 2000,
 
})
 
})
return tableBody(result, showResultId, true, needGroup, needCate, needLink, rootpagename, _title, _expectedrows)
+
return tableBody(Resultado, showResultadoId, true, needGroup, needCate, needLink, rootpagename, _title, _expectedrows)
 
end
 
end
 
end -- p.query
 
end -- p.query
Linha 1 057: Linha 1 057:
 
end
 
end
   
-- no constraint no result.
+
-- no constraint no Resultado.
 
if where == '' then
 
if where == '' then
 
return '<span style="color:red;font-weight:bold;">Recipes/extract: No constraint</span>'
 
return '<span style="color:red;font-weight:bold;">Recipes/extract: No constraint</span>'
Linha 1 063: Linha 1 063:
   
 
-- query:
 
-- query:
local result = mw.ext.cargo.query('Recipes', 'result, resultid, resultimage, resulttext, amount, version, station, args', {
+
local Resultado = mw.ext.cargo.query('Recipes', 'Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version, station, args', {
 
where = where,
 
where = where,
groupBy = "resultid, result, amount, version, ings",
+
groupBy = "Resultadoid, Resultado, amount, version, ings",
orderBy = "result, amount DESC, version", -- Don't order by station
+
orderBy = "Resultado, amount DESC, version", -- Don't order by station
 
limit = 20, -- enough.
 
limit = 20, -- enough.
 
})
 
})
Linha 1 076: Linha 1 076:
 
--default mode = Ingredientes
 
--default mode = Ingredientes
 
local sep = sep or "<br/>'''or'''<br/>"
 
local sep = sep or "<br/>'''or'''<br/>"
local withResult = getArg('withresult')
+
local withResultado = getArg('withResultado')
 
local withStation = not getArg('nostation')
 
local withStation = not getArg('nostation')
 
local withVersion = not getArg('noversion')
 
local withVersion = not getArg('noversion')
 
local str = nil
 
local str = nil
for _, row in ipairs(result) do
+
for _, row in ipairs(Resultado) do
 
if str then
 
if str then
 
str = str .. sep
 
str = str .. sep
Linha 1 116: Linha 1 116:
 
str = str .. compactStation(row['station'])
 
str = str .. compactStation(row['station'])
 
end
 
end
if withResult then
+
if withResultado then
 
str = str .. ' = '
 
str = str .. ' = '
 
if row['amount'] ~= '1' then
 
if row['amount'] ~= '1' then
Linha 1 122: Linha 1 122:
 
end
 
end
 
local args = {mode='image'}
 
local args = {mode='image'}
if row['resultimage'] then
+
if row['Resultadoimage'] then
args['image'] = row['resultimage']
+
args['image'] = row['Resultadoimage']
 
end
 
end
str = str .. itemLink(row['result'], args)
+
str = str .. itemLink(row['Resultado'], args)
 
end
 
end
 
str = str..'</span>'
 
str = str..'</span>'
Linha 1 133: Linha 1 133:
 
local sep = sep or "'''or'''"
 
local sep = sep or "'''or'''"
 
local str = nil
 
local str = nil
for _, row in ipairs(result) do
+
for _, row in ipairs(Resultado) do
 
if str then
 
if str then
 
str = str .. sep
 
str = str .. sep
Linha 1 144: Linha 1 144:
 
elseif mode == 'station' then
 
elseif mode == 'station' then
 
-- only return first row.
 
-- only return first row.
for _, row in ipairs(result) do
+
for _, row in ipairs(Resultado) do
 
return stationCell(row['station'], {})
 
return stationCell(row['station'], {})
 
end
 
end
elseif mode == 'result' then
+
elseif mode == 'Resultado' then
 
-- only return first row.
 
-- only return first row.
 
local needCate, needLink = getFlags(args)
 
local needCate, needLink = getFlags(args)
for _, row in ipairs(result) do
+
for _, row in ipairs(Resultado) do
return resultCell(row, getArg('showresultid'), needLink, true)
+
return ResultadoCell(row, getArg('showResultadoid'), needLink, true)
 
end
 
end
 
else
 
else

Revisão das 18h49min de 14 de junho de 2019

This module provides the functionality of Template:Recipes. See that template's page for documentation.


local l10n_auto_translate_eicons_pagename = {
	['zh'] = true,
}

local item_link = require('Module:Item').go
local trim = mw.text.trim
local cargo = mw.ext.cargo

local currentFrame -- global cache for current frame object.
local inputArgs -- global args cache.
local lang -- cache current lang.

local extCols_stationBefore = nil
local extCols_stationAfter = nil

local extCols_A = nil
local extCols_B = nil
local extCols_C = nil
local extCols_D = nil

function getArg(key)
	local v = trim(inputArgs[key] or '')
	if v=='' then
		return nil
	else
		return v
	end
end

local itemLink = function(name, args)
	local args = args or {}
	args[1] = name
	args[2] = currentFrame:expandTemplate{ title = 'tr', args = {name, lang=lang} }
	args['eicons'] = l10n_auto_translate_eicons_pagename[lang]
	args['small'] = 'y'
	args['lang'] = lang or 'en'
	args['nolink'] = args['nolink'] and 'y' or nil
	return item_link(currentFrame, args)
end

-- credit: http://richard.warburton.it
-- this version is with trim.
local explode = function(div,str)
	if (div=='') then return false end
	local pos,arr = 0,{}
	-- for each divider found
	for st,sp in function() return string.find(str,div,pos,true) end do
		table.insert(arr, trim(string.sub(str,pos,st-1))) -- Attach chars left of current divider
		pos = sp + 1 -- Jump past current divider
	end
	table.insert(arr, trim(string.sub(str,pos))) -- Attach chars right of last divider
	return arr
end

-- retuan a array of itemname, split xxx/yyy to item1=xxx, item2=yyy. If it's something like "Lead/Iron Bar", it will normalize as item1 = Iron Bar, item2 = Lead Bar.
local split = (function()
	local metals = {
		['Copper/Tin'] = 1,
		['Silver/Tungsten'] = 1,
		['Gold/Platinum'] = 1,
		['Iron/Lead'] = 1,
		['Cobalt/Palladium'] = 1,
		['Mythril/Orichalcum'] = 1,
		['Adamantite/Titanium'] = 1,
		['Tin/Copper'] = 2,
		['Tungsten/Silver'] = 2,
		['Platinum/Gold'] = 2,
		['Lead/Iron'] = 2,
		['Palladium/Cobalt'] = 2,
		['Orichalcum/Mythril'] = 2,
		['Titanium/Adamantite'] = 2,
	}
	return function(name)
		local count = select(2, name:gsub("/", "/", 2))
		if count == 0 then
			-- only 1 item
			return { trim(name) }
		elseif count == 1 then
			-- 2 items
			local item1a, item1b, item2a, item2b = name:match("^%s*(%S+)%s*(.-)/%s*(%S+)%s*(.-)$")
			local x = metals[item1a..'/'..item2a]
			if tostring(item1b) == '' and x then
				item1b = item2b
			end
			if x == 2 then
				return {trim(item2a..' '..item2b), trim(item1a..' '..item1b)}
			else
				return {trim(item1a..' '..item1b), trim(item2a..' '..item2b)}
			end
		else
			-- 3 or more items
			return explode('/', name)
		end
	end
end)()

-- return 1 or 2 value(s), when input is name[note], return item, note.
local itemname = function(str)
		local item, note = str:match("^(.-)(%b[])$")
		if item then
			return item, note
		else
			return str
		end
end

-- normalize ingredient name input, Lead Bar=>¦Lead Bar¦, Iron/Lead Bar => ¦Iron Bar¦Lead Bar¦, Lead/Iron Bar => ¦Iron Bar¦Lead Bar¦ ....
local normalize = function(name)
	local Resultado = '¦'
	for k, v in ipairs(split(name)) do
		Resultado = Resultado .. itemname(v) .. '¦'
	end
	return Resultado
end

local escape = function(str)
	return str:gsub("'", "\\'"):gsub("&#39;", "\\'")
end
local enclose = function(str)
	return "'" .. escape(str) .. "'"
end

local getItemGroupName = function(item)
	if item == 'Wood' or item == 'Ebonwood' or item == 'Rich Mahogany' or item == 'Pearlwood' or item == 'Shadewood'
	or item == 'Spooky Wood' or item == 'Boreal Wood' or item == 'Palm Wood' then
		return 'Any Wood'
	elseif item == 'Iron Bar' or item == 'Lead Bar' then
		return 'Any Iron Bar'
	elseif item == 'Sand Block' or item == 'Pearlsand Block' or item == 'Crimsand Block' or item == 'Ebonsand Block' or item == 'Hardened Sand Block' then
		return 'Any Sand'
	elseif item == 'Red Pressure Plate' or item == 'Green Pressure Plate' or item == 'Gray Pressure Plate' or item == 'Brown Pressure Plate'
	    or item == 'Blue Pressure Plate' or item == 'Yellow Pressure Plate' or item == 'Lihzahrd Pressure Plate' then
		return 'Any Pressure Plate'
	elseif item == 'Bird' or item == 'Blue Jay' or item == 'Cardinal' then
		return 'Any Bird'
	elseif item == 'Black Scorpion' or item == 'Scorpion' then
		return 'Any Scorpion'
	elseif item == 'Squirrel' or item == 'Red Squirrel' then
		return 'Any Squirrel'
	elseif item == 'Grubby' or item == 'Sluggy' or item == 'Buggy' then
		return 'Any Bug'
	elseif item == 'Mallard Duck' or item == 'Duck' then
		return 'Any Duck'
	elseif item == 'Sulphur Butterfly' or item == 'Julia Butterfly' or item == 'Monarch Butterfly' or item == 'Purple Emperor Butterfly'
	    or item == 'Red Admiral Butterfly' or item == 'Tree Nymph Butterfly' or item == 'Ulysses Butterfly' or item == 'Zebra Swallowtail Butterfly' then
		return 'Any Butterfly'
	elseif item == 'Firefly' or item == 'Lightning Bug' then
		return 'Any Firefly'
	elseif item == 'Snail' or item == 'Glowing Snail' then
		return 'Any Snail'
	end
end

local normalizeStation = function(station)
	if station == 'Altar' then
		station = 'Demon Altar'
	end
	return station
end

local normalizeVersion = function(_version)
	local _version = trim(_version):lower()
	local version = ''
	if _version:find('desktop', 1, true) then
		version = version .. ' desktop'
	end
	if _version:find('console', 1, true) then
		version = version .. ' console'
	end
	if _version:find('old-gen', 1, true) then
		version = version .. ' old-gen'
	end
	if _version:find('japan', 1, true) then
		version = version .. ' japan'
	end
	if _version:find('mobile', 1, true) then
		version = version .. ' mobile'
	end
	if _version:find('3ds', 1, true) then
		version = version .. ' 3ds'
	end
	if version == ' desktop console old-gen mobile 3ds' then
		version = ''
	end
	return trim(version)
end

local criStr = function(args)
	local constraints = {}
	-- station = ? and station != ?
	local _station = trim(args['station'] or '')
	local _stationnot = trim(args['stationnot'] or '')
	local str = ''
	if _station ~= '' then
		for _, v in ipairs(explode('/', _station)) do
			if str ~= '' then
				str = str .. ' OR '
			end
			str = str .. "station = " .. enclose(normalizeStation(v))
		end
	end
	if _stationnot ~= '' then
		if str ~= '' then
			str = '(' .. str .. ')'
		end
		for _, v in ipairs(explode('/', _stationnot)) do
			if str ~= '' then
				str = str .. ' AND '
			end
			str = str .. 'station <> ' .. enclose(normalizeStation(v))
		end
	end
	constraints['station'] = str
	-- Resultado = ? and Resultado != ?
	local _Resultado = trim(args['Resultado'] or '')
	local _Resultadonot = trim(args['Resultadonot'] or '')
	local str = ''
	if _Resultado ~= '' then
		for _, v in ipairs(explode('/', _Resultado)) do
			if str ~= '' then
				str = str .. ' OR '
			end
			if mw.ustring.sub(v, 1, 5) == 'LIKE ' then
				str = str .. "Resultado LIKE " .. enclose(trim(mw.ustring.sub(v, 6)))
			else
				str = str .. 'Resultado=' .. enclose(v)
			end
		end
	end
	if _Resultadonot ~= '' then
		if str ~= '' then
			str = '(' .. str .. ')'
		end
		for _, v in ipairs(explode('/', _Resultadonot)) do
			if str ~= '' then
				str = str .. ' AND '
			end
			if mw.ustring.sub(v, 1, 5) == 'LIKE ' then
				str = str .. "Resultado NOT LIKE " .. enclose(trim(mw.ustring.sub(v, 6)))
			else
				str = str .. 'Resultado <> ' .. enclose(v)
			end
		end
	end
	if str ~= '' then
		constraints['Resultado'] = str
	end
	-- ingredient = ?
	local _ingredient = trim(args['ingredient'] or '')
	if _ingredient ~= '' then
		local str = ''
		for _, v in ipairs(explode('/', _ingredient)) do
			if str ~= '' then
				str = str .. ' OR '
			end
			if mw.ustring.sub(v, 1, 1) == '#' then
				str = str .. "Ingredientes HOLDS LIKE '%¦" .. escape(mw.ustring.sub(v, 2)) .. "¦%'"
			elseif mw.ustring.sub(v, 1, 5) == 'LIKE ' then
				str = str .. "Ingredientes HOLDS LIKE '%¦" .. escape(trim(mw.ustring.sub(v, 6))) .. "¦%'"
			else
				str = str .. "Ingredientes HOLDS LIKE '%¦" .. escape(v) .. "¦%'"
				-- any xxx
				local group = getItemGroupName(v)
				if group then
					str = str .. " OR Ingredientes HOLDS LIKE '%¦" .. escape(group) .. "¦%'"
				end
			end
		end
		constraints['ingredient'] = str
	end

	--versions
	local _version = normalizeVersion(args['version'] or args['versions'] or '')
	if _version ~= '' then
		constraints['version'] = 'version = '..enclose(_version)
	end

	local where = ''
	if constraints['station'] then
		where = constraints['station']
	end
	if constraints['Resultado'] then
		if where ~= '' then
			where = where .. ' AND '
		end
		where = where .. '(' .. constraints['Resultado'] .. ')'
	end
	if constraints['ingredient'] then
		if where ~= '' then
			where = where .. ' AND '
		end
		where = where .. '(' .. constraints['ingredient'] .. ')'
	end
	if constraints['version'] then
		if where ~= '' then
			where = where .. ' AND '
		end
		where = where .. '(' .. constraints['version'] .. ')'
	end
	return where
end

local ResultadoCell = function(row, showResultadoId, needLink, noVersion)
	local Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version = row['Resultado'], row['Resultadoid'], row['Resultadoimage'], row['Resultadotext'], row['amount'], row['version']
	local str = ''
	local args = {anchor = 'y', nolink = not needLink, class='multi-line'}
	if showResultadoId then
		args['id'] = Resultadoid
	end
	if Resultadoimage then
		args['image'] = Resultadoimage
	end
	if Resultadotext then
		args[2] = Resultadotext
	end
	str = str .. itemLink(Resultado, args)
	if amount ~= '1' then
		str = str .. ' <span class="note-text">('..amount..')</span>'
	end
	if not noVersion then
		if version ~= '' then
			str = str .. ' (' ..currentFrame:expandTemplate{ title = 'version icons', args = {version} }..')'
		end
	end
	return str
end

local IngredientesCell = function(args)
	local str = '<ul>'
	for _, v in ipairs(explode('^', args)) do
		str = str .. '<li>'
		local item, amount = v:match('^(.-)¦(.-)$')
		local s
		for _, itemname in ipairs(split(item)) do
			if s then
				s = s .. " ''or'' " .. itemLink(itemname)
			else
				s = itemLink(itemname)
			end
		end
		str = str .. s
		if amount ~= '1' then
			str = str .. ' <span class="note-text">('..amount..')</span>'
		end
		str = str .. '</li>'
	end
	str = str .. '</ul>'
	return str
end

local stationCell = function(station, options)
	options = options or {wrap = 'y'}
	if station == 'By Hand' then
		return '[[By Hand]]'
	elseif station == 'Furnace' or station == 'Work Bench' or station == 'Sawmill' or station == "Tinkerer's Workshop" or station == 'Dye Vat'
	  or station == 'Loom' or station == 'Keg' or station == 'Hellforge' or station == 'Bookcase' or station == 'Imbuing Station' or station == 'Lava'
	  or station == 'Honey' or station == 'Glass Kiln' or station == 'Flesh Cloning Vat' or station == 'Autohammer' or station == 'Crystal Ball'
	  or station == 'Ice Machine' or station == 'Meat Grinder' or station == 'Living Loom' or station == 'Heavy Work Bench' or station == 'Sky Mill'
	  or station == 'Solidifier' or station == 'Honey Dispenser' or station == 'Bone Welder' or station == 'Blend-O-Matic' or station == 'Steampunk Boiler'
	  or station == 'Ancient Manipulator' or station == 'Lihzahrd Furnace' or station == 'Living Wood' then
		return itemLink(station, options)
	elseif station == 'Iron Anvil' then
		return itemLink('Iron Anvil', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Lead Anvil', options)
	elseif station == 'Adamantite Forge' then
		return itemLink('Adamantite Forge', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Titanium Forge', options)
	elseif station == 'Mythril Anvil' then
		return itemLink('Mythril Anvil', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Orichalcum Anvil', options)
	elseif station == 'Demon Altar' then
		return itemLink('Demon Altar', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Crimson Altar', options)
	elseif station == 'Cooking Pot' then
		return itemLink('Cooking Pot', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Cauldron', options)
	elseif station == 'Placed Bottle' then
		return itemLink('Placed Bottle', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Alchemy Table', options)
	elseif station == 'Water' then
		return itemLink('Water', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Sink', options)
	elseif station == 'Table and Chair' then
		return itemLink('Table', options) .. " '''and''' " .. itemLink('Chair', options)
	elseif station == 'Work Bench and Chair' then
		return itemLink('Work Bench', options) .. " '''and''' " .. itemLink('Chair', options)
	elseif station == 'Crystal Ball and Lava' then
		return itemLink('Crystal Ball', options) .. " '''and''' " .. itemLink('Lava', options)
	elseif station == 'Crystal Ball and Honey' then
		return itemLink('Crystal Ball', options) .. " '''and''' " .. itemLink('Honey', options)
	elseif station == 'Crystal Ball and Water' then
		return itemLink('Crystal Ball', options) .. " '''and''' ".. '<span class="water">' .. itemLink('Water', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Sink', options) .. '</span>'
	elseif station == 'Sky Mill and Water' then
		return itemLink('Sky Mill', options) .. " '''and''' ".. '<span  class="water">' .. itemLink('Water', options) .. "<br/>'''''or'''''<br/>" .. itemLink('Sink', options) .. '</span>'
	elseif station == 'Sky Mill and Snow Biome' then
		return itemLink('Sky Mill', options) .. " '''and''' ".. '[[Snow biome]]'
	elseif station == 'Placed Bottle only' then
		return itemLink('Placed Bottle', options)
	else
		return station
	end
end
-- for extract.
local compactStation = function(station)
	if station == 'By Hand' then
		return ''
	elseif station == 'Furnace' or station == 'Work Bench' or station == 'Sawmill' or station == "Tinkerer's Workshop" or station == 'Dye Vat'
	  or station == 'Loom' or station == 'Keg' or station == 'Hellforge' or station == 'Bookcase' or station == 'Imbuing Station' or station == 'Lava'
	  or station == 'Honey' or station == 'Glass Kiln' or station == 'Flesh Cloning Vat' or station == 'Autohammer' or station == 'Crystal Ball'
	  or station == 'Ice Machine' or station == 'Meat Grinder' or station == 'Living Loom' or station == 'Heavy Work Bench' or station == 'Sky Mill'
	  or station == 'Solidifier' or station == 'Honey Dispenser' or station == 'Bone Welder' or station == 'Blend-O-Matic' or station == 'Steampunk Boiler'
	  or station == 'Ancient Manipulator' or station == 'Lihzahrd Furnace' or station == 'Living Wood' then
		return ' @&thinsp;' .. itemLink(station, {mode = 'image'})
	elseif station == 'Iron Anvil' then
		return ' @&thinsp;' .. itemLink('Iron Anvil', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Lead Anvil', {mode = 'image'})
	elseif station == 'Adamantite Forge' then
		return ' @&thinsp;' .. itemLink('Adamantite Forge', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Titanium Forge', {mode = 'image'})
	elseif station == 'Mythril Anvil' then
		return ' @&thinsp;' .. itemLink('Mythril Anvil', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Orichalcum Anvil', {mode = 'image'})
	elseif station == 'Demon Altar' then
		return ' @&thinsp;' .. itemLink('Demon Altar', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Crimson Altar', {mode = 'image'})
	elseif station == 'Cooking Pot' then
		return ' @&thinsp;' .. itemLink('Cooking Pot', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Cauldron', {mode = 'image'})
	elseif station == 'Placed Bottle' then
		return ' @&thinsp;' .. itemLink('Placed Bottle', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Alchemy Table', {mode = 'image'})
	elseif station == 'Water' then
		return ' @&thinsp;' .. itemLink('Water', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Sink', {mode = 'image'})
	elseif station == 'Table and Chair' then
		return ' @&thinsp;' .. itemLink('Table', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;" .. itemLink('Chair', {mode = 'image'})
	elseif station == 'Work Bench and Chair' then
		return ' @&thinsp;' .. itemLink('Work Bench', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;" .. itemLink('Chair', {mode = 'image'})
	elseif station == 'Crystal Ball and Lava' then
		return ' @&thinsp;' .. itemLink('Crystal Ball', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;" .. itemLink('Lava', {mode = 'image'})
	elseif station == 'Crystal Ball and Honey' then
		return ' @&thinsp;' .. itemLink('Crystal Ball', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;" .. itemLink('Honey', {mode = 'image'})
	elseif station == 'Crystal Ball and Water' then
		return ' @&thinsp;' .. itemLink('Crystal Ball', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;".. '(&thinsp;' .. itemLink('Water', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Sink', {mode = 'image'}) .. '&thinsp;)'
	elseif station == 'Sky Mill and Water' then
		return ' @&thinsp;' .. itemLink('Sky Mill', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;".. '(&thinsp;' .. itemLink('Water', {mode = 'image'}) .. "&thinsp;/&thinsp;" .. itemLink('Sink', {mode = 'image'}) .. '&thinsp;)'
	elseif station == 'Sky Mill and Snow Biome' then
		return ' @&thinsp;' .. itemLink('Sky Mill', {mode = 'image'}) .. "&thinsp;&amp;&thinsp;".. '[[Snow biome|Snow]]'
	elseif station == 'Placed Bottle only' then
		return ' @&thinsp;' .. itemLink('Placed Bottle', {mode = 'image'})
	else
		return ' @&thinsp;' .. station
	end
end

local getFlags = function(args)
	local needCate = 1
	local needLink = true
	local _cate = trim(args['cate'] or '')
	if _cate == 'force' or _cate == 'all' then
		needCate = 2
	elseif _cate == 'n' or _cate == 'no' then
		needCate = nil
	end
	local _link = trim(args['link'] or '')
	if _link == 'y' or _link == 'yes' or _link == 'force' then
		needLink = true
	elseif _link == 'n' or _link == 'no' then
		needLink = false
	end
	return needCate, needLink
end


local addCate, cateStr = (function()
	local cate = {
		['Lead Anvil'] = 'Iron or Lead Anvil',
		['Iron Anvil'] = 'Iron or Lead Anvil',
		['Orichalcum Anvil'] = 'Mythril or Orichalcum Anvil',
		['Mythril Anvil'] = 'Mythril or Orichalcum Anvil',
		['Demon Altar'] =  'Demon or Crimson Altar',
		['Crimson Altar'] = 'Demon or Crimson Altar',
		['Altar'] = 'Demon or Crimson Altar',
		['Titanium Forge'] = 'Adamantite or Titanium Forge',
		['Adamantite Forge'] = 'Adamantite or Titanium Forge',
		['Cauldron'] = 'Cooking Pot or Cauldron',
		['Cooking Pot'] = 'Cooking Pot or Cauldron',
		['Bottle only'] = 'Placed Bottle',
		['Placed Bottle only'] = 'Placed Bottle',
		['Bottle'] = 'Placed Bottle or Alchemy Table',
		['Placed Bottle'] = 'Placed Bottle or Alchemy Table',
		['Alchemy Table'] = 'Placed Bottle or Alchemy Table',
		['Water'] = 'Water or Sink',
		['Sink'] = 'Water or Sink',
		['Crystal Ball and Water'] = 'Crystal Ball and Water or Sink',
		['Sky Mill and Water'] = 'Sky Mill and Water or Sink',
	}
	local cateCache = {}
	local addCate = function(station)
		cateCache[station] = true
	end
	local cateStr = function()
		local str = ''
		for station, _ in pairs(cateCache) do
			str = str .. '[[Category:'..(cate[station] or station)..']]'
		end
		if str ~= '' then
			str = '[[Category:Craftable items]]' .. str
		end
		return str
	end
	return addCate, cateStr
end)()

local tableStart = function(title, withStation)
	local header_
	local str = '<div class="crafts '.. (getArg('class') or '')
	local _id = (getArg('id') or '')
	if _id ~= '' then
		str = str .. '" id="'.. _id
	end
	local _css = (getArg('css') or getArg('style') or '')
	if _css ~= '' then
		str = str .. '" style="'.. _css
	end
	str = str .. '"><div class="wrap"><table '
	if (getArg('sortable') or 'y'):sub(1,1) ~= 'n' then
		str = str .. 'class="sortable" '
	end
	str = str .. 'cellpadding="0" cellspacing="0">'
	if title ~= '' then
		str = str .. '<caption>' .. title .. '</caption>'
	end

	local _i, _field
	str = str .. '<tr>'
	_i = 1
	_field = 'col-A-1'
	while getArg(_field) do
		if not extCols_A then
			extCols_A = {}
		end
		table.insert(extCols_A, _field)
		str = str .. '<th>'.. getArg(_field) ..'</th>'
		_i = _i + 1
		_field = 'col-A-' .. _i
	end
	str = str .. '<th class="Resultado">' .. (getArg('header-Resultado') or 'Resultado') .. '</th>'
	_i = 1
	_field = 'col-B-1'
	while getArg(_field) do
		if not extCols_B then
			extCols_B = {}
		end
		table.insert(extCols_B, _field)
		str = str .. '<th>'.. getArg(_field) ..'</th>'
		_i = _i + 1
		_field = 'col-B-' .. _i
	end
	str = str .. '<th class="Ingredientes">' .. (getArg('header-Ingredientes') or 'Ingredientes') .. '</th>'
	_i = 1
	_field = 'col-C-1'
	while getArg(_field) do
		if not extCols_C then
			extCols_C = {}
		end
		table.insert(extCols_C, _field)
		str = str .. '<th>'.. getArg(_field) ..'</th>'
		_i = _i + 1
		_field = 'col-C-' .. _i
	end
	if withStation then
		_i = 1
		_field = 'station-col-before-1'
		while getArg(_field) do
			if not extCols_stationBefore then
				extCols_stationBefore = {}
			end
			table.insert(extCols_stationBefore, _field)
			str = str .. '<th class="station">'.. getArg(_field) ..'</th>'
			_i = _i + 1
			_field = 'station-col-before-' .. _i
		end
		str = str .. '<th class="station">' .. (getArg('header-station') or '[[Crafting station]]') .. '</th>'
		_i = 1
		_field = 'station-col-after-1'
		while getArg(_field) do
			if not extCols_stationAfter then
				extCols_stationAfter = {}
			end
			table.insert(extCols_stationAfter, _field)
			str = str .. '<th class="station">'.. getArg(_field) ..'</th>'
			_i = _i + 1
			_field = 'station-col-after-' .. _i
		end
	end
	_i = 1
	_field = 'col-D-1'
	while getArg(_field) do
		if not extCols_D then
			extCols_D = {}
		end
		table.insert(extCols_D, _field)
		str = str .. '<th>'.. getArg(_field) ..'</th>'
		_i = _i + 1
		_field = 'col-D-' .. _i
	end
	str = str .. '</tr>'
	return str
end

local tableEnd = function(rows_count, expectedrows)
	local str = '</table><div style="display: none">total: '..rows_count..' row(s)</div></div></div>'
	if expectedrows and rows_count ~= expectedrows then
		str = str .. '[[Category:Recipes table with unexcepted total number of rows]]'
	end
	if not expectedrows and rows_count == 0 then
		str = str .. '[[Category:Recipes table with no row]]'
	end
	return str
end

local tableRow = function(str, row, current_station, station_count, rows_count, showResultadoId, withStation, needCate, needLink, needGroup, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count)
	local str_w = '' -- before Resultado col
	local str_x = '' -- between Resultado and Ingredientes cols
	local str_y = '' -- between Ingredientes and station cols
	local str_z = '' -- after station
	local str_ResultadoCell = ''

	local Resultado_index = getArg('Resultado-index-#'..rows_count) or getArg('Resultado-index-'..row['Resultado']..'-'..row['version']) or getArg('Resultado-index-'..row['Resultado'])

	str = str .. '<tr data-rowid="'..tostring(rows_count)..'">'

	if needGroup then
		local Resultado = row['Resultado']..'|'..row['Resultadoid']..'|'..row['Resultadoimage']..'|'..row['Resultadotext']..'|'..row['amount']..'|'..row['version']
		-- grouping Resultado col
		if current_Resultado == Resultado then -- is same group ??
			Resultado_count = Resultado_count + 1
		else
			--new group:
			-- rowspan value for prev group, if needed.
			if Resultado_count then
				str = str:gsub("yyyrowspanyyy", tostring(Resultado_count))
			end
			-- begin this group
			current_Resultado = Resultado
			Resultado_count = 1
			str_ResultadoCell = '<td class="Resultado" rowspan="yyyrowspanyyy">'.. ResultadoCell(row, showResultadoId, needLink).. '</td>'
		end
		-- grouping ext cols
		if Resultado_index and (current_Resultado_ext == Resultado_index) then -- is same group ??
			Resultado_ext_count = Resultado_ext_count + 1
		else
			--new group:
			-- rowspan value for prev group, if needed.
			if Resultado_ext_count then
				str = str:gsub("zzzrowspanzzz", tostring(Resultado_ext_count))
			end
			-- begin this group
			current_Resultado_ext = Resultado_index
			Resultado_ext_count = 1
			if extCols_A then
				for _, v in ipairs(extCols_A) do
					if Resultado_index then
						str_w = str_w .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
					else
						str_w = str_w .. '<td rowspan="zzzrowspanzzz"></td>'
					end
				end
			end
			if extCols_B then
				for _, v in ipairs(extCols_B) do
					if Resultado_index then
						str_x = str_x .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
					else
						str_x = str_x .. '<td rowspan="zzzrowspanzzz"></td>'
					end
				end
			end
			if extCols_C then
				for _, v in ipairs(extCols_C) do
					if Resultado_index then
						str_y = str_y .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
					else
						str_y = str_y .. '<td rowspan="zzzrowspanzzz"></td>'
					end
				end
			end
			if extCols_D then
				for _, v in ipairs(extCols_D) do
					if Resultado_index then
						str_z = str_z .. '<td rowspan="zzzrowspanzzz">' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
					else
						str_z = str_z .. '<td rowspan="zzzrowspanzzz"></td>'
					end
				end
			end
		end
	else
		if extCols_A then
			for _, v in ipairs(extCols_A) do
				if Resultado_index then
					str_w = str_w .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
				else
					str_w = str_w .. '<td></td>'
				end
			end
		end
		if extCols_B then
			for _, v in ipairs(extCols_B) do
				if Resultado_index then
					str_x = str_x .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
				else
					str_x = str_x .. '<td></td>'
				end
			end
		end
		if extCols_C then
			for _, v in ipairs(extCols_C) do
				if Resultado_index then
					str_y = str_y .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
				else
					str_y = str_y .. '<td></td>'
				end
			end
		end
		if extCols_D then
			for _, v in ipairs(extCols_D) do
				if Resultado_index then
					str_z = str_z .. '<td>' .. (getArg(Resultado_index .. '-row-' .. v) or '') .. '</td>'
				else
					str_z = str_z .. '<td></td>'
				end
			end
		end
		str_ResultadoCell = '<td class="Resultado">'.. ResultadoCell(row, showResultadoId, needLink).. '</td>'
	end

	str = str .. str_w .. str_ResultadoCell .. str_x .. '<td class="Ingredientes">' .. IngredientesCell(row['args']).. '</td>' .. str_y

	if withStation then
		local station = row['station']
		if current_station == station then -- is same group ??
			station_count = station_count + 1
		else
			--new group:
			-- rowspan value for prev group, if needed.
			if station_count then
				str = str:gsub("xxxrowspanxxx", tostring(station_count))
			end
			-- begin this group
			current_station = station
			station_count = 1
			local station_index = getArg('station-index-'..station)
			-- station before:
			if extCols_stationBefore then
				for _, v in ipairs(extCols_stationBefore) do
					if station_index then
						str = str .. '<td class="station" rowspan="xxxrowspanxxx">' .. (getArg(station_index .. '-row-' .. v) or '') .. '</td>'
					else
						str = str .. '<td class="station" rowspan="xxxrowspanxxx"></td>'
					end
				end
			end
			str = str .. '<td class="station" rowspan="xxxrowspanxxx">'.. stationCell(station) ..'</td>'
			-- station after:
			if extCols_stationAfter then
				for _, v in ipairs(extCols_stationAfter) do
					if station_index then
						str = str .. '<td class="station" rowspan="xxxrowspanxxx">' .. (getArg(station_index .. '-row-' .. v) or '') .. '</td>'
					else
						str = str .. '<td class="station" rowspan="xxxrowspanxxx"></td>'
					end
				end
			end
		end
	end

	str = str .. str_z ..'</tr>'
	return str, current_station, station_count, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count
end

local extRows = function(withStation, isTop)
	local prefix
	if isTop then
		prefix = 'topextrow-'
	else
		prefix = 'extrow-'
	end
	local returnstr = ''
	local valid = true
	local p
	local str
	local _i = 1
	local temp
	while valid do
		local i = tostring(_i) .. '-'
		p = prefix .. i
		valid = false
		str = '<tr data-'..prefix..'id="'..tostring(_i)..'">'
		if extCols_A then
			for _, v in ipairs(extCols_A) do
				temp = getArg(p..v)
				if temp then
					valid = true
					str = str .. '<td>' .. temp .. '</td>'
				else
					str = str .. '<td></td>'
				end
			end
		end
		temp = getArg(p..'col-Resultado')
		if temp then
			valid = true
			str = str .. '<td class="Resultado">' .. temp .. '</td>'
		else
			str = str .. '<td class="Resultado"></td>'
		end
		if extCols_B then
			for _, v in ipairs(extCols_B) do
				temp = getArg(p..v)
				if temp then
					valid = true
					str = str .. '<td>' .. temp .. '</td>'
				else
					str = str .. '<td></td>'
				end
			end
		end
		temp = getArg(p..'col-Ingredientes')
		if temp then
			valid = true
			str = str .. '<td class="Ingredientes">' .. temp .. '</td>'
		else
			str = str .. '<td class="Ingredientes"></td>'
		end
		if extCols_C then
			for _, v in ipairs(extCols_C) do
				temp = getArg(p..v)
				if temp then
					valid = true
					str = str .. '<td>' .. temp .. '</td>'
				else
					str = str .. '<td></td>'
				end
			end
		end
		if withStation then
			-- station before:
			if extCols_stationBefore then
				for _, v in ipairs(extCols_stationBefore) do
					temp = getArg(p..v)
					if temp then
						valid = true
						str = str .. '<td class="station">' .. temp .. '</td>'
					else
						str = str .. '<td class="station"></td>'
					end
				end
			end
			temp = getArg(p..'col-station')
			if temp then
				valid = true
				str = str .. '<td class="station">' .. temp .. '</td>'
			else
				str = str .. '<td class="station"></td>'
			end
			-- station after:
			if extCols_stationAfter then
				for _, v in ipairs(extCols_stationAfter) do
					temp = getArg(p..v)
					if temp then
						valid = true
						str = str .. '<td class="station">' .. temp .. '</td>'
					else
						str = str .. '<td class="station"></td>'
					end
				end
			end
		end
		if extCols_D then
			for _, v in ipairs(extCols_D) do
				temp = getArg(p..v)
				if temp then
					valid = true
					str = str .. '<td>' .. temp .. '</td>'
				else
					str = str .. '<td></td>'
				end
			end
		end
		str = str .. '</tr>'

		if valid then
			_i = _i + 1
			returnstr = returnstr .. str
		end
	end
	return returnstr
end


local tableBody = function(Resultado, showResultadoId, withStation, needGroup, needCate, needLink, rootpagename, title, expectedrows)
		local str = tableStart(title, withStation)
		-- top ext rows:
		str = str .. extRows(withStation, true)
		-- main rows:
		local current_station
		local station_count
		local rows_count = 0
		local current_Resultado
		local Resultado_count
		local current_Resultado_ext
		local Resultado_ext_count
		for _, row in ipairs(Resultado) do
			rows_count = rows_count + 1
			-- table row:
			str, current_station, station_count, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count = tableRow(str, row, current_station, station_count, rows_count, showResultadoId, withStation, needCate, needLink, needGroup, current_Resultado, Resultado_count, current_Resultado_ext, Resultado_ext_count)
			-- cate:
			if needCate then
				if needCate == 2 or rootpagename == row['Resultado'] then
					addCate(row['station'])
				end
			end
		end
		-- rowspan value for last station group and Resultado group
		if station_count then
			str = str:gsub("xxxrowspanxxx", tostring(station_count))
		end
		if needGroup then
			str = str:gsub("yyyrowspanyyy", tostring(Resultado_count))
			str = str:gsub("zzzrowspanzzz", tostring(Resultado_ext_count))
		end
		-- ext rows:
		str = str .. extRows(withStation)
		-- table end
		str = str .. tableEnd(rows_count, expectedrows)

		-- cate
		if needCate then
			str = str .. cateStr()
		end

		return str
end
-----------------------------------------------------------------

local p = {}

-- for {{recipes/register}}
p.register = function(frame)
	local args = frame:getParent().args

	-- {{{Ingredientes}}}
	local Ingredientes = {} -- list of {index, itemname, amount}
	for k, v in pairs(args) do
		if(type(k) == 'number') then
			if k % 2 == 1 then  -- 2n-1, nth item
				local index, item, amount = (k+1)/2, trim(v), trim(args[k+1])
				Ingredientes[index] = {item, amount}
			end
		end
	end

	local serialized = '' -- serialized Ingredientes list
	for _, v in ipairs(Ingredientes) do
		serialized = serialized .. '^' .. v[1] .. '¦' .. v[2]
	end
	serialized = mw.ustring.sub(serialized, 2)

	table.sort(Ingredientes, function(a , b) return a[1] < b[1] end) -- sort by ingredient item name
	local Ingredientes_string = ''
	local Ingredientes_string_full = ''
	for _, v in ipairs(Ingredientes) do
		local name, amount = unpack(v)
		local ingstr = normalize(name)
		Ingredientes_string = Ingredientes_string .. '^' .. ingstr
		Ingredientes_string_full = Ingredientes_string_full .. '^' .. ingstr .. amount
	end

	--{{{version}}}, normalize
	version = normalizeVersion(args['version'] or '')

	--store
	frame:callParserFunction('#cargo_store:_table=Recipes',{
		Resultado = trim(args['Resultado'] or ''),
		Resultadoid = trim(args['Resultadoid'] or ''),
		Resultadoimage = trim(args['image'] or ''),
		Resultadotext = trim(args['text'] or ''),
		amount = trim(args['amount'] or ''),
		version = version,
		station = normalizeStation(trim(args['station'] or '')),
		Ingredientes = mw.ustring.sub(Ingredientes_string, 2),
		ings = mw.ustring.sub(Ingredientes_string_full, 2),
		args = serialized,
	})
end -- p.register

-- for {{recipes}}
p.query = function(frame)
	currentFrame = frame -- global frame cache
	local args = frame:getParent().args
	inputArgs = args

	lang = getArg('lang') or frame:expandTemplate{ title = 'lang' } or 'en'

	local where = trim(args['where'] or '')
	if where == '' then
		where = criStr(args)
	end

	-- no constraint no Resultado.
	if where == '' then
		return '<span style="color:red;font-weight:bold;">Recipes: No constraint</span>'
	end

	-- format:
	local needCate, needLink = getFlags(args)
	local needGroup = true
	if (getArg('grouping') or 'y'):sub(1,1) == 'n' then
		needGroup = false
	end
	local showResultadoId = false
	if trim(args['showResultadoid'] or '') ~= '' then
		showResultadoId = true
	end
	local _title = trim(args['title'] or '')
	local _expectedrows = trim(args['expectedrows'] or '')
	if _expectedrows ~= '' then
		_expectedrows = tonumber(_expectedrows)
	else
		_expectedrows = nil
	end
	local rootpagename = mw.title.getCurrentTitle().rootText

	if trim(args['nostation'] or '') ~= '' then
		-- no station
		-- query, still need contain station field for cate.
		local Resultado = mw.ext.cargo.query('Recipes', 'Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version, station, args', {
			where = where,
			groupBy = "Resultadoid, Resultado, amount, version, ings",
			orderBy = "Resultado, amount DESC, version", -- Don't order by station
			limit = 2000,
		})
		return tableBody(Resultado, showResultadoId, false, needGroup, needCate, needLink, rootpagename, _title, _expectedrows)
	else
		-- with station
		-- query
		local Resultado = mw.ext.cargo.query('Recipes', 'Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version, station, args', {
			where = where,
			groupBy = "Resultadoid, Resultado, amount, ings, version",
			orderBy = "station, Resultado, amount DESC, version, ings", -- order by station first for station grouping.
			limit = 2000,
		})
		return tableBody(Resultado, showResultadoId, true, needGroup, needCate, needLink, rootpagename, _title, _expectedrows)
	end
end -- p.query

-- for {{recipes/extract}}
p.extract = function(frame)
	currentFrame = frame -- global frame cache

	local args = frame:getParent().args
	inputArgs = args

	lang = getArg('lang') or frame:expandTemplate{ title = 'lang' } or 'en'

	local where = trim(args['where'] or '')
	if where == '' then
		where = criStr(args)
	end

	-- no constraint no Resultado.
	if where == '' then
		return '<span style="color:red;font-weight:bold;">Recipes/extract: No constraint</span>'
	end

	-- query:
	local Resultado = mw.ext.cargo.query('Recipes', 'Resultado, Resultadoid, Resultadoimage, Resultadotext, amount, version, station, args', {
		where = where,
		groupBy = "Resultadoid, Resultado, amount, version, ings",
		orderBy = "Resultado, amount DESC, version", -- Don't order by station
		limit = 20, -- enough.
	})

	-- output
	local mode = getArg('mode')
	local sep = getArg('sep') or getArg('seperator')
	if not mode or mode =='compact' or mode == '' then
		--default mode = Ingredientes
		local sep = sep or "<br/>'''or'''<br/>"
		local withResultado = getArg('withResultado')
		local withStation = not getArg('nostation')
		local withVersion = not getArg('noversion')
		local str = nil
		for _, row in ipairs(Resultado) do
			if str then
				str = str .. sep
			else
				str = ''
			end
			str = str .. '<span class="recipe compact">'
			if withVersion then
				if row['version'] ~= '' then
					str = str ..currentFrame:expandTemplate{ title = 'version icons', args = {row['version']} }..': '
				end
			end
			local ingFlag = nil
			for _, v in ipairs(explode('^', row['args'])) do
				if ingFlag then
					str = str .. ' + '
				else
					ingFlag = true
				end
				local item, amount = v:match('^(.-)¦(.-)$')
				if amount ~= '1' then
					str = str .. amount .. ' '
				end
				local s
				for _, itemname in ipairs(split(item)) do
					if s then
						s = s .. "&thinsp;/&thinsp;" .. itemLink(itemname, {mode='image'})
					else
						s = itemLink(itemname, {mode='image'})
					end
				end
				str = str .. s
			end
			if withStation then
				str = str .. compactStation(row['station'])
			end
			if withResultado then
				str = str .. ' = '
				if row['amount'] ~= '1' then
					str = str .. row['amount'] .. ' '
				end
				local args = {mode='image'}
				if row['Resultadoimage'] then
					args['image'] = row['Resultadoimage']
				end
				str = str .. itemLink(row['Resultado'], args)
			end
			str = str..'</span>'
		end
		return str
	elseif mode == 'Ingredientes' then
		local sep = sep or "'''or'''"
		local str = nil
		for _, row in ipairs(Resultado) do
			if str then
				str = str .. sep
			else
				str = ''
			end
			str = str .. IngredientesCell(row['args'])
		end
		return '<div class="crafting-Ingredientes">'..str..'</div>'
	elseif mode == 'station' then
		-- only return first row.
		for _, row in ipairs(Resultado) do
			return stationCell(row['station'], {})
		end
	elseif mode == 'Resultado' then
		-- only return first row.
		local needCate, needLink = getFlags(args)
		for _, row in ipairs(Resultado) do
			return ResultadoCell(row, getArg('showResultadoid'), needLink, true)
		end
	else
		return '<span style="color:red;font-weight:bold;">Recipes/extract: Invalid mode</span>'
	end
end -- p.extract

return p