Module:Survivors
Jump to navigation
Jump to search
local p = {}
local utils = require("Module:Utils")
local data = require("Module:Datatable" .. utils.lang())
local perksData = mw.loadData("Module:Datatable/Loadout" .. utils.lang())
local perkImg = require("Module:PerkImage")
local str = require("Module:Strings")
local frame = mw.getCurrentFrame()
p.strings = {
survNotFound = "Survivor not found",
name = "Name",
altName = "Other Name(s)",
gender = "Gender",
role = "Role",
origin = "Origin",
dlc = "DLC",
actor = "Voice Actor",
unknownActor = "Undisclosed Voice Actor", --unkown/undisclosed
male = "Male",
female = "Female",
transmale = "Trans Male",
transfemale = "Trans Female",
undefined = "Undefined",
survivors = "Survivors",
menuMusic = "Menu Music",
cost = "Cost",
freeCost = "Free", --this string needs to be same as the string at DLCs that are free
metadata = "Metadata",
--Metadata
charid = "CharID",
themeFilename = "Theme Filename"
}
local strings = p.strings
----------------------------------------------
if utils.lang() ~= cstr.empty and (counter or 0) < 1 then
counter = (counter or 0) + 1
strings = require("Module:Survivors" .. utils.lang()).strings
end
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)
local dlcs = require("Module:DLCs")
local various = require("Module:Various")
charName = utils.resolveParameter(charName, 1, false)
local survivorId = getSurvivorIdByName(charName)
local surv = utils.getCharacterById(survivorId, survivors)
if not surv then return strings.survNotFound end
local result = cstr.empty
surv.dlcList = dlcs.getDlcsByCharacter(surv)
surv.dlc = dlcs.getMainDlc(surv.dlcList) --Main DLC
surv.chapterPackDlc = dlcs.getChapterPackDlc(surv.dlcList) --Chapter for case they contain an info about a discount
surv.isDiscounted = dlcs.isDiscounted(surv.dlcList)
if type(surv) ~= types.table then return utils.resolveParameter(charName) end
result =
'{| class = "infoboxtable charInfoboxTable survivorInfobox"' .. nl ..
ntl ..' class = "infoboxTitle" | ' .. nl ..
'! class = "center bold" colspan = 2 | ' .. ((surv.moniker and the(surv) .. surv.moniker) or surv.shortName or surv.name) .. nl ..
ntl .. nl ..
'! class = "center charInfoboxImage" colspan = 2 | ' .. various.getCharPortrait(surv, nil, false) .. nl ..
ntl .. nl
if surv.moniker ~= nil then
result = result .. tl .. class('titleColumn') .. tl .. strings.name .. dtl .. class('valueColumn') .. tl .. (surv.shortName or surv.name) .. nl .. ntl .. nl
end
if surv.altName ~= nil then
result = result .. tl .. class('titleColumn') .. tl .. strings.altName .. dtl .. class('valueColumn') .. tl .. surv.altName .. nl .. ntl .. nl
end
result = result ..
tl .. class('titleColumn') .. tl .. strings.gender .. dtl .. class('valueColumn') .. tl .. surv.gender .. nl ..
ntl .. nl ..
((surv.role and tl .. class('titleColumn') .. tl .. strings.role .. dtl .. class('valueColumn') .. tl .. surv.role .. nl ..
ntl .. nl) or cstr.empty) ..
tl .. class('titleColumn') .. tl .. strings.origin .. dtl .. class('valueColumn') .. tl .. surv.origin .. nl ..
ntl .. nl
if surv.dlc ~= nil then
result = result .. tl .. class('titleColumn') .. tl .. strings.dlc .. dtl .. class('valueColumn') .. tl .. dlcs.getDlcFullNameByCharacter(surv) .. nl .. ntl .. nl
end
result = result ..
tl .. class('titleColumn') .. tl .. strings.actor .. dtl .. class('valueColumn') .. tl .. (surv.actor or strings.uknownActor) .. nl
if surv.dlc and
(
(not surv.dlc.retracted and (surv.dlc.cost == nil or type(surv.dlc.cost) == types.table or (type(surv.dlc.cost) == types.string and surv.dlc.cost ~= strings.freeCost)))
or (surv.dlc.retracted and surv.isDiscounted)
)
then
local ac = utils.getCcyById(5) --we retrieve the ac and is currency (mainly due to other non-en wikis)
local is = utils.getCcyById(3)
local isCost = (not surv.dlc.licensed and utils.commaFormat(surv.isDiscounted and (surv.chapterPackDlc and surv.chapterPackDlc.discount and data.charISCost - surv.chapterPackDlc.discount * data.charISCost or data.charISCost * 0.5) or data.charISCost) or 0)
local acCost = utils.commaFormat(surv.isDiscounted and (surv.chapterPackDlc and surv.chapterPackDlc.discount and data.charACCost - surv.chapterPackDlc.discount * data.charACCost or data.charACCost * 0.5) or data.charACCost)
result = result .. ntl .. nl ..
tl .. class('titleColumn') .. tl .. strings.cost .. dtl .. class('valueColumn') .. tl ..
((not surv.dlc.licensed and isCost .. space .. utils.IconLink(is.plural or is.name .. "s") .. nl) or cstr.empty) ..
acCost .. space .. utils.IconLink(ac.plural or ac.name .. "s") .. nl
end
local theme, themeSuccess = various.resolveCharacterThemeMusic(surv, true)
if themeSuccess then
result = result .. ntl .. nl ..
tl .. class("titleColumn", "center") .. colspan(2) .. tl .. space .. strings.menuMusic .. nl .. ntl .. nl ..
tl .. class("valueColumn", "center", "soundColumn") .. colspan(2) .. tl .. space .. theme .. nl
end
--Metadata
local metadataNewLine = ntl .. class("metadata") .. nl .. tl .. class("titleColumn") .. tl
result = result ..
ntl .. nl ..
tl .. colspan(2) .. space .. class("metadata") .. tl .. center(b(strings.metadata)) .. nl ..
metadataNewLine .. strings.charid .. dtl .. utils.getCharacterIdentifier(surv) .. nl ..
(surv.theme ~= false and (not themeSuccess and various.shouldHaveTheme(surv) and metadataNewLine .. strings.themeFilename .. dtl .. theme .. nl) or cstr.empty)
result = result ..
'|}'
--mw.log(result)
return result
end
return p