Module:Characters

-- The following pages are related: https://naughty-kingdom.wikia.com/wiki/Module:Characters https://naughty-kingdom.wikia.com/wiki/Module:Characters/data https://naughty-kingdom.wikia.com/wiki/Module:Characters/qa local p = {} local characters = mw.loadData('Module:Characters/data') local qa = mw.loadData('Module:Characters/qa')

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

function compareLess(x, y)   return x[1] < y[1] end function compareMore(x, y)   return x[1] > y[1] end function tableSort(table1,table2,more) for i,v in ipairs(table1) do       table1[i] = {table1[i], table2[i]} end if more == 'less' then table.sort(table1, compareLess) else table.sort(table1, compareMore) end for i, v in ipairs(table1) do       table1[i] = v[1] table2[i] = v[2] end return table2 end

function check(num,maxi,c) if num == nil then if maxi == 4 then return '/' end return 'Add data here.' else return num end end

function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end

function p.xptable(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 = { frame:expandTemplate { title = 'Clear'}, '==XP Table==', '{| class="wikitable mw-datatable" style="text-align: center;"', '|-',       '! Level', '! Coins/h', '! Max Coins', '! XP to next Level', '! Bonus %', '|-'   }    local table1 = {} local table2 = {} for i, j in pairs(char_data.stats) do        table.insert(table1, string.match(i,"%d+")) table.insert(table2, j)   end for i, j in pairs(tableSort(table1, table2, 'less')) do      table.insert(data, '|'..i)       table.insert(data, '|'..check(j.h)) table.insert(data, '|'..check(j.m)) table.insert(data, '|'..check(j.x,i)) table.insert(data, '|'..check(j.b)) table.insert(data, '|-') end table.insert(data, '|}') return table.concat(data, "\n") 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 count = 0 for i, j in pairs(char_data.facts) do       if j ~= nil then count = count+1 end end if count == 0 then return " Please insert data to Module:Characters/data." end local data = {} local infobox = { image = name..'.png', gp=''..check(char_data.facts.gp)..' ', gd=''..check(char_data.facts.gd)..' ', bonus=' '..check(char_data.facts.bonus)..' ', b=check(char_data.facts.b), a=check(char_data.facts.a), h=check(char_data.facts.h), w=check(char_data.facts.w), c=check(char_data.facts.c), s=check(char_data.facts.s), W=check(char_data.facts.W), f=check(char_data.facts.f), p=check(char_data.facts.p), P=check(char_data.facts.P), A=check(char_data.facts.A), e=check(char_data.facts.e)   } table.insert(data, frame:expandTemplate { title = 'Character info', args = infobox }) return table.concat(data, '\n') end

function p.questions(frame) local name = mw.title.getCurrentTitle.text local data = { '==Q&A==', '{| class="wikitable mw-datatable sortable" style="text-align: center;"', '|-',       '! Question', '! Answer', '|-'   }    for a, s in pairs(qa) do         c=0 if s[name]~=nil then table.insert(data, '| '..s.q)           for b, d in pairs(s) do                if string.match(b,name) then c = c+1 if c == 1 then table.insert(data, '| '..d)                    else table.insert(data, " or ") table.insert(data, d)           end end end table.insert(data, '|-') end end table.insert(data, "|colspan=2|Add questions here") table.insert(data, '|}') for i, d in pairs(data) do mw.log(d) end 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', '! Gift Preference', '! Gift Dislike', '! data-sort-type="number" | Coins/h (MAX LVL)', '! data-sort-type="number" | Max Coins (MAX LVL)', '! data-sort-type="number" | h untill full', '! data-sort-type="number" | Available', '|-'   }    for a, s in pairs(characters) do        z = nil table.insert(data, '| '..a..'') table.insert(data, '| ') if s.facts.gp == nil then gp = "" else gp=s.facts.gp end table.insert(data, '|style="color:#46C646;"|'..gp) if s.facts.gd == nil then gd = "" else gd=s.facts.gd end table.insert(data, '|style="color:#F00;"|'..gd) if type(check(s.stats.lvl4.h)) == "number" then x = check(s.stats.lvl4.h) else z = '?' x = 0 end table.insert(data, '|'..check(s.stats.lvl4.h)) if type(check(s.stats.lvl4.m)) == "number" then y = check(s.stats.lvl4.m) else z = '?' y = 0 end table.insert(data, '|'..check(s.stats.lvl4.m)) if z == nil then z = round(y/x,2) end table.insert(data, '|'..z)       table.insert(data, '|'..check(s.chapter)) table.insert(data, '|-') end table.insert(data, '|}') for i, d in pairs(data) do mw.log(d) end return table.concat(data, "\n") end return p