Dead by Daylight Wiki
Advertisement
Dead by Daylight Wiki

local p = {}
local data = require("Module:Datatable")
local mathOps = require("Module:MathOps")
local utils = require("Module:Utils")
local str = require("Module:Strings")
local c = utils -- As there is onlny one function relevant to colors I make only alias to utils Module to convenient naming "c - color"
local frame = mw.getCurrentFrame()

local strings = {
	noDLC = "DLC nie został znaleziony w tabeli DLC w [[Module:datatable]]",
	noSpecialTheme = "Nie posiada",
	noSteamLink = "Brak Strony z Sklepem",
	sp = "Strona Sklepu",
	rd = "Data Wydania",
	cat = "Kategoria",
	cost = "Koszt",
	theme = "Motyw Muzyczny",
	chapter = "CHAPTER",
	file = "Plik",
	fd = "dlc.fullDate", --temporary replacement for resolveDateTime
	retracted = "Wycofany",
	dlcLink = "Rozszerzenia do Gry"
}

fileSuffixes = {
		"", --Undefined
		"_main_header", --DLC Image
		" Theme Music" --DLC Theme music
	}

function p.getCallTable(parameter)
	return mw.dumpObject(parameter)
end

function getShortenedFileName(name)
	name = utils.RemoveSpecialCharacters(name)
	return getShortName(name)
end

function getShortName(name)
	if name:match(":") ~= nil then
		return name:match(".*: *(.+)")
	else
		return name
	end
end

function resolveDlcParameter(dlc)
	if dlc == nil then
		return getDlcByName(getShortName(mw.title.getCurrentTitle().text)) or getDlcByName(mw.title.getCurrentTitle().text)
	elseif type(dlc) == "table" then
		if dlc.args[1] == nil then 
			return getDlcByName(getShortName(mw.title.getCurrentTitle().text)) or getDlcByName(mw.title.getCurrentTitle().text) --none parameter, calling from page
		end
		if type(dlc.args[1]) == nil then 
			return getDlcByName(getShortName(mw.title.getCurrentTitle().text))
		elseif type(dlc.args[1]) == "string" then
			if tonumber(dlc.args[1]) == nil then 
				return getDlcByName(dlc.args[1])
			else 
				return getDlcById(tonumber(dlc.args[1]))
			end
		end
	elseif type(dlc) == "string" then
		return getDlcByName(dlc)
	elseif type(dlc) == "number" then
		return getDlcById(dlc)
	end
end

function getDlcByName(name)
	for _, dlcItem in ipairs(dlcs) do
		if name == dlcItem.name then return dlcItem end
	end
end

function getDlcById(id)
	for _, dlcItem in ipairs(dlcs) do
		if id == dlcItem.id then return dlcItem end
	end
end

function p.getCountOfDlcs()
	return utils.getCount("dlc")
end

function p.getCountOfChapters()
	return utils.getCount("chapter")
end

function p.getCountOfParagraphs()
	return utils.getCount("paragraph")
end

function p.getCountOfClothingDlcs()
	return utils.getCount("clothing")
end

function p.getCountOfSoundtracks()
	return utils.getCount("ost")
end

function p.getCountOfCharacterDlcs()
	return utils.getCount("character")
end

function getCountOfCosts(dlc)
	for i, _ in ipairs(dlc.cost) do end
	return i
end

function getCostTable(dlc)
	local result = ""
	
	if type(dlc.cost) == "string" then
		return "| " .. dlc.cost	
	end
	for i, cost in ipairs(dlc.cost) do
		local ccy = getCurrencyById(cost.ccy)
		
		if cost.value == 0 then
			cost.value = "-"
		end
		result = result .. "| " 
		if ccy.gc then
			result = result .. utils.commaFormat(cost.value) .. " " .. frame:expandTemplate{ title = "IconLink", args = { ccy.name, ccy.name, ccy.symbol } } -- #1: calling IconLink template #2: using full template for polish declination ~Yupi
		else
			result = result .. cost.value .. " " .. ccy.symbol -- changed it to work with polish ccy ~Yupi
		end
		if dlc.cost[i + 1] ~= nil then
			result = result .. nl .. ntl .. nl
		end
	end
	
	return result
end

function getCountDlcCosts(dlc)
	if type(dlc.cost) == "string" then return 1 end
	return #dlc.cost
end

function getCurrencyById(id)
	for _, ccyItem in ipairs(ccy) do
		if ccyItem.id == id then return ccyItem end
	end
end

function resolveCurrency(ccy)
	if ccy.gc then
		return 
	else
		
	end
end

function p.resolveThemeMusic() resolveThemeMusic(getDlcById(15)) end --dev remove

--Stranger Things Theme Music.ogg
function resolveThemeMusic(dlc)
	local name = strings.file .. ":" .. getShortenedFileName(dlc.name) .. fileSuffixes[3] --remake it -dev TODO
	mw.log(name)
	mw.log(mw.title.new( name .. ".ogg").exists)
	if mw.title.new( name .. ".mp3").exists then return "[[" .. name .. ".mp3]]" end
	if mw.title.new( name .. ".ogg").exists then return "[[" .. name .. ".ogg]]" end
	
	for i, theme in ipairs(dlcThemes) do
		if theme.id == dlc.id then
			if mw.title.new(strings.file .. ":" .. theme.fileName .. ".mp3").exists then return "[[" .. strings.file .. ":" .. theme.fileName .. ".mp3]]" end
			if mw.title.new(strings.file .. ":" .. theme.fileName .. ".ogg").exists then return "[[" .. strings.file .. ":" .. theme.fileName .. ".ogg]]" end
			break
		end
	end
	return strings.noSpecialTheme
end

function resolveShopLink(dlc)
	if dlc.link ~= nil then
		return "[https://store.steampowered.com/app/" .. dlc.link .. " " .. strings.sp .. "]"
	end
	return strings.noSteamLink
end

function resolveDlcCategory(dlc)
	if dlc.retracted ~= true then
		return dlcCategories[dlc.category]
	else
		return strings.retracted .. " " .. dlcCategories[dlc.category]
	end
end

function p.getImageFileNameByDlc(id) mw.log(getImageFileNameByDlc(getDlcById(id))) end --dev remove

function getImageFileNameByDlc(dlc)
	for _, dlcImage in ipairs(dlcImages) do
		if dlc.id == dlcImage.id then
			return utils.resolveImageName(dlcImage.cover)
		end
	end
	return utils.resolveImageName(utils.resolveFileName(dlc.name) .. fileSuffixes[2])
end

function p.resolveDlcTable(dlc)
	dlc = resolveDlcParameter(dlc)
	if dlc == nil then return "'''" .. frame:expandTemplate{title = "clr", args = { "gold", strings.noDlc}} .. "'''" .. nl end
	local result = ""

	result = result .. "{|class=\"wikitable\" style=\"float:right;\"" .. nl
	result = result .. "|- style=\"font-size: 24px;\"" .. nl
	result = result .. "! width=\"300px\" align=\"center\" colspan=\"2\" | '''" .. dlc.name .. "'''" .. nl
	result = result .. ntl .. nl
	result = result .. "| align=\"center\" width=\"300px\" height=\"50px\" colspan=\"2\" |[[" .. strings.file .. ":" .. getImageFileNameByDlc(dlc) .. "|300px]]" .. nl
	result = result .. ntl .. nl
	result = result .. "| width=\"100px\" | '''" .. strings.rd .. "'''|| width=\"200px\" | " .. dlc.fullDate .. nl --changed because the function doesn't work with polish names ~Yupi
	result = result .. ntl .. nl
	result = result .. "| width=\"100px\" | '''" .. strings.cat .. "'''|| width=\"200px\" | " .. resolveDlcCategory(dlc) .. nl
	result = result .. ntl .. nl
	result = result .. "| width=\"100px\" rowspan = " .. getCountDlcCosts(dlc) .. " | '''" .. strings.cost .. "''' || width=\"200px\" " .. getCostTable(dlc) .. nl
	result = result .. ntl .. nl
	result = result .. "| width=\"100px\" | '''" .. strings.theme .. "'''|| width=\"200px\" |" .. resolveThemeMusic(dlc) .. nl
	result = result .. ntl .. nl
	result = result .. "! width=\"300px\" align=\"center\" colspan=\"2\" | " .. resolveShopLink(dlc) .. nl
	result = result .. "|}"

	mw.log(mw.dumpObject(result))
	return result
end

--DEV
function try(f, catch_f)
	local status, exception = pcall(f)
	if not status then
		catch_f(exception)
	end
end

function p.getListOfDlcChapters()
	local result = "";
	local counter = 1;
	
	for _, dlcItem in ipairs(dlcs) do
		if dlcItem.category == 1 then
			result = result .. "* [[" .. strings.chapter .. " " .. ToRomanNumerals(counter) .. ": " .. dlcItem.name .. "]]" .. nl
			counter = counter + 1
		end
	end
	
	mw.log(result)
	return result
end

function p.resolveDlcTableMainPage()
	local result = ""
	local name
	local fileName
	
	utils.sortDlcByCategory(dlcs)

	result = result .. '<div class="fpbox" id="fpDlcs" style="text-align: center;">'
	result = result .. '<div class="heading">[[' .. strings.dlcLink .. ']]</div>'
	result = result .. '<div class="fplinks">'
	for i, dlc in ipairs(dlcs) do
		if not dlc.skip then
			name = dlc.name or strings.noDLc
			fileName = resolveDlcCapsuleFileNameByDlc(dlc) .. '.jpg'
			--if fileName == "" then
			--	fileName = "UnknownDLC.png"
			--else
			--	fileName = fileName .. '.jpg'
			--end
			
			result = result .. '<div class="fplink dlcMainPageBox plainlinks image"><div class="box"><div class="row"><div class="cell">'
			result = result .. '<div class="image">[[File:' .. fileName .. '|link=' .. name .. ']]</div>'
			result = result .. '<div class="dlcLink link">[[' .. name .. ']]</div></div></div></div></div>'
		end
	end
	result = result .. '</div>'
	result = result .. '</div>'

	return result
end

function resolveDlcCapsuleFileNameByDlc(dlc)
	local fileConst = "_Capsule"
	local fileName
	
	fileName = utils.resolveFileName(dlc.name) .. fileConst
	--if fileName == "" or not utils.isValidFileName(fileName, 'jpg') then 
	--	fileName = ""
	--end
	
	return fileName
end

function getCapsuleFileNameFromTableById(id)
	for j, image in ipairs(dlcCapsuleImages) do
		if image.id == id then
			return image.image
		end
	end
	return nil
end

return p
Advertisement