Module:Characters

local p = {} local characters = mw.loadData('Module:Characters/data') local quests = mw.loadData('Module:Characters/quests') local f = require('Module:Functions')

p.config = { geek = "#02e8ab", charmer = "#ff00c8", artist = "#ff8000", jock = "#0062ff", romantic = "#ff0000" }

function p.other(frame) if frame.args[1] == "" then return end return frame.args[1] end

function check(num,c) if (num == nil or num == "")==true then return 'Add here.' else return num end end

function getRelationships(frame,list,pixels,newline) characters = "" count = 1 for s, a in pairs(list) do		if(newline ~= nil and (count-1)%newline == 0) then characters = characters.." " end characters = characters..' ' count = count+1 end return characters end

function p.infobox(frame) local name = mw.title.getCurrentTitle.text local char_data=characters[name] if char_data == nil then return " Please insert data to Module:Characters/data." end local data = {} local infobox = { image = name..'.png', relationships = getRelationships(frame,char_data.relationships,75,4), geek = char_data.defaultStats.geek, color_geek = p.config.geek, charmer = char_data.defaultStats.charmer, color_charmer = p.config.charmer, artist = char_data.defaultStats.artist, color_artist = p.config.artist, jock = char_data.defaultStats.jock, color_jock = p.config.jock, romantic = char_data.defaultStats.romantic, color_romantic = p.config.romantic }   table.insert(data, frame:expandTemplate { title = 'Character info', args = infobox }) return table.concat(data, '\n') end

function getStats(data) local stats = "" for i, j in pairs(data) do 		stats = stats..''..f.upfirst(i)..' '..j..' ' end return stats end

function p.outfits(frame) local name = mw.title.getCurrentTitle.text local char_data=characters[name] if char_data == nil then return "" end local count = 1 local data = { '==Outfits==', ' ',		'{| class="wikitable mw-datatable sortable" style="text-align: center;"', '|-',	}	for i, j in pairs(char_data.outfits) do 		if(count%6 == 0) then table.insert(data, '|-') end table.insert(data, '| '..j.name..' '..getStats(j.stats)..' '..j.acquisition) count = count+1 end table.insert(data, '|-') local c = count-1 if(count>6) then c = 6 end table.insert(data, '|colspan='..c..'| Add outfit') table.insert(data, '|} ') return table.concat(data, '\n') end

function inList(what,list) for i, j in pairs(list) do		if(string.match(j,what)) then return true end end return false end

function getRewards(data) local rewards = "" local hasIcon = {"xp","money","kiss"} local link = "" for i, j in pairs(data) do		if(inList(i, hasIcon)) then link = '' else link = f.upfirst(i) end rewards = rewards..link.." "..j.." " end return rewards end

function p.quests(frame) local name = mw.title.getCurrentTitle.text local data = { '==Quests==', ' ',		'{| class="wikitable mw-datatable sortable" style="text-align: center;"', '|-',		'! Quest', '! Description', '! Explanation', '! Rewards', '|-'	}	for i, j in pairs(quests) do		for b,k in pairs(j.characters) do			if(string.match(k,name)) then table.insert(data, '|'..j.title) table.insert(data, '|'..j.description) table.insert(data, '|'..j.explanation) table.insert(data, '|'..getRewards(j.rewards)) table.insert(data, '|-') end end end table.insert(data, '|colspan=4| Add quest') table.insert(data, '|} ') return table.concat(data, '\n') end

function p.table(frame) local data = { '==Character List==', '{| class="wikitable mw-datatable sortable" style="text-align: center;"', '|-',       '! Name', '! Picture', '! Relationships', '! data-sort-type="number" | Available', '|-'   }    for a, s in pairs(characters) do        table.insert(data, '| '..a..f.noPage(frame,a,"")..'') table.insert(data, '| ') table.insert(data, '|'..getRelationships(frame,s.relationships,55)) table.insert(data, '|'..check(s.available)) table.insert(data, '|-') end table.insert(data, '|colspan=4| Add character') table.insert(data, '|}') return table.concat(data, "\n") end return p