Dead by Daylight Wiki
Advertisement

local p = {}
local data = require("Module:Datatable")
local mathOps = require("Module:MathOps")
local utils = require("Module:Utils")
local perksData = mw.loadData("Module:Datatable/Perks")
local perkImg = require("Module:PerkImage")
local str = require("Module:Strings")
local frame = mw.getCurrentFrame()


strings = {
	the = "The",
	altName = "Alt. Name",
	gender = "Gender",
	role = "Role",
	nationality = "Nationality",
	dlc  = "DLC",
	actor = "Voice Actor",
	uknownActor = "Undisclosed Voice Actor", --unkown/undisclosed
	male = "Male",
	female = "Female",
	undefined = "Undefined",
	survivors = "Survivors"
}

local perks = perksData.perks

function p.getCountOfSurvivors()
	return utils.getCount("survivor")
end

function getSurvivorNameById(id) --not used
	for _, s in ipairs(survivors) do
		if s.id == id then return s.name end
	end
	return 0
end

function getSurvivorIdByName(name)
	for _, survivor in ipairs(survivors) do
		if survivor.name == name then
			return survivor.id
		end
	end
	
	return 0
end

function p.getSurvivorById(id)
	for _, survivor in ipairs(survivors) do
		if survivor.id == id then return survivor end
	end
	return nil
end

function p.resolveSurvivorCharTable(charName)
	charName = utils.resolveParameter(charName, 1, false)
	local survivorId = getSurvivorIdByName(charName)
	local surv = utils.getCharacterById(survivorId, survivors)
	local result = cstr.empy
	
	if type(surv) ~= types.table then return utils.resolveParameter(charName) end
	
	result = 
		'{| class = "infoboxtable"' .. nl ..
		ntl ..' class = "infoboxTitle" | ' .. nl ..
		'! class = "center bold" colspan = 2 | ' .. (surv.shortName or surv.name) .. nl ..
		ntl .. nl ..
		'! class = "center" colspan = 2 | ' .. file(resolveSurvPortraitImageFileName(surv) .. '.png', '150px') .. nl ..
		ntl .. nl
		if surv.altName ~= nil then
			result = result .. '| class = "titleColumn" | ' .. strings.altName .. ' || class = "valueColumn" | ' .. surv.altName .. nl .. ntl .. nl
		end
	result = result ..
		'| class = "titleColumn" | ' .. strings.gender .. ' || class = "valueColumn" | ' .. utils.resolveGender(surv.gender) .. nl ..
		ntl .. nl ..
		'| class = "titleColumn" | ' .. strings.role .. ' || class = "valueColumn" | ' .. surv.role .. nl ..
		ntl .. nl ..
		'| class = "titleColumn" | ' .. strings.nationality .. ' || class = "valueColumn" | ' .. surv.nationality .. nl ..
		ntl .. nl
		if surv.dlc ~= nil then
			local dlcs = require("Module:DLCs")
			result = result .. '| class = "titleColumn" | ' .. strings.dlc .. ' || class = "valueColumn" | ' .. link(dlcs.getDlcFullNameByCharacter(surv)) .. nl .. ntl .. nl
		end
	result = result ..
		'| class = "titleColumn" | ' .. strings.actor .. ' || class = "valueColumn" | ' .. (surv.actor or strings.uknownActor) .. nl ..
		'|}'
	
	
	--mw.log(result)
	return result	

end
	

function p.resolveSurvivorsTable()
	local result = cstr.empty
	local name
	local fileName

	result = result .. '<div style = "color: #fff;">'
	maxId = utils.getMaxId(survivors)
	for i, survivor in ipairs(survivors) do
		fileName = utils.resolveCharacterPortraitFileName(survivor, maxId)
		
		result = result .. 
			'<div style = "display: inline-block; text-align:center; margin: 10px">' .. link(survivor.name) ..
			link(cstr.file .. fileName .. '.png|center|frameless|link=' .. survivor.name) .. '</div>'
	end
	result = result .. '</div>'

	return result
end

function p.resolveSurvivorsTableMainPage()
	local result = cstr.empty
	local name
	local fileName

	result = result ..
		'<div class = "fpbox" id = "fpsurvivors" style = "text-align: center;">' ..
		'<div class = "heading">' .. the(strings.survivors) .. space .. link(strings.survivors) .. space .. link(cstr.file .. 'IconHelpLoading survivor.png|32px') .. '</div>' ..
		'<div class = "fplinks charSection">'
	utils.sortTableById(survivors)
	local maxId = utils.getMaxId(survivors)
	for i, survivor in ipairs(survivors) do
		name = survivor.shortName or survivor.name
		fileName = utils.resolveCharacterPortraitFileName(survivor, maxId)
		
		result = result .. 
			'<div class = "fplink charMainPageBox plainlinks image"><div class = "box"><div class = "row"><div class = "cell">' ..
				'<div class = "image">' .. link(cstr.file .. fileName .. '.png|link=' .. name) .. '</div>' ..
				'<div class = "charLink survivorLink link">' .. link(name) .. '</div>' ..
				'<div class = "charPerkBox">' .. resolveCharPerksMainPage(survivor) .. '</div>' ..
			'</div></div></div></div>'
	end
	result = result ..
		'</div>' ..
		'</div>'

	return result
end

function resolveCharPerksMainPage(character)
	local mPerks = require("Module:Perks")
	local result = ''
	local perkList = mPerks.getPerksByCharacter(character)
	
	utils.sortPerksByLevel(perkList)
	for _, perk in ipairs(perkList) do
		--p.getTeachablePerkIcon(perk, true => because of avoiding file existence check)
		result = result .. '[[' .. cstr.file .. mPerks.getTeachablePerkIcon(perk, true)  .. '|link=' .. perk.name .. '|42px]]'
	end
	--Teachable unknown.png
	return result
end
	
function resolveSurvPortraitImageFileName(surv, addon)
	local fileConst = "_charSelect_portrait"
	return "S" .. string.format("%02d", surv.id) .. ((addon and space .. addon) or cstr.empty) .. fileConst
end

function getSurvivorListWithPerks()
	local perkTable = {}
	for _,perk in ipairs(perks) do
		if perk.character ~= nil and perk.charType == 'S' then
			if perkTable[perk.character] == nil then
				perkTable[perk.character] = {}
			end
			perkTable[perk.character].id = perk.character
			perkTable[perk.character][#perkTable[perk.character]+1] = perk
		end
	end
	
	return perkTable
end

function p.resolveSurvivorsEntries()
	local perkTable = getSurvivorListWithPerks()
	local result = ""
	
	result = result .. '<div style="display: flex; flex-flow: row wrap; justify-content:center;">' .. nl
	
	for _, trio in ipairs(perkTable) do
		result = result .. '<div class = "entryTable">' .. nl ..
		'{| class = "wikitable"' .. nl
		
		survivor = p.getSurvivorById(trio.id)
		result = result .. '|+ ' .. survivor.name .. nl ..
		ntl .. nl ..
		tl .. 'class = "center" rowspan = 3' .. tl .. file(resolveSurvPortraitImageFileName(survivor) .. dot .. cstr.png, "99px", 'link=' .. survivor.name) .. nl
		utils.sortPerksByLevel(trio)
		for i, perk in ipairs(trio) do
			result = result .. hl .. file(perkImg.main(perk.techName or perk.name),"33px") .. nl ..
			hl .. link(perk.name) .. nl
			if i < #trio then
				result = result .. ntl .. nl
			end
		end
		result = result .. '|}' .. nl ..
		'</div>' .. nl
	end
	
	result = result .. '</div>' .. nl
	
	mw.log(result)
	--mw.log(mw.dumpObject(perkTable))
	return result
end

return p
Advertisement