Module:Characters

local p = {} 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,_count) 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 if(_count) then return count-1 end return characters end

function p.infobox(frame) local name = mw.title.getCurrentTitle.text local char_data= mw.loadData('Module:Characters/data')[name] if char_data == nil then return " Please insert data to Module:Characters/data." end local data = {} local infobox = { image = name..'.png', fullName = char_data.fullName, age = char_data.age, height = char_data.height, eyes = char_data.eyes, skin = char_data.skin, hair = char_data.hair, cup = char_data.cup, personality = char_data.personality, likes = char_data.likes, dislikes = char_data.dislikes, bio = char_data.bio, 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 p.bio(frame) local name = mw.title.getCurrentTitle.text local char_data= mw.loadData('Module:Characters/data')[name] if char_data == nil then return "" end local data = '==Overview==' .. '\n' .. ' ' .. char_data.bio .. ' ' .. '\n' return data 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= mw.loadData('Module:Characters/data')[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', '! Gender', '! Available', '|-'   }    for a, s in pairs(mw.loadData('Module:Characters/data')) do        table.insert(data, '| '..a..f.noPage(frame,a,"")..'') table.insert(data, '| ') table.insert(data, '| data-sort-value='..getRelationships(frame,s.relationships,55,nil,true)..' |'..getRelationships(frame,s.relationships,55)) gender = "female" if(s.gender ~= null) then gender = s.gender end table.insert(data, '| ') table.insert(data, '|'..check(s.available)) table.insert(data, '|-') end table.insert(data, '|}') table.insert(data, 'Add character ') return table.concat(data, "\n") end return p