Documentation for this module may be created at Module:IntroSentence/Player/doc
local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_map = require("Module:MapUtil")
local util_sentence = require("Module:SentenceUtil")
local util_table = require('Module:TableUtil')
local util_text = require("Module:TextUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require('Module:i18nUtil')
local PlayerPronunciations = require('Module:PlayerPronunciations')
local DisambigList = require('Module:IntroSentence/DisambigList').main
local CompoundRole = require('Module:CompoundRole')
local m_team = require('Module:Team')
local h = {}
local p = {}
function p.main(data, sentenceType)
i18n.init('IntroSentence/Player')
return h.makeOutput(data, sentenceType)
end
function h.makeOutput(data, sentenceType)
local tbl = {
h.getSentence(data, sentenceType),
DisambigList(data.id, 'Player'),
}
return util_table.concat(tbl, '\n\n')
end
function h.getSentence(data, sentenceType)
local replacements = {
PLAYER_ENTIRE_NAME = i18n.default('playerEntireName'),
FIRSTNAME = data.firstname,
ID = data.id and i18n.default('id', data.id) or '',
LASTNAME = data.lastname,
PRONUNCIATION = PlayerPronunciations.getDataAndReturnPlaceholder(),
NATIVENAME = h.getNativeName(data),
PLAYER = i18n.default(data.ispersonality and 'personality' or 'player'),
CURRENTLY = i18n.default(h.isCurrent(data) and 'currently' or 'previously'),
IS_FOR_A_PLAYER = i18n.default(h.isActive(data) and 'is_present' or 'is_past'),
IS_TENSE = i18n.default(h.isCurrent(data) and 'is_present' or 'is_past'),
PREDICATE = h.getPredicate(data),
TEAM_LIST = h.getTeamList(data),
RETIRED = data.isretired and i18n.default('retired') or '',
}
return util_sentence.makeReplacements(data.sentence or i18n.default('sentence' .. sentenceType), replacements)
end
function h.getNativeName(data)
if not data.nativename then return '' end
return i18n.default(
'nativeName',
data.namealphabet or i18n.default('native'),
data.nativename
)
end
function h.isActive(data)
-- maybe add support if retired too
return not data.died
end
function h.isCurrent(data)
if data.lastteampresent then return true end
if data.teamStr then return true end
return false
end
function h.getPredicate(data)
if data.lastteam == 'Suspended' then
return i18n.default('predicateSuspended')
elseif data.lastteam or h.hasAnyTeamList(data) then
return i18n.default('predicateStandard')
end
return ''
end
function h.hasAnyTeamList(data)
if not data.currentTeamList then return false end
if #data.currentTeamList > 0 then return true end
return #data.currentTeamList.last > 0
end
function h.getTeamList(data)
if data.hasAutoTeams then
return h.getAutoTeamList(data.currentTeamList)
end
return h.getLegacyTeamList(data)
end
function h.getAutoTeamList(currentTeamList)
return util_table.printList(
util_map.copy(
h.selectTeamList(currentTeamList),
h.makeTeamDisplay
)
)
end
function h.selectTeamList(currentTeamList)
if #currentTeamList > 0 then
return currentTeamList
end
return { currentTeamList.last }
end
function h.makeTeamDisplay(tbl)
return i18n.default(
'roleListItem',
h.getRoleForDisplay(tbl) or i18n.default('staff'),
m_team.plainlinked(tbl.team)
)
end
function h.getRoleForDisplay(tbl)
if type(tbl.role) == 'table' then
return tbl.role:sentence()
end
-- idk how sub/trainee status should be determined here
-- like really this case shouldn't exist anymore
-- im not sure how it's possible
-- but i think it was erroring without it...?
local compoundRole = CompoundRole(tbl.role)
return compoundRole:sentence()
end
function h.getLegacyTeamList(data)
return h.getLegacyFirstTeam(data) .. h.getLegacyOtherTeams(data)
end
function h.getLegacyFirstTeam(data)
return i18n.default(
'roleListItem',
data.role:sentence() or '',
m_team.plainlinked(data.teamStr or data.lastteam)
)
end
function h.getLegacyOtherTeams(data)
if not data.team2 then return '' end
return i18n.default(
'also_staff',
h.addOtherTeams(data)
)
end
function h.addOtherTeams(data)
local teamlist = {}
local i = 2
while data['team' .. i] do
teamlist[#teamlist+1] = m_team.plainlinked(data['team' .. i])
i = i + 1
end
return util_table.printList(teamlist)
end
return p