Module:ProjectLister/CPCap

From Terra Invicta Official Wiki

Documentation for this module may be created at Module:ProjectLister/CPCap/doc

---
---Reads the Project data files and presents them in readable formats, with additional calculated statistics.
---
---@module CPCapProjectLister
local CPCapProjectLister = {}

--region Dependencies
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local ProjectData = mw.loadData('Module:CSVReader/Project')

local ProjectNameBuilder = require('Module:ProjectLister/NameBuilder')
local CPCapProjectData =  mw.loadData('Module:EffectLister/CPCapProjects')

local ProjectCosts = mw.loadData('Module:ProjectLister/Costs')

--endregion

--region Private constants
local insert = table.insert
local concat = table.concat
local CouncilIcons = {
	DestroyCouncil='destroy',
	ResistCouncil='resist',
	EscapeCouncil='escape',
	ExploitCouncil='exploit',
	CooperateCouncil='cooperate',
	AppeaseCouncil='appease',
	SubmitCouncil='submit',
	AlienCouncil='alien'
}
local ScienceCategories = {
	Energy = 'energy',
	InformationScience='information',
	LifeScience='life',
	Materials='material',
	MilitaryScience='military',
	SocialScience='social',
	SpaceScience='space',
	Xenology='xenology'
}
--endregion



--region Private member variables
--none
--endregion

--region Private methods
--endregion

--region Public methods

---@return wiki table of Projects that give CP cap
function CPCapProjectLister.ListProjects()
	local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;"'
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n! Project'
	returnString = returnString .. '\n! Type'
	returnString = returnString .. '\n! Research<br>Cost'
	returnString = returnString .. '\n! Full<br>Cost'
	returnString = returnString .. '\n! ' .. TVModule.TV({args={'cp'}}) .. ' Bonus'
	returnString = returnString .. '\n! rowspan=2|Available To:'
	returnString = returnString .. '\n|-'
	
	local factionTotals = {
		destroy = 0,
		resist = 0,
		escape = 0,
		exploit = 0,
		cooperate = 0,
		appease = 0,
		submit = 0,
	}
	for projectID, CPCapBonus in pairs(CPCapProjectData) do
		returnString = returnString .. '\n| ' .. ProjectNameBuilder.buildName({args={projectID}})
		returnString = returnString .. '\n| ' .. IconModule.Icon({args={ScienceCategories[ProjectData[projectID]['techCategory']]}})
		returnString = returnString .. '\n| ' .. ProjectData[projectID]['researchCost']
		returnString = returnString .. '\n| ' .. tostring(ProjectCosts[projectID]['total'])
		returnString = returnString .. '\n| ' .. CPCapBonus
		if not ProjectData[projectID]['factionPrereq/0'] or ProjectData[projectID]['factionPrereq/0'] == '' then
			returnString = returnString .. '\n| All'
			factionTotals['destroy'] = factionTotals['destroy'] + CPCapBonus
			factionTotals['resist'] = factionTotals['resist'] + CPCapBonus
			factionTotals['escape'] = factionTotals['escape'] + CPCapBonus
			factionTotals['exploit'] = factionTotals['exploit'] + CPCapBonus
			factionTotals['cooperate'] = factionTotals['cooperate'] + CPCapBonus
			factionTotals['appease'] = factionTotals['appease'] + CPCapBonus
			factionTotals['submit'] = factionTotals['submit'] + CPCapBonus
		else
			local councils = {}
			for i = 0, 5 do
				local freq = ProjectData[projectID]['factionPrereq/' .. i]
				if freq and freq ~= '' and freq ~= 0 then
					insert(councils, IconModule.Icon({args={CouncilIcons[freq]}}))
					factionTotals[CouncilIcons[freq]] = factionTotals[CouncilIcons[freq]] + CPCapBonus
				end
			end
			returnString = returnString .. '\n| ' .. concat(councils, '')
		end
		returnString = returnString .. '\n|-'
	end
	returnString = returnString .. '\n|- class="sortbottom"'
	returnString = returnString .. "\n! Total " .. TVModule.TV({args={'cp'}}) .. ' Bonus:' 
	returnString = returnString .. "\n! colspan=5 | "
	returnString = returnString .. '\n{| class="wikitable" style="text-align: center;"'
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'destroy'}})
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'resist'}})
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'escape'}})
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'exploit'}})
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'cooperate'}})
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'appease'}})
	returnString = returnString .. '\n! ' .. IconModule.Icon({args={'submit'}})
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n| ' .. factionTotals['destroy']
	returnString = returnString .. '\n| ' .. factionTotals['resist']
	returnString = returnString .. '\n| ' .. factionTotals['escape']
	returnString = returnString .. '\n| ' .. factionTotals['exploit']
	returnString = returnString .. '\n| ' .. factionTotals['cooperate']
	returnString = returnString .. '\n| ' .. factionTotals['appease']
	returnString = returnString .. '\n| ' .. factionTotals['submit']
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n|}'
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n|}'
	
	return returnString
end

--endregion

return CPCapProjectLister