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] = tostring(mw.html.create('span'):css('color','#cc0000'):wikitext("Str genes " .. result["reqstr"])); end if (result["reqhealth"] ~= nil) then header_req[#header_req+1] = tostring(mw.html.create('span'):css('color','#00AD00'):wikitext("Health genes " .. result["reqhealth"])); end if (result["reqlust"] ~= nil) then header_req[#header_req+1] = tostring(mw.html.create('span'):css('color','#B800B8'):wikitext("Lust genes " .. result["reqlust"])); end if (result["reqmlvl"] ~= nil) then header_req[#header_req+1] = tostring(mw.html.create('span'):css('color','#CC9900'):wikitext("Max Level genes " .. result["reqmlvl"])); end local header_text = ''; if #header_req > 0 then header_text = result["name"] .. ' Req. ' .. table.concat(header_req," "); 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,evosize,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] = ' '; if (string.gsub(string.gsub(evolution["evoname"], "%s%(.*", ""),"%s%d+","") ~= evolution["evotype"]) then						evo_res[#evo_res+1] = tostring(mw.html.create('span'):addClass('simple-tooltip simple-tooltip-inline tooltipstered') :attr('data-simple-tooltip',tostring(mw.html.create('span'):wikitext('Type: ' .. evolution["evotype"]))):wikitext(evolution["evoname"]));					else						evo_res[#evo_res+1] = evolution["evoname"];					end					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["evosize"] ~= nil) then						evo_res[#evo_res+1] = evolution["evosize"];						evo_res[#evo_res+1] = " size";						evo_res[#evo_res+1] = ", ";					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"]; if (string.gsub(string.gsub(evolution["evoname"], "%s%(.*", ""),"%s%d+","") ~= evolution["evotype"]) then						current_row[#current_row+1] = tostring(mw.html.create('span'):addClass('simple-tooltip simple-tooltip-inline tooltipstered') :attr('data-simple-tooltip',tostring(mw.html.create('span'):wikitext('Type: ' .. evolution["evotype"]))):wikitext(evolution["evoname"]));					else						current_row[#current_row+1] = evolution["evoname"];					end					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["evosize"] ~= nil) then						current_row[#current_row+1] = evolution["evosize"];						current_row[#current_row+1] = " size";						current_row[#current_row+1] = ", ";					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 html_table = mw.html.create('table'):addClass('label-table') :tag('thead') :tag('tr') :tag('th'):attr('colspan', '3') :tag('div'):addClass('label-header'):wikitext(header_text):done:done:done:done :tag('tbody') :tag('tr') :tag('td'):attr('rowspan', '0') :tag('img'):addClass('label-image') :attr('src', frame:callParserFunction{ name = 'filepath', args = result["image"],'72x72px' }):done:done :tag('td'):attr('colspan', '2'):css('border','none'):done:done;

local misc_text = table.concat(fix_size,"") .. table.concat(fix_skills,"") .. table.concat(evo_res,""); if #misc_text > 0 then html_table = html_table:tag('tr') :tag('td'):attr('colspan', '2') :tag('span'):addClass('label-text'):wikitext(misc_text):done: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 = html_table:tag('tr') :tag('td'):tag('span'):addClass('label-text'):wikitext(name):done:done :tag('td'):tag('span'):addClass('label-text'):wikitext(table.concat(evo_type["text"],"")):done:done:done; end end; 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

function p.skillTree(frame) local imgSize = frame.args[4]; local data = mw.title.makeTitle("",frame.args[3].."/load"):getContent; if (data == nil) then return ""; end local stat,decoded = pcall(mw.text.jsonDecode,data); if (stat == false) then return ""; end local tf_type = { [0] = ,   	[1] = ,    	[2] = ,    	[3] = ,    	[4] = ,    	[5] = ,    	[6] = ,    	[7] = ,    	[8] = ,    	[9] = ,    };	local unknw = function(tab, index) return 'Unknown' end; setmetatable(tf_type,{__index = unknw}); local tf_node = ''; local html_table = mw.html.create('table'):addClass('label-table') :tag('tbody'); local html_rows = { [0] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [1] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [2] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [3] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [4] = mw.html.create('tr'):addClass('label-row'):tag('td'):tag('div'):addClass('label-connection-h-a'):done:done, [5] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [6] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [7] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, [8] = mw.html.create('tr'):addClass('label-row'):tag('td'):done, }	for i, result in ipairs(decoded[frame.args[2]]) do		local current_row = ((i-1) - (math.floor((i-1)/5))*5)*2; local image = tf_type[result["type"]]; local html_node = mw.html.create('td'):tag('div'):addClass('label-node'):wikitext(tf_node) :tag('span'):addClass('label-header'):wikitext(result["name"]):done :tag('span'):addClass('label-image'):wikitext(image):done :tag('span'):addClass('label-image-background'):wikitext(tf_node):done :tag('span'):addClass('label-primary'):wikitext(result["costPrimary"]):done; for i = 1, result["count"] do			html_node = html_node :tag('span'):addClass('label-count-' .. i):wikitext(result["count"]):done; end if (result["costSecondary"] ~= nil and result["speciesSecondary"] ~= nil) then html_node = html_node :tag('span'):addClass('label-secondary'):addClass('label-' .. result["speciesSecondary"]):wikitext(result["costSecondary"]):done; end html_rows[current_row] = html_rows[current_row]:node(html_node:allDone); if (result["connection_right"] ~= nil) then html_rows[current_row] = html_rows[current_row]:tag('td'):tag('div'):addClass('label-connection-h'):done:done; end if (result["connection_bottom"] ~= nil) then html_rows[current_row+1] = html_rows[current_row+1]:tag('td'):tag('div'):addClass('label-connection-v'):done:done; end end html_table = html_table:node(html_rows[0]) :node(html_rows[1]) :node(html_rows[2]) :node(html_rows[3]) :node(html_rows[4]) :node(html_rows[5]) :node(html_rows[6]) :node(html_rows[7]) :node(html_rows[8]):allDone; local result = tostring(html_table); return result; end

return p