Module:Buildings

local p = {} p.buildings = mw.loadData('Module:Buildings/data') local f = require('Module:Functions')

function calculate(value,time) return f.round(value/(time/60),2) end

function stat(name,money,xp,time,unlock,characters,base) local data = {} local col = 0 if(getCharacters(characters) == nil) then col = col+1 end if(unlock == nil) then col = col+1 end if(base~=nil) then table.insert(data,'{| class="wikitable mw-datatable sortable" style="text-align: center;"') end table.insert(data, '| colspan=5 |'..name) table.insert(data, '|-') table.insert(data, '|'..money) table.insert(data, '|'..xp) table.insert(data, '|'..calculate(money,time)) table.insert(data, '|'..calculate(xp,time)) table.insert(data, '| colspan='..col..'|'..f.time(time)) if(unlock ~= nil) then table.insert(data, '|'..unlock) end if(getCharacters(characters) ~= nil) then	table.insert(data, '|'..getCharacters(characters)) end table.insert(data, '|-') if(base~=nil) then table.insert(data, '|}') 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;"') 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, '{| class="wikitable mw-datatable mw-collapsible mw-collapsed" style="text-align: center; width:100%; height:100%; padding:0; margin:0;"') table.insert(data, '|-') table.insert(data, '! colspan=5 | Stats') table.insert(data, '|-') for i, j in pairs(s.tasks) do   		stat(i,j.money,j.xp,j.time,j.unlock,j.characters) end table.insert(data, '|}') table.insert(data, '|-') table.insert(data, '|}') end table.insert(data, 'Add building ') return table.concat(data, "\n") end

return p