Module:AutoAdvancements

local p = {} local trim = mw.text.trim local split = mw.text.split local tableParser = mw.text.listToText p.tp = tableParser

local settings = { ["baseAdvancements"] = "TesseractFour"; ["iconHeight"] = 52; ["iconMarginHeight"] = 1; }

local advancementTree = {} local advancementTable = {}

function check(string) return string and #tostring(string) > 0 end

function convertTable(table) local tbl = {} for k,v in pairs(table) do       if type(v) == "table" then tbl[k] = convertTable(v) else tbl[k] = v;       end end return tbl end

function addChild(table, child) if not(table.children) then table.children = { [1] = child; }   else table.children[#table.children + 1] = child; end return child end

function getElement(table, adress) mw.log(adress) local adr = split(adress,".",true) local looper = table for i = 1, #adr do       mw.log(looper,adr[i],#looper) if i == 1 then looper = looper[adr[i]] else looper = looper.children[tonumber(adr[i])] end if not(looper) then return nil end end return looper end

function p.loadAdvancements(string) mw.log(string) listAdv = split(string,",",true) for i = 1, #listAdv do       local cur = trim(listAdv[i]); mw.log(cur) local data = {}; if not pcall(function data = mw.loadData("Module:AutoAdvancements/" .. cur) end) then return "Couldn't find module: " .. cur end data = convertTable(data) for j = 1, #data do           mw.log(cur .. "." .. data[j].id) if data[j].root then advancementTree.root=data[j] advancementTable[cur .. "." .. data[j].id]=data[j] advancementTable[cur .. "." .. data[j].id].pth="root" else if not(advancementTable[data[j].parent]) then return "Could not find: \"" .. data[j].parent .. "\" parent of : \"" .. data[j].id .. "\"" end local pth = advancementTable[data[j].parent].pth if pth then local tbl = getElement(advancementTree, pth) if not(tbl) then return "Could not find: \"" .. pth .. "\" parent of : \"" .. data[j].id .. "\"" end addChild(tbl,data[j]).pth = pth .. "." .. #tbl.children else return "Error, \"" .. data[j].parent .. "\" has no path." end advancementTable[cur .. "." .. data[j].id]=data[j] end end end return advancementTree end

function p.Generate(frame) end return p