Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Identity.js
Show All 11 Lines | "<element name='Civ' a:help='Civilisation that this unit is primarily associated with, typically a 4-letter code. Choices include: gaia (world objects), athen (Athenians), brit (Britons), cart (Carthaginians), gaul (Gauls), iber (Iberians), kush (Kushites), mace (Macedonians), maur (Mauryas), pers (Persians), ptol (Ptolemies), rome (Romans), sele (Seleucids), spart (Spartans)'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Lang' a:help='Unit language for voices'>" + | "<element name='Lang' a:help='Unit language for voices'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Gender' a:help='Unit gender for voices. Choices includes male or female.'>" + | "<element name='PossiblePhenotypes' a:help='Optional list of space-separated phenotypes which can be chosen between when Phenotype is random.'>" + | ||||
"<attribute name='datatype'>" + | |||||
"<value>tokens</value>" + | |||||
"</attribute>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='Phenotype' a:help='Unit phenotype for voices and visual. Random will choose between the phenotypes specified in PossiblePhenotypes.'>" + | |||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<element name='GenericName' a:help='Generic English-language name for this class of unit.'>" + | "<element name='GenericName' a:help='Generic English-language name for this class of unit.'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='SpecificName' a:help='Specific native-language name for this unit type.'>" + | "<element name='SpecificName' a:help='Specific native-language name for this unit type.'>" + | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | Identity.prototype.Schema = | ||||
"<element name='Undeletable' a:help='Prevent players from deleting this entity.'>" + | "<element name='Undeletable' a:help='Prevent players from deleting this entity.'>" + | ||||
"<data type='boolean'/>" + | "<data type='boolean'/>" + | ||||
"</element>"; | "</element>"; | ||||
Identity.prototype.Init = function() | Identity.prototype.Init = function() | ||||
{ | { | ||||
this.classesList = GetIdentityClasses(this.template); | this.classesList = GetIdentityClasses(this.template); | ||||
this.visibleClassesList = GetVisibleIdentityClasses(this.template); | this.visibleClassesList = GetVisibleIdentityClasses(this.template); | ||||
this.SetPhenotype(); | |||||
}; | }; | ||||
Identity.prototype.Deserialize = function () | Identity.prototype.Deserialize = function(data) | ||||
{ | { | ||||
this.Init(); | this.Init(); | ||||
this.phenotype = data.phenotype; | |||||
}; | }; | ||||
Identity.prototype.Serialize = null; // we have no dynamic state to save | Identity.prototype.Serialize = function() | ||||
{ | |||||
return { | |||||
"phenotype": this.phenotype | |||||
}; | |||||
}; | |||||
Identity.prototype.GetCiv = function() | Identity.prototype.GetCiv = function() | ||||
{ | { | ||||
return this.template.Civ; | return this.template.Civ; | ||||
}; | }; | ||||
Identity.prototype.GetLang = function() | Identity.prototype.GetLang = function() | ||||
{ | { | ||||
return this.template.Lang || "greek"; // ugly default | return this.template.Lang || "greek"; // ugly default | ||||
}; | }; | ||||
Identity.prototype.GetGender = function() | /** | ||||
* Get a list of possible Phenotypes. | |||||
* @return {string[]} A list of possible phenotypes. | |||||
*/ | |||||
Identity.prototype.GetPossiblePhenotypes = function() | |||||
{ | |||||
return !!this.template.PossiblePhenotypes ? this.template.PossiblePhenotypes._string.split(/\s+/) : []; | |||||
}; | |||||
/** | |||||
* Set a (new) Phenotype. | |||||
* @param {string} newPhenotype - The phenotype which the entity has to become. | |||||
*/ | |||||
Identity.prototype.SetPhenotype = function(newPhenotype) | |||||
{ | |||||
if (newPhenotype) | |||||
this.phenotype = newPhenotype; | |||||
else if (this.template.Phenotype) | |||||
this.phenotype = this.template.Phenotype == "random" ? pickRandom(this.GetPossiblePhenotypes()) : this.template.Phenotype; | |||||
}; | |||||
/** | |||||
* Get the current Phenotype. | |||||
* @return {string} The current phenotype. | |||||
*/ | |||||
Identity.prototype.GetPhenotype = function() | |||||
{ | { | ||||
return this.template.Gender || "male"; // ugly default | return this.phenotype; | ||||
}; | }; | ||||
Identity.prototype.GetRank = function() | Identity.prototype.GetRank = function() | ||||
{ | { | ||||
return this.template.Rank || ""; | return this.template.Rank || ""; | ||||
}; | }; | ||||
Identity.prototype.GetClassesList = function() | Identity.prototype.GetClassesList = function() | ||||
Show All 33 Lines | Identity.prototype.GetGenericName = function() | ||||
return this.template.GenericName; | return this.template.GenericName; | ||||
}; | }; | ||||
Identity.prototype.IsUndeletable = function() | Identity.prototype.IsUndeletable = function() | ||||
{ | { | ||||
return this.template.Undeletable == "true"; | return this.template.Undeletable == "true"; | ||||
}; | }; | ||||
/** | |||||
* Get the visual actor by replacing any tag. | |||||
* @return {string} - Location of the visual actor file. | |||||
*/ | |||||
// ToDo: Ought to be moved to its own component. | |||||
Identity.prototype.GetVisualActor = function() | |||||
{ | |||||
let cmpVisualActor = Engine.QueryInterface(this.entity, IID_Visual); | |||||
if (!cmpVisualActor) | |||||
return; | |||||
let baseVisualActor = cmpVisualActor.GetBaseVisualActor(); | |||||
let phenotype = this.GetPhenotype(); | |||||
let visualActor = baseVisualActor.replace(/\{phenotype\}/g, phenotype); | |||||
return visualActor; | |||||
}; | |||||
Engine.RegisterComponentType(IID_Identity, "Identity", Identity); | Engine.RegisterComponentType(IID_Identity, "Identity", Identity); |
Wildfire Games · Phabricator