Differential D1108 Diff 5010 ps/trunk/binaries/data/mods/public/simulation/ai/common-api/technology.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/common-api/technology.js
LoadModificationTemplates(); | |||||
var API3 = function(m) | var API3 = function(m) | ||||
{ | { | ||||
/** Wrapper around a technology template */ | /** Wrapper around a technology template */ | ||||
m.Technology = function(allTemplates, templateName) | m.Technology = function(templateName) | ||||
{ | { | ||||
this._templateName = templateName; | this._templateName = templateName; | ||||
let template = allTemplates[templateName]; | let template = TechnologyTemplates.Get(templateName); | ||||
// check if this is one of two paired technologies. | // check if this is one of two paired technologies. | ||||
this._isPair = template.pair !== undefined; | this._isPair = template.pair !== undefined; | ||||
if (this._isPair) | if (this._isPair) | ||||
{ | { | ||||
if (allTemplates[template.pair].top == templateName) | let pairTech = TechnologyTemplates.Get(template.pair); | ||||
this._pairedWith = allTemplates[template.pair].bottom; | this._pairedWith = pairTech.top == templateName ? pairTech.bottom : pairTech.top; | ||||
else | |||||
this._pairedWith = allTemplates[template.pair].top; | |||||
} | } | ||||
// check if it only defines a pair: | // check if it only defines a pair: | ||||
this._definesPair = template.top !== undefined; | this._definesPair = template.top !== undefined; | ||||
this._template = template; | this._template = template; | ||||
this._techTemplates = allTemplates; | |||||
}; | }; | ||||
/** returns generic, or specific if civ provided. */ | /** returns generic, or specific if civ provided. */ | ||||
m.Technology.prototype.name = function(civ) | m.Technology.prototype.name = function(civ) | ||||
{ | { | ||||
if (civ === undefined) | if (civ === undefined) | ||||
return this._template.genericName; | return this._template.genericName; | ||||
if (this._template.specificName === undefined || this._template.specificName[civ] === undefined) | if (this._template.specificName === undefined || this._template.specificName[civ] === undefined) | ||||
return undefined; | return undefined; | ||||
return this._template.specificName[civ]; | return this._template.specificName[civ]; | ||||
}; | }; | ||||
m.Technology.prototype.pairDef = function() | m.Technology.prototype.pairDef = function() | ||||
{ | { | ||||
return this._definesPair; | return this._definesPair; | ||||
}; | }; | ||||
/** in case this defines a pair only, returns the two paired technologies. */ | /** in case this defines a pair only, returns the two paired technologies. */ | ||||
m.Technology.prototype.getPairedTechs = function() | m.Technology.prototype.getPairedTechs = function() | ||||
{ | { | ||||
if (!this._definesPair) | if (!this._definesPair) | ||||
return undefined; | return undefined; | ||||
let techOne = new m.Technology(this._techTemplates, this._template.top); | return [ | ||||
let techTwo = new m.Technology(this._techTemplates, this._template.bottom); | new m.Technology(this._template.top), | ||||
new m.Technology(this._template.bottom) | |||||
return [techOne,techTwo]; | ]; | ||||
}; | }; | ||||
m.Technology.prototype.pair = function() | m.Technology.prototype.pair = function() | ||||
{ | { | ||||
if (!this._isPair) | if (!this._isPair) | ||||
return undefined; | return undefined; | ||||
return this._template.pair; | return this._template.pair; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator