Module:Mermaid

local p = {}; local cargo = mw.ext.cargo; local utils = require( "Module:Utils" );

function p.spirits(frame) local temp_res = {}; local temp_res2 = {}; local results = cargo.query("spirit_evolution","name,element,image,fxskills,sizebonus,reqstr,reqhealth,reqlust,reqmlvl,evinto",{		where = 'element="' .. frame.args[1] .. '"';	}); for _, result in ipairs(results) do		local header_req = {}; if (result["reqstr"] ~= nil) then header_req[#header_req+1] = "Str genes "; header_req[#header_req+1] = result["reqstr"]; header_req[#header_req+1] = " "; end if (result["reqhealth"] ~= nil) then header_req[#header_req+1] = "Health genes "; header_req[#header_req+1] = result["reqstr"]; header_req[#header_req+1] = " "; end if (result["reqlust"] ~= nil) then header_req[#header_req+1] = "Lust genes "; header_req[#header_req+1] = result["reqstr"]; header_req[#header_req+1] = " "; end if (result["reqmlvl"] ~= nil) then header_req[#header_req+1] = "Max Level genes "; header_req[#header_req+1] = result["reqstr"]; header_req[#header_req+1] = " "; end local header_text = ''; if #header_req > 0 then header_text = result["name"] .. ' Requirement ' .. table.concat(temp_res,""); else header_text = result["name"]; end local fix_skills = {}; if (result["fxskills"] ~= nil) then local fix_skills_parsed = utils.toNumberedTable(result["fxskills"],'/'); for _, skill in ipairs(fix_skills_parsed) do				fix_skills[#fix_skills+1] = '+ '; fix_skills[#fix_skills+1] = skill; fix_skills[#fix_skills+1] = ' '; end fix_skills[#fix_skills] = nil; end local fix_size = {}; if (result["sizebonus"] ~= nil) then fix_size[#fix_size+1] = '+ '; fix_size[#fix_size+1] = result["sizebonus"]; fix_size[#fix_size+1] = ' Size'; end local evolutions = cargo.query("spirit_evolution_part","evosource,evoname,evoelement,evotype,evoskills,evohealth,evomana,evostr,evomagic,evoldmg,evolres,evoarmor,evospeed,evopassive",{			where = 'name="' .. result["name"] .. '"';		}); local evo_res = {}; local evo_table = {}; evo_table["n"] = 0; for _, evolution in ipairs(evolutions) do			if evolution["evoelement"] == nil or evolution["evoelement"] == result["element"] then if evolution["evosource"] == nil then evo_res[#evo_res+1] = ' '; evo_res[#evo_res+1] = evolution["evoname"]; evo_res[#evo_res+1] = ": "; if (evolution["evoskills"] ~= nil) then local evo_skills_parsed = utils.toNumberedTable(evolution["evoskills"],'/'); for _, evo_skill in ipairs(evo_skills_parsed) do							evo_res[#evo_res+1] = evo_skill; evo_res[#evo_res+1] = ", "; end end if (evolution["evohealth"] ~= nil) then evo_res[#evo_res+1] = evolution["evohealth"]; evo_res[#evo_res+1] = " health"; evo_res[#evo_res+1] = ", "; end if (evolution["evomana"] ~= nil) then evo_res[#evo_res+1] = evolution["evomana"]; evo_res[#evo_res+1] = " mana"; evo_res[#evo_res+1] = ", "; end if (evolution["evostr"] ~= nil) then evo_res[#evo_res+1] = evolution["evostr"]; evo_res[#evo_res+1] = " strength"; evo_res[#evo_res+1] = ", "; end if (evolution["evomagic"] ~= nil) then evo_res[#evo_res+1] = evolution["evomagic"]; evo_res[#evo_res+1] = " magic"; evo_res[#evo_res+1] = ", "; end if (evolution["evoldmg"] ~= nil) then evo_res[#evo_res+1] = evolution["evoldmg"]; evo_res[#evo_res+1] = " lust dmg"; evo_res[#evo_res+1] = ", "; end if (evolution["evolres"] ~= nil) then evo_res[#evo_res+1] = evolution["evolres"]; evo_res[#evo_res+1] = " lust res"; evo_res[#evo_res+1] = ", "; end if (evolution["evoarmor"] ~= nil) then evo_res[#evo_res+1] = evolution["evoarmor"]; evo_res[#evo_res+1] = " armor"; evo_res[#evo_res+1] = ", "; end if (evolution["evospeed"] ~= nil) then evo_res[#evo_res+1] = evolution["evospeed"]; evo_res[#evo_res+1] = " speed"; evo_res[#evo_res+1] = ", "; end if (evolution["evopassive"] ~= nil) then local evo_passives_parsed = utils.toNumberedTable(evolution["evopassive"],'/'); for _, evo_passive in ipairs(evo_passives_parsed) do							evo_res[#evo_res+1] = evo_passive; evo_res[#evo_res+1] = ", "; end end evo_res[#evo_res] = nil; else if evo_table[evolution["evosource"]] == nil then evo_table[evolution["evosource"]] = {}; evo_table[evolution["evosource"]]["name"] = evolution["evosource"]; evo_table[evolution["evosource"]]["text"] = {}; evo_table["n"] = evo_table["n"] + 1; end local current_row = evo_table[evolution["evosource"]]["text"]; current_row[#current_row+1] = evolution["evoname"]; current_row[#current_row+1] = ": "; if (evolution["evoskills"] ~= nil) then local evo_skills_parsed = utils.toNumberedTable(evolution["evoskills"],'/'); for _, evo_skill in ipairs(evo_skills_parsed) do							current_row[#current_row+1] = evo_skill; current_row[#current_row+1] = ", "; end end if (evolution["evohealth"] ~= nil) then current_row[#current_row+1] = evolution["evohealth"]; current_row[#current_row+1] = " health"; current_row[#current_row+1] = ", "; end if (evolution["evomana"] ~= nil) then current_row[#current_row+1] = evolution["evomana"]; current_row[#current_row+1] = " mana"; current_row[#current_row+1] = ", "; end if (evolution["evostr"] ~= nil) then current_row[#current_row+1] = evolution["evostr"]; current_row[#current_row+1] = " strength"; current_row[#current_row+1] = ", "; end if (evolution["evomagic"] ~= nil) then current_row[#current_row+1] = evolution["evomagic"]; current_row[#current_row+1] = " magic"; current_row[#current_row+1] = ", "; end if (evolution["evoldmg"] ~= nil) then current_row[#current_row+1] = evolution["evoldmg"]; current_row[#current_row+1] = " lust dmg"; current_row[#current_row+1] = ", "; end if (evolution["evolres"] ~= nil) then current_row[#current_row+1] = evolution["evolres"]; current_row[#current_row+1] = " lust res"; current_row[#current_row+1] = ", "; end if (evolution["evoarmor"] ~= nil) then current_row[#current_row+1] = evolution["evoarmor"]; current_row[#current_row+1] = " armor"; current_row[#current_row+1] = ", "; end if (evolution["evospeed"] ~= nil) then current_row[#current_row+1] = evolution["evospeed"]; current_row[#current_row+1] = " speed"; current_row[#current_row+1] = ", "; end if (evolution["evopassive"] ~= nil) then local evo_passives_parsed = utils.toNumberedTable(evolution["evopassive"],'/'); for _, evo_passive in ipairs(evo_passives_parsed) do							current_row[#current_row+1] = evo_passive; current_row[#current_row+1] = ", "; end end current_row[#current_row] = nil; current_row[#current_row+1] = ' '; end end end if #fix_size > 0 and #fix_skills > 0 then fix_size[#fix_size+1] = " "; end if #fix_size == 0 and #fix_skills == 0 and #evo_res > 0 then evo_res[1] = ""; end local table_text = ""; local html_table = mw.html.create('span'):addClass('label-text') :tag('table'):addClass('label-table') :tag('thead') :tag('tbody'); local misc_text = table.concat(fix_size,"") .. table.concat(fix_skills,"") .. table.concat(evo_res,""); if #misc_text > 0 then html_table:tag('tr') :tag('td'):attr('colspan', '2') :wikitext(misc_text):done:done; end; if evo_table["n"] > 0 then evo_table["n"] = nil; for _, evo_type in pairs(evo_table) do				evo_type["text"][#evo_type["text"]] = nil; local name = string.gsub(evo_type["name"], '/', ' '); html_table:tag('tr') :tag('td'):wikitext(name):done :tag('td'):wikitext(table.concat(evo_type["text"],"")):done:done; end end; table_text = tostring(html_table:allDone); local squashed_name = string.gsub(result["name"], '%s+', ''); temp_res[#temp_res+1] = squashed_name; temp_res[#temp_res+1] = ''		temp_res[\n'; if (result["evinto"] ~= nil) then temp_res[#temp_res+1] = squashed_name; temp_res[#temp_res+1] = ' --> '; temp_res[#temp_res+1] = string.gsub(string.gsub(result["evinto"], '%s+', ''), '/', ' & '); temp_res[#temp_res+1] = '\n'; end temp_res2[#temp_res2+1] = 'click ' temp_res2[#temp_res2+1] = squashed_name; temp_res2[#temp_res2+1] = ' "/wiki/';		temp_res2[#temp_res2+1] = result["name"];		temp_res2[#temp_res2+1] = '" "';		temp_res2[#temp_res2+1] = squashed_name;		temp_res2[#temp_res2+1] = '"\n'; end local restbl = table.concat(temp_res,""); local result = string.gsub(	string.gsub(string.gsub(restbl,'"',"'"), '%[%[', '%["'), '%]%]', '"%]') .. table.concat(temp_res2,"");   return result; end

return p