Dead by Daylight Wiki
(Utworzono nową stronę "local p = {} local data = require("Module:Datatable") local mathOps = require("Module:MathOps") local utils = require("Module:Utils") local frame = mw.getCurrentFrame()...")
 
Linia 9: Linia 9:
 
function p.getCountOfKillers()
 
function p.getCountOfKillers()
 
return utils.getCount("killer")
 
return utils.getCount("killer")
  +
end
  +
  +
function getKillerIndexById(id)
  +
for i, s in ipairs(killers) do
  +
if s.id == id then return i end
  +
end
  +
return 0
  +
end
  +
  +
function p.resolveKillersTable()
  +
local result = ""
  +
local name
  +
local fileName
  +
  +
result = result .. "<div style=\"color: #fff;\">"
  +
for i, killer in ipairs(killers) do
  +
name = killer.shortName or killer.realName or killer.name
  +
fileName = resolveKillersPortraitFileNameById(killer.id)
  +
  +
result = result .. "<div style=\"display: inline-block; text-align:center; margin: 10px\">[[" .. name .. "]] - " .. killer.name
  +
result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. killer.name .. "]]</div>"
  +
  +
end
  +
result = result .. "</div>"
  +
  +
return result
  +
end
  +
  +
function p.resolveKillersTableMainPage()
  +
local result = ""
  +
local name
  +
local fileName
  +
  +
result = result .. "<div class=\"fpbox\" id=\"fpkiller\" style=\"text-align: center;\">"
  +
result = result .. "<div class=\"heading\">The [[Zabójcy]] [[File:IconHelpLoading killer.png|32px]]</div>"
  +
result = result .. "<div class=\"fplinks\">"
  +
for i, killer in ipairs(killers) do
  +
  +
fileName = resolveKillersPortraitFileNameById(killer.id)
  +
  +
result = result .. "<div class=\"fplink plainlinks image\"><div class=\"box\"><div class=\"row\"><div class=\"cell\">"
  +
result = result .. "<div class=\"image\">[[File:" .. fileName .. ".png|link=" .. killer.name .. "]]</div>"
  +
result = result .. "<div class=\"link\">[[The " .. killer.name .. "]]</div></div></div></div></div>"
  +
end
  +
result = result .. "</div>"
  +
result = result .. "</div>"
  +
  +
return result
  +
end
  +
  +
function resolveKillersPortraitFileNameById(id)
  +
i = getKillerIndexById(id)
  +
local fileConst = "_charPreview_portrait"
  +
local fileName
  +
  +
fileName = getFileNameFromTableById(id)
  +
if not isValidFileName(fileName) then --Szukanie nowych nazw plików
  +
fileName = resolveNewInitialsByIndex(i) .. fileConst
  +
end
  +
if not isValidFileName(fileName) then --Szukanie starych nazw plików
  +
mw.log("File not found. Looking further...")
  +
fileName = getKillersInitialsByIndex(i) .. fileConst
  +
end
  +
if not isValidFileName(fileName) then --Plik nie został znaleziony
  +
fileName = "UnknownKiller" .. fileConst
  +
end
  +
  +
fileName = fileName
  +
mw.log(fileName)
  +
return fileName
  +
end
  +
  +
function isValidFileName(name)
  +
return not (name == "" or not mw.title.new("File:" .. name .. ".png").exists)
  +
end
  +
  +
function getFileNameFromTableById(id)
  +
mw.log(id)
  +
for j, sImage in ipairs(killerImages) do
  +
if sImage.id == id then
  +
return sImage.preview
  +
end
  +
end
  +
return ""
  +
end
  +
  +
function resolveNewInitialsByIndex(i)
  +
if killers[i] == nil then
  +
return ""
  +
end
  +
local k = killers
  +
local initials = getKillersInitialsByIndex(i)
  +
local dlcCodeName =""
  +
if k[i].dlc ~= nil and dlcs[k[i].dlc] ~= nil then
  +
dlcCodeName = getDlcById(k[i].dlc).codeName
  +
end
  +
  +
local dlcInitial = dlcCodeName:match("^(%S).*$") or "A" --A jest dla postaci z podstawowej gry które nie mają DLC albo kryptonimu DLC
  +
  +
mw.log(dlcInitial .. "K " .. initials)
  +
return dlcInitial .. "K " .. initials
  +
end
  +
  +
function getKillersInitialsByIndex(i)
  +
if killers[i] == nil then
  +
return ""
  +
end
  +
  +
local firstLetter, secondLetter
  +
  +
firstLetter, secondLetter = killers[i].name:match("^(%S)(%S).*$") --could be merged but I keep it separated for case of need
  +
  +
return string.upper(firstLetter .. secondLetter)
  +
end
  +
  +
function getDlcById(id)
  +
for _, dlc in ipairs(dlcs) do
  +
if dlc.id == id then return dlc end
  +
end
 
end
 
end
   

Wersja z 14:43, 16 maj 2020


local p = {}
local data = require("Module:Datatable")
local mathOps = require("Module:MathOps")
local utils = require("Module:Utils")
local frame = mw.getCurrentFrame()
local bar = "&#124;" -- code for |
local nl = "\n"

function p.getCountOfKillers()
	return utils.getCount("killer")
end

function getKillerIndexById(id)
	for i, s in ipairs(killers) do
		if s.id == id then return i end
	end
	return 0
end

function p.resolveKillersTable()
	local result = ""
	local name
	local fileName

	result = result .. "<div style=\"color: #fff;\">"
	for i, killer in ipairs(killers) do
		name = killer.shortName or killer.realName or killer.name
		fileName = resolveKillersPortraitFileNameById(killer.id)
		
		result = result .. "<div style=\"display: inline-block; text-align:center; margin: 10px\">[[" .. name .. "]] - " .. killer.name
		result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. killer.name .. "]]</div>"

	end
	result = result .. "</div>"

	return result
end

function p.resolveKillersTableMainPage()
	local result = ""
	local name
	local fileName

	result = result .. "<div class=\"fpbox\" id=\"fpkiller\" style=\"text-align: center;\">"
	result = result .. "<div class=\"heading\">The [[Zabójcy]] [[File:IconHelpLoading killer.png|32px]]</div>"
	result = result .. "<div class=\"fplinks\">"
	for i, killer in ipairs(killers) do
		
		fileName = resolveKillersPortraitFileNameById(killer.id)
		
		result = result .. "<div class=\"fplink plainlinks image\"><div class=\"box\"><div class=\"row\"><div class=\"cell\">"
		result = result .. "<div class=\"image\">[[File:" .. fileName .. ".png|link=" .. killer.name .. "]]</div>"
		result = result .. "<div class=\"link\">[[The " .. killer.name .. "]]</div></div></div></div></div>"
	end
	result = result .. "</div>"
	result = result .. "</div>"

	return result
end

function resolveKillersPortraitFileNameById(id)
	i = getKillerIndexById(id)
	local fileConst = "_charPreview_portrait"
	local fileName
	
	fileName = getFileNameFromTableById(id)
	if not isValidFileName(fileName) then --Szukanie nowych nazw plików
		fileName = resolveNewInitialsByIndex(i) .. fileConst
	end
	if not isValidFileName(fileName) then --Szukanie starych nazw plików
		mw.log("File not found. Looking further...")
		fileName = getKillersInitialsByIndex(i) .. fileConst
	end
	if not isValidFileName(fileName) then --Plik nie został znaleziony
		fileName = "UnknownKiller" .. fileConst
	end
	
	fileName = fileName
	mw.log(fileName)
	return fileName
end

function isValidFileName(name)
	return not (name == "" or not mw.title.new("File:" .. name .. ".png").exists)
end

function getFileNameFromTableById(id)
	mw.log(id)
	for j, sImage in ipairs(killerImages) do
		if sImage.id == id then
			return sImage.preview
		end
	end
	return ""
end

function resolveNewInitialsByIndex(i)
	if killers[i] == nil then
		return ""	
	end
	local k = killers
	local initials = getKillersInitialsByIndex(i)
	local dlcCodeName =""
	if k[i].dlc ~= nil and dlcs[k[i].dlc] ~= nil then
		dlcCodeName = getDlcById(k[i].dlc).codeName
	end
	
	local dlcInitial = dlcCodeName:match("^(%S).*$") or "A" --A jest dla postaci z podstawowej gry które nie mają DLC albo kryptonimu DLC

	mw.log(dlcInitial .. "K " .. initials)
	return dlcInitial .. "K " .. initials
end

function getKillersInitialsByIndex(i)
	if killers[i] == nil then
		return ""	
	end
	
	local firstLetter, secondLetter
	
	firstLetter, secondLetter = killers[i].name:match("^(%S)(%S).*$") --could be merged but I keep it separated for case of need
	
	return string.upper(firstLetter .. secondLetter)
end

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

return p