Module:Buildings

local p = {} p.buildings = mw.loadData('Module:Buildings/data') p.config = { statcolumns = 5, imageSize = 15, imageStatSize = 20 }

local f = require('Module:Functions')

function calculate(value,time) if(value == nil or time == nil) then return "?" end return f.round(value/(time/60),2) end

function stat(name,money,xp,time,unlock,characters,stat,frame) local data = {} if(frame~=nil) then return ' '.. ' '..money..'  '.. '  '..xp..'  '.. ' /min '..calculate(money,time)..'  '.. ' /min '..calculate(xp,time)..'  '.. ' Time '..f.time(time)..'  '.. ' '..		' Unlock: '..unlock end s = "" if (stat ~= nil) then s = ' '..f.upfirst(stat)..' ' end table.insert(data, ' '..s..name..' ') table.insert(data, ' ') table.insert(data, ' ') table.insert(data, ' ') table.insert(data, ' /min ') table.insert(data, ' /min ') table.insert(data, ' Time ') table.insert(data, ' ') table.insert(data, ' ') table.insert(data, ' '..f.hasValue(money)..' ') table.insert(data, ' '..f.hasValue(xp)..' ') table.insert(data, ' '..calculate(money,time)..' ') table.insert(data, ' '..calculate(xp,time)..' ') table.insert(data, ' '..f.time(time)..' ') table.insert(data, ' ') if(unlock ~= nil) then table.insert(data, ' Unlock: '..unlock..' ') end if(getCharacters(characters) ~= nil) then	table.insert(data, ' Characters: '..getCharacters(characters)..' ') end return table.concat(data, "\n") end

function getImages(images, levels, description,stats, name, frame) local _images = {'")

return frame:preprocess(table.concat(_images, "\n")) end

function getCharacters(data) local characters = "" if(data == nil) then return nil end for i, j in pairs(data) do		characters = characters..j	end return characters end

function p.table(frame) local data = { '==Buildings List==', ' '   }    for a, s in pairs(p.buildings) do    	table.insert(data,'{| class="wikitable mw-datatable sortable" style="text-align: center; float:left;"') table.insert(data,'|-') table.insert(data, '| '..getImages(s.images,s.levels, s.description,s.stats,a, frame)) table.insert(data, '|-') table.insert(data, '| style="padding:0;"|') table.insert(data, ' ') table.insert(data, '|-') table.insert(data, '|}') end table.insert(data, 'Add building ') return table.concat(data, "\n") end

return p