Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Identity.js
Show All 10 Lines | Identity.prototype.Schema = | ||||
"<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)'>" + | "<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='Gender' a:help='Unit gender for voices and visual. Choices are male, female or random.'>" + | ||||
Stan: I think the last part is kinda misleading. It could get people to think they cannot do what… | |||||
Done Inline Actions.. can be chosen when Phenotype is random. Silier: .. can be chosen when Phenotype is random. | |||||
"<text/>" + | "<choice>" + | ||||
"<value>male</value>" + | |||||
Not Done Inline ActionsJust wondering, why some choices start with upper case and some with lower case? vladislavbelov: Just wondering, why some choices start with upper case and some with lower case? | |||||
"<value>female</value>" + | |||||
"<value>random</value>" + | |||||
"</choice>" + | |||||
"</element>" + | "</element>" + | ||||
Done Inline ActionsJust a thought: we could make it a choice; either PossiblePhenotypes (which implies a random Phenotype) or a defined Phenotype? Mainly because PossiblePhenotypes has no meaning without a random Phenotype? Freagarach: Just a thought: we could make it a choice; either `PossiblePhenotypes` (which implies a random… | |||||
Done Inline ActionsThat sounds annoying to inherit. If your parent is random phenotype, and a child ends up specifying one, it has to delete the "possible phenotypes" thing. Maybe what one could do is that Phenotype is a list of tokens - if it's just one token it has to be that, otherwise it picks randomly from the list. That might work. wraitii: That sounds annoying to inherit. If your parent is random phenotype, and a child ends up… | |||||
"</optional>" + | "</optional>" + | ||||
Done Inline ActionsI wouldn't repeat the possible choices here and above. wraitii: I wouldn't repeat the possible choices here and above. | |||||
"<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.'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
▲ Show 20 Lines • Show All 58 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.gender = !!this.template.Gender == "random" ? randBool() ? "male" : "female" : this.template.Gender || "male"; // ugly default | |||||
Done Inline ActionsAs elexis said, I think you should define possible genders in the template on top of allowing a specific one, so that we can have space alien stuff with random fictive genders? or even fantasy races. wraitii: As elexis said, I think you should define possible genders in the template on top of allowing a… | |||||
Done Inline Actions
Any help on this would be appreciated :) Freagarach: > Agreed, but without such a list, I cannot randomly choose between them right? Unless there is… | |||||
Done Inline ActionsChange the schema to be something like <Identity> <PossibleGenders datatype="tokens">male female</PossibleGenders> <Gender>random</Gender> </Identity> And then just use PossibleGenders as your list. You can then override it in children templates and all, which is convenient. wraitii: Change the schema to be something like
```
<Identity>
<PossibleGenders datatype="tokens">male… | |||||
Done Inline ActionsPretty sure calling a function without default parameters (param = defaultvalue) without any parameters will trigger some warnings. Stan: Pretty sure calling a function without default parameters (param = defaultvalue) without any… | |||||
Done Inline ActionsIt seems like it is just undefined then, which is right what we want it to be, right? Freagarach: It seems like it is just `undefined` then, which is right what we want it to be, right? | |||||
Done Inline ActionsSince you're only calling this here, I would actually remove the function entirely and just init here with the template value. If future code wants to be able to change phenotypes, it'll add the function then. wraitii: Since you're only calling this here, I would actually remove the function entirely and just… | |||||
Done Inline ActionsOkay, but why remove support? If some mod wants to let entities change phenotype, the function is already here. Freagarach: Okay, but why remove support? If some mod wants to let entities change phenotype, the function… | |||||
Done Inline ActionsMeh, trivial to add imo. wraitii: Meh, trivial to add imo. | |||||
}; | }; | ||||
Identity.prototype.Deserialize = function () | Identity.prototype.Deserialize = function(data) | ||||
{ | { | ||||
this.Init(); | this.Init(); | ||||
this.gender = data.gender; | |||||
}; | }; | ||||
Done Inline ActionsI think you might be able to delete Deserialize() now you're using the default serialiser. wraitii: I think you might be able to delete Deserialize() now you're using the default serialiser. | |||||
Identity.prototype.Serialize = null; // we have no dynamic state to save | Identity.prototype.Serialize = function() | ||||
{ | |||||
return { | |||||
"gender" = this.gender; | |||||
}; | |||||
}; | |||||
Done Inline ActionsI think it'd still work if you just removed the Identity.prototype.Serialize function altogether wraitii: I think it'd still work if you just removed the `Identity.prototype.Serialize` function… | |||||
Done Inline ActionsProbably, but don't we want to serialise as little as possible? Freagarach: Probably, but don't we want to serialise as little as possible? | |||||
Done Inline ActionsIt's not really been a concern of JS code, and it's probably better to auto-serialise since then you won't forget to serialise any newly added variable. wraitii: It's not really been a concern of JS code, and it's probably better to auto-serialise since… | |||||
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() | Identity.prototype.GetGender = function() | ||||
{ | { | ||||
return this.template.Gender || "male"; // ugly default | return this.gender; | ||||
Done Inline ActionsThis is wrong here, pick up random gender in init function. This will return random gender for the same entity every time you call it. Silier: This is wrong here, pick up random gender in init function. This will return random gender for… | |||||
Done Inline ActionsInstead of the "ugly default" it could error out if the template is broken. Why hardcode male and female to begin with? What about space alien stuff with random fictive genders? elexis: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence… | |||||
Done Inline Actions
I found out that also buildings are male,,,
Well the template is not broken when no gender is specified, since it is currently optional in the schema.
Agreed, but without such a list, I cannot randomly choose between them right? Unless there is a way to check in the "Identity.js" which choices are allowed so that this function can choose between all of them (minus the "random")? Freagarach: > I suppose not everything that has an Identity also has a Gender (buildings?)
I found out that… | |||||
}; | }; | ||||
Done Inline ActionsSeems weird to have both this and the below? Do you need to keep this for the sound for now? wraitii: Seems weird to have both this and the below? Do you need to keep this for the sound for now? | |||||
Done Inline ActionsYeah it's only called in binaries/data/mods/public/simulation/components/Sound.js Stan: Yeah it's only called in binaries/data/mods/public/simulation/components/Sound.js | |||||
Identity.prototype.GetRank = function() | Identity.prototype.GetRank = function() | ||||
{ | { | ||||
return this.template.Rank || ""; | return this.template.Rank || ""; | ||||
}; | }; | ||||
Identity.prototype.GetClassesList = function() | Identity.prototype.GetClassesList = function() | ||||
{ | { | ||||
return this.classesList; | return this.classesList; | ||||
}; | }; | ||||
Done Inline ActionsUnused parameter newPhenotype. Also don't hardcode "male" there, I think it's better to have "none" if there is no phenotype defined - after all it's probably unused in the template then. wraitii: Unused parameter `newPhenotype`. Also don't hardcode "male" there, I think it's better to have… | |||||
Done Inline ActionsThe hardcoding of "male" is still a necessity here because the sounds use it. The hardcoding can be removed (by defining a phenotype for every template) in a seperate patch I guess. Freagarach: The hardcoding of "male" is still a necessity here because the sounds use it. The hardcoding… | |||||
Identity.prototype.GetVisibleClassesList = function() | Identity.prototype.GetVisibleClassesList = function() | ||||
{ | { | ||||
return this.visibleClassesList; | return this.visibleClassesList; | ||||
}; | }; | ||||
Identity.prototype.HasClass = function(name) | Identity.prototype.HasClass = function(name) | ||||
Done Inline ActionsI think you could use this as default param. Stan: I think you could use this as default param. | |||||
{ | { | ||||
return this.GetClassesList().indexOf(name) != -1; | return this.GetClassesList().indexOf(name) != -1; | ||||
}; | }; | ||||
Identity.prototype.GetFormationsList = function() | Identity.prototype.GetFormationsList = function() | ||||
{ | { | ||||
if (this.template.Formations && this.template.Formations._string) | if (this.template.Formations && this.template.Formations._string) | ||||
return this.template.Formations._string.split(/\s+/); | return this.template.Formations._string.split(/\s+/); | ||||
Show All 24 Lines |
I think the last part is kinda misleading. It could get people to think they cannot do what they want.