Module:Trades

local ProcessArgs = require('Module:ProcessArgs')

local npcLevels = { "novice", "apprentice", "journeyman", "expert", "master" }

local p = {}

local function parseTradeArg(row) local fieldSep = ',' local tokenSep = '=' local endlToken = '@' local trades = {} for line in string.gmatch(row, '[^\r\n]+' .. endlToken .. '[\r\n]+') do		local parsedLine = {} for key, value in string.gmatch(line, '([%a]+)%s*' .. tokenSep .. '%s*(.-)%s*[' .. fieldSep .. endlToken .. ']') do			if value ~= '' then parsedLine[key:lower] = value end end table.insert(trades, parsedLine) end end

local function parseTableArgs(frame, args, isNpcTable) local allTrades = {} for level=1, #npcLevels do if not args['trades' .. level] then break end allTrades[level] = parseTradeArg(args['trades' .. level]) allTrades[level]['slots'] = args['slots' .. level] end return allTrades end

function p.npcTradeTable(frame) local args = frame if frame == mw.getCurrentFrame then args = ProcessArgs.merge(true) else frame = mw.getCurrentFrame end trades = parseTableArgs(frame, args, true) mw.logObject(trades) end

function p.itemTradeTable(frame) local args = frame if frame == mw.getCurrentFrame then args = ProcessArgs.merge(true) else frame = mw.getCurrentFrame end end

return p