Module:Buildings

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

local f = require('Module:Functions')

--https://collegelife.miraheze.org/wiki/Buildings function p.overview(frame) local data = { '==Buildings List==', ' '   }    for a, s in pairs(p.buildings) do    	table.insert(data,'{| class="wikitable mw-datatable sortable" style="width:250px;text-align: center; float:left; margin:10px;"') table.insert(data,'|-') table.insert(data, '| '..getImages(s.images,s.levels, s.description,s.stats,a, s.exists, frame)) table.insert(data, '|-') table.insert(data, '| style="padding:0;"|') table.insert(data, ' ') table.insert(data, '| style="padding:0;"|') table.insert(data, ' ') table.insert(data, '|-') table.insert(data, '|}') end table.insert(data, ' ') return table.concat(data, "\n") end

--https://collegelife.miraheze.org/wiki/Buildings/Stats function p.stats(frame) local data = { '==Buildings Stats==', ' ',		 '{| class="wikitable mw-datatable sortable" style="text-align: center;',		  '|-',		  '! Buildng',		  '! ',		  '! ',		  '! /min',          '! /min',          '! Collect Time',          '! Upgrade Time',		  '! Upgrade cost',		  '|-'	}	for a, j in pairs(p.buildings) do 		table.insert(data,'| rowspan='..f.length(j.stats.money)..'|'..a.." "..getFirstImage(a,j.images,j.exists))		for i in f.range(f.length(j.stats.money)) do			table.insert(data, '|'..j.stats.money[i])			table.insert(data, '|'..j.stats.xp[i])			table.insert(data, '|'..calculate(j.stats.money[i],j.stats.time))			table.insert(data, '|'..calculate(j.stats.xp[i],j.stats.time))            table.insert(data, '| data-sort-value='..j.stats.time..'|'..f.time(j.stats.time))            table.insert(data, '|'..(j.stats.hoursForUpgrade[i] or ""))            table.insert(data, '|'..(j.stats.costForUpgrade[i] or ""))            table.insert(data, '|') table.insert(data, '|-') end end table.insert(data,'|}') return table.concat(data, "\n") end

--https://collegelife.miraheze.org/wiki/Buildings/Tasks function p.tasks(frame) local data = { '==Buildings Tasks==', ' ',		 '{| class="wikitable mw-datatable sortable" style="text-align: center;',		  '|-',		  '! Buildng',		  '! ',		  '! ',		  '! /min',		  '! /min',		  '! Time',		  '! Type',		  '|-'	}	for a, j in pairs(p.buildings) do 		if(f.length(j.tasks)==0) then 			table.insert(data,'| '..a.." "..getFirstImage(a,j.images,j.exists))			table.insert(data, '| colspan = 6 | ?')			table.insert(data, '|-')		else 			table.insert(data,'| rowspan='..f.length(j.tasks)..'|'..a.." "..getFirstImage(a,j.images,j.exists)) 		end		for b, task in pairs(j.tasks) do			table.insert(data,'|'..task.money)			table.insert(data,'|'..task.xp)			table.insert(data,'|'..calculate(task.money,task.time))			table.insert(data,'|'..calculate(task.xp,task.time))			table.insert(data,'| data-sort-value='..task.time..'|'..f.time(task.time))			table.insert(data,'|' .. task.stat)			table.insert(data,'|-')		end 	end		table.insert(data,'|}') return table.concat(data, "\n") end

--https://collegelife.miraheze.org/wiki/Buildings/Clothes_store function p.clothesstore local characters = mw.loadData('Module:Characters/data') local c = require('Module:Characters') local data = {} local data = { '==Outfits==', ' '	}	for a, b in pairs(characters) do		for i, j in pairs(b.outfits) do table.insert(data, ' '..j.name..' '..c.getStats(j.stats)..' '..j.acquisition.." ") end end table.insert(data," ") return table.concat(data, "\n") end

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 and stat ~="") 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, exists, 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 getFirstImage(name,image,exists) if(image == nil or exists ~= nil and exists[1] == false) then return "" end return "" end

return p