Dead by Daylight Wiki
mNo edit summary
mNo edit summary
Line 3: Line 3:
 
--local data = require("Module:Datatable")
 
--local data = require("Module:Datatable")
 
local dataPerks = require("Module:Datatable/Perks")
 
local dataPerks = require("Module:Datatable/Perks")
  +
local utils = require("Module:Utils")
   
 
local bar = "|" -- code for |
 
local bar = "|" -- code for |
Line 9: Line 10:
   
 
local strings = {
 
local strings = {
  +
perkValuesNotFound = "The Values for the perk wasn't found"
 
}
 
}
   
Line 48: Line 50:
 
end
 
end
   
function subValues(desc)
+
function pl(id, tripplet)
  +
--local page = mw.title.getCurrentTitle().text
local pl = desc:gsub("#pl%((%d)%)", "PL Detected: " .. "%1")
 
  +
--if id == nil then id = ":empty:" end
return pl
 
  +
mw.log(tripplet)
  +
for _,perk in ipairs(perks) do
  +
if perk.id == id then
  +
local index = 1 + (tripplet - 1 * 3) --tripplet is an offset, +1 is indexing from 1 in LUA, * 3 is because every values are grouped by 3 values
  +
return utils.clr(perk.values[index], perk.baseLevel) .. "/" .. utils.clr(perk.values[index + 1], perk.baseLevel + 1) .. "/" .. utils.clr(perk.values[index + 2], perk.baseLevel + 2)
  +
end
  +
end
  +
return "'''" .. strings.perkValuesNotFound .. "''"
  +
end
  +
  +
function subValues(perkDesc)
  +
local result
  +
for m in perkDesc.desc[1]:gmatch("#pl%((%d)%)") do--pl(perkDesc.id, "%1")) --TODO the first index shouldn't be hardcoded due to history log (if the description will be copied, then it won't be the first)
  +
mw.log(mw.dumpObject(m))
 
result = perkDesc.desc[1]:gsub("#pl%((%d)%)", pl(perkDesc.id, m))
  +
mw.log(result)
  +
end
  +
--mw.log("PL: " .. pl)
 
return result
 
end
 
end
   
Line 58: Line 79:
 
for _, perkDesc in ipairs(perkDescription) do
 
for _, perkDesc in ipairs(perkDescription) do
 
if perkDesc.id == id then
 
if perkDesc.id == id then
mw.log(subValues(perkDesc.desc[1]))
+
mw.log(subValues(perkDesc))
return subValues(perkDesc.desc[1])
+
return subValues(perkDesc)
 
end
 
end
 
end
 
end

Revision as of 20:29, 28 August 2020


local p = {}
local frame = mw.getCurrentFrame()
--local data = require("Module:Datatable")
local dataPerks = require("Module:Datatable/Perks")
local utils = require("Module:Utils")

local bar = "|" -- code for |
local nl = "\n"
local ntl = "|-" -- new table line

local strings = {
	perkValuesNotFound = "The Values for the perk wasn't found"
}

function getUnusedPerksCount()
	local result = 0
	
	for _, perk in ipairs(perks) do
		if perk.unused == true then result = result + 1 end
	end

	return result
end

function getCommonPerksCount()
	local result = 0
	
	for _, perk in ipairs(perks) do
		if perk.character == nil and perk.unused ~= true then result = result + 1 end
	end
	
	return result
end

local _unusedPerksCount = getUnusedPerksCount()
local _commonPerksCount = getCommonPerksCount()
local _uniquePerksCount = table.getn(perks) - _unusedPerksCount - _commonPerksCount


function p.getPerksCount()
	return _uniquePerksCount + _commonPerksCount
end

function ResolveIntParam(param)
	if type(param) == "table" and param.args[1] ~= nil then
		return tonumber(param.args[1])
	else
		return param
	end
end

function pl(id, tripplet)
	--local page = mw.title.getCurrentTitle().text
	--if id == nil then id = ":empty:" end
	mw.log(tripplet)
	for _,perk in ipairs(perks) do
		if perk.id == id then
			local index = 1 + (tripplet - 1 * 3) --tripplet is an offset, +1 is indexing from 1 in LUA, * 3 is because every values are grouped by 3 values
			return utils.clr(perk.values[index], perk.baseLevel) .. "/" .. utils.clr(perk.values[index + 1], perk.baseLevel + 1) .. "/" .. utils.clr(perk.values[index + 2], perk.baseLevel + 2)
		end
	end
	return "'''" .. strings.perkValuesNotFound .. "''"
end

function subValues(perkDesc)
	local result
	for m in perkDesc.desc[1]:gmatch("#pl%((%d)%)") do--pl(perkDesc.id, "%1")) --TODO the first index shouldn't be hardcoded due to history log (if the description will be copied, then it won't be the first)
		mw.log(mw.dumpObject(m))
		result = perkDesc.desc[1]:gsub("#pl%((%d)%)", pl(perkDesc.id, m))
		mw.log(result)
	end
	--mw.log("PL: " .. pl)
	return result
end

function p.getPerkDescription(id)
	id = ResolveIntParam(id)
	
	for _, perkDesc in ipairs(perkDescription) do
		if perkDesc.id == id then
			mw.log(subValues(perkDesc))
			return subValues(perkDesc)
		end
	end
end

function p.getPerkTeachableDescription(id)
	id = ResolveIntParam(id)
	
	for _, perkDesc in ipairs(perkDescription) do
		if perkDesc.id == id then
			mw.log(perkDesc.teachDesc[1])
			return perkDesc.teachDesc[1]
		end
	end
end

return p