Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Upgrade.js
Show All 10 Lines | "<element>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Icon' a:help='Icon to show in the GUI'>" + | "<element name='Icon' a:help='Icon to show in the GUI'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Variant' a:help='The name of the variant to switch to when upgrading'>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='Tooltip' a:help='This will be added to the tooltip to help the player choose why to upgrade.'>" + | "<element name='Tooltip' a:help='This will be added to the tooltip to help the player choose why to upgrade.'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Time' a:help='Time required to upgrade this entity, in seconds'>" + | "<element name='Time' a:help='Time required to upgrade this entity, in seconds'>" + | ||||
"<data type='nonNegativeInteger'/>" + | "<data type='nonNegativeInteger'/>" + | ||||
"</element>" + | "</element>" + | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | Upgrade.prototype.Upgrade = function(template) | ||||
this.expendedResources = this.GetResourceCosts(template); | this.expendedResources = this.GetResourceCosts(template); | ||||
if (!cmpPlayer.TrySubtractResources(this.expendedResources)) | if (!cmpPlayer.TrySubtractResources(this.expendedResources)) | ||||
{ | { | ||||
this.expendedResources = {}; | this.expendedResources = {}; | ||||
return false; | return false; | ||||
} | } | ||||
this.upgrading = template; | this.upgrading = template; | ||||
this.SetUpgradeAnimationVariant(template); | |||||
// Prevent cheating | // Prevent cheating | ||||
this.ChangeUpgradedEntityCount(1); | this.ChangeUpgradedEntityCount(1); | ||||
if (this.GetUpgradeTime(template) !== 0) | if (this.GetUpgradeTime(template) !== 0) | ||||
{ | { | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.timer = cmpTimer.SetInterval(this.entity, IID_Upgrade, "UpgradeProgress", 0, UPGRADING_PROGRESS_INTERVAL, { "upgrading": template }); | this.timer = cmpTimer.SetInterval(this.entity, IID_Upgrade, "UpgradeProgress", 0, UPGRADING_PROGRESS_INTERVAL, { "upgrading": template }); | ||||
Show All 13 Lines | Upgrade.prototype.CancelUpgrade = function(owner) | ||||
if (cmpPlayer) | if (cmpPlayer) | ||||
cmpPlayer.AddResources(this.expendedResources); | cmpPlayer.AddResources(this.expendedResources); | ||||
this.expendedResources = {}; | this.expendedResources = {}; | ||||
this.ChangeUpgradedEntityCount(-1); | this.ChangeUpgradedEntityCount(-1); | ||||
this.upgrading = false; | this.upgrading = false; | ||||
this.CancelTimer(); | this.CancelTimer(); | ||||
this.SetElapsedTime(0); | this.SetElapsedTime(0); | ||||
Silier: choice && this.template[choice].Variant | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | |||||
if (!cmpVisual) | |||||
return; | |||||
cmpVisual.SelectAnimation("idle", false, 1.0); | |||||
}; | }; | ||||
Upgrade.prototype.GetUpgradeTime = function(templateArg) | Upgrade.prototype.GetUpgradeTime = function(templateArg) | ||||
{ | { | ||||
let template = this.upgrading || templateArg; | let template = this.upgrading || templateArg; | ||||
let choice = this.upgradeTemplates[template]; | let choice = this.upgradeTemplates[template]; | ||||
if (!choice) | if (!choice) | ||||
Show All 17 Lines | Upgrade.prototype.GetProgress = function() | ||||
return this.GetUpgradeTime() == 0 ? 1 : Math.min(this.elapsedTime / 1000.0 / this.GetUpgradeTime(), 1.0); | return this.GetUpgradeTime() == 0 ? 1 : Math.min(this.elapsedTime / 1000.0 / this.GetUpgradeTime(), 1.0); | ||||
}; | }; | ||||
Upgrade.prototype.SetElapsedTime = function(time) | Upgrade.prototype.SetElapsedTime = function(time) | ||||
{ | { | ||||
this.elapsedTime = time; | this.elapsedTime = time; | ||||
}; | }; | ||||
/** | |||||
Done Inline ActionsNo more parameter. Polakrity: No more parameter.
You forgot to remove Jsdoc. | |||||
* @param {Object} templateArg - The object containing the upgrade data. | |||||
*/ | |||||
Upgrade.prototype.SetUpgradeAnimationVariant = function(templateArg) | |||||
{ | |||||
let template = this.upgrading || templateArg; | |||||
let choice = this.upgradeTemplates[template]; | |||||
Done Inline Actionsmerge the 2 conditions. Polakrity: merge the 2 conditions. | |||||
if (!choice) | |||||
return; | |||||
if (!this.template[choice].Variant) | |||||
return; | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | |||||
if (!cmpVisual) | |||||
return; | |||||
cmpVisual.SelectAnimation(this.template[choice].Variant, false, 1.0); | |||||
}; | |||||
Upgrade.prototype.UpgradeProgress = function(data, lateness) | Upgrade.prototype.UpgradeProgress = function(data, lateness) | ||||
{ | { | ||||
if (this.elapsedTime/1000.0 < this.GetUpgradeTime()) | if (this.elapsedTime/1000.0 < this.GetUpgradeTime()) | ||||
{ | { | ||||
this.SetElapsedTime(this.GetElapsedTime() + UPGRADING_PROGRESS_INTERVAL + lateness); | this.SetElapsedTime(this.GetElapsedTime() + UPGRADING_PROGRESS_INTERVAL + lateness); | ||||
return; | return; | ||||
} | } | ||||
Show All 13 Lines |
Wildfire Games · Phabricator
choice && this.template[choice].Variant