Module:Infobox/Personnage

De Starfield Wiki
Documentation[voir] [modifier] [purger]

Paramétrage du modèle {{Infobox Personnage}}.

local general = require("Module:Infobox/Fonctions")
local localdata = require("Module:Infobox/Localdata")

-- Date à laquelle se déroule le jeu
REFERENCE_DATE = 2330

-- Cherche une année écrite sur 4 chiffres dans une date et la retourne
function get_year(a_date)
	if a_date == nil then
		return nil
	end
	year_i, year_j = string.find(a_date, "%d%d%d%d")
	if year_i == nil then
		return nil
	end
	return tonumber(string.sub(a_date, year_i, year_j))
end

-- Détermination de l'âge du personnage en fonction des dates de naissance
-- et de mort. Si le paramètre "âge" est renseigné, alors il fait foi.
local calculated_age
if localdata["âge"] == nil then
	local birth_year = get_year(localdata["naissance"])
	local death_year = get_year(localdata["mort"])
	if birth_year ~= nil then
		calculated_age = tostring((death_year or REFERENCE_DATE) - birth_year)
	end
end

-- Formate la valeur du paramètre "naissance" en ajoutant
-- l'âge si elle est connue et si le personnage n'est pas mort.
format_birth = function(localdata)
	local birth = localdata["naissance"]
	local death = localdata["mort"]
	local age = localdata["âge"]
	if death == nil then
		if age ~= nil then
			return string.format("%s (%s)", birth, age)
		elseif calculated_age ~= nil then
			return string.format("%s (%s ans)", birth, calculated_age)
		end
	end
	return birth
end

-- Formate la valeur du paramètre "mort" en ajoutant
-- l'âge si elle est connue et si le personnage est mort.
format_death = function(localdata)
	local death = localdata["mort"]
	local age = localdata["âge"]
	if death ~= nil then
		if age ~= nil then
			return string.format("%s (%s)", death, age)
		elseif calculated_age ~= nil then
			return string.format("%s (à %s ans)", death, calculated_age)
		end
	end
	return death
end

return {
    parts = {
        general.title(),
        general.image(),
        {
            type = "table",
            title = "Biographie",
            rows = {
                {type = "row", label = "Type", value = "type"},
                {type = "row", label = "Naissance", value = format_birth},
                {type = "row", label = "Mort", value = format_death},
                {type = "row", label = "Activités", value = "activités"},
                {type = "row", label = "Affiliation", value = "affiliation"},
                {type = "row", label = "Père", value = "père"},
                {type = "row", label = "Mère", value = "mère"},
                {type = "row", label = "Fratrie", value = "fratrie"},
                {type = "row", label = "Conjoint", value = "conjoint"},
                {type = "row", label = "Enfants", value = "enfants"},
                {type = "row", label = "Parentèle", value = "parentèle"},
            },
        },
        {
            type = "table",
            title = "Apparitions",
            rows = {
                {type = "row", label = "Localisation", value = "localisation"},
                {type = "row", label = "Missions", value = "missions"},
            },
        },
        {
            type = "table",
            title = "Caractéristiques",
            rows = {
                {type = "row", label = "Niveau", value = "niveau"},
                {type = "row", label = "Compétences", value = "compétences"},
            },
        },
        {
            type = "table",
            title = "Voix",
            rows = {
	        	{type = "row", label = "Anglaise", value = "voix vo"},
	        	{type = "row", label = "Française", value = "voix vf"},
            },
        },
        general.creation_kit({
        	rows = {
	        	{type = "row", label = "Race", value = "race"},
	        	{type = "row", label = "Voice type", value = "voice type"},
	        	{type = "row", label = "Dialogue", value = "dialogue"},
	        },
        }),
    }
}