Differential D2794 Diff 12891 ps/trunk/binaries/data/mods/public/simulation/components/ResourceTrickle.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/ResourceTrickle.js
function ResourceTrickle() {} | function ResourceTrickle() {} | ||||
ResourceTrickle.prototype.Schema = | ResourceTrickle.prototype.Schema = | ||||
"<a:help>Controls the resource trickle ability of the unit.</a:help>" + | "<a:help>Controls the resource trickle ability of the unit.</a:help>" + | ||||
"<element name='Rates' a:help='Trickle Rates'>" + | "<element name='Rates' a:help='Trickle Rates'>" + | ||||
Resources.BuildSchema("nonNegativeDecimal") + | Resources.BuildSchema("nonNegativeDecimal") + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Interval' a:help='Number of miliseconds must pass for the player to gain the next trickle.'>" + | "<element name='Interval' a:help='Number of miliseconds must pass for the player to gain the next trickle.'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>"; | "</element>"; | ||||
ResourceTrickle.prototype.Init = function() | ResourceTrickle.prototype.Init = function() | ||||
{ | { | ||||
this.trickleInterval = +this.template.Interval; | |||||
this.CheckTimer(); | this.CheckTimer(); | ||||
}; | }; | ||||
ResourceTrickle.prototype.GetTimer = function() | ResourceTrickle.prototype.GetInterval = function() | ||||
{ | { | ||||
return +this.template.Interval; | return this.trickleInterval; | ||||
}; | }; | ||||
ResourceTrickle.prototype.GetRates = function() | ResourceTrickle.prototype.GetRates = function() | ||||
{ | { | ||||
return this.rates; | return this.rates; | ||||
}; | }; | ||||
/** | /** | ||||
Show All 33 Lines | ResourceTrickle.prototype.OnValueModification = function(msg) | ||||
this.CheckTimer(); | this.CheckTimer(); | ||||
}; | }; | ||||
ResourceTrickle.prototype.CheckTimer = function() | ResourceTrickle.prototype.CheckTimer = function() | ||||
{ | { | ||||
if (!this.ComputeRates()) | if (!this.ComputeRates()) | ||||
{ | { | ||||
if (this.timer) | if (!this.timer) | ||||
{ | return; | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
cmpTimer.CancelTimer(this.timer); | cmpTimer.CancelTimer(this.timer); | ||||
delete this.timer; | delete this.timer; | ||||
return; | |||||
} | } | ||||
let oldTrickleInterval = this.trickleInterval; | |||||
this.trickleInterval = ApplyValueModificationsToEntity("ResourceTrickle/Interval", +this.template.Interval, this.entity); | |||||
if (this.trickleInterval < 0) | |||||
{ | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
cmpTimer.CancelTimer(this.timer); | |||||
delete this.timer; | |||||
return; | return; | ||||
} | } | ||||
if (this.timer) | if (this.timer) | ||||
{ | |||||
if (this.trickleInterval == oldTrickleInterval) | |||||
return; | |||||
// If the timer wasn't invalidated before (interval <= 0), just update it. | |||||
if (oldTrickleInterval > 0) | |||||
{ | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
cmpTimer.UpdateRepeatTime(this.timer, this.trickleInterval); | |||||
return; | return; | ||||
} | |||||
} | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
let interval = +this.template.Interval; | this.timer = cmpTimer.SetInterval(this.entity, IID_ResourceTrickle, "Trickle", this.trickleInterval, this.trickleInterval, undefined); | ||||
this.timer = cmpTimer.SetInterval(this.entity, IID_ResourceTrickle, "Trickle", interval, interval, undefined); | |||||
}; | }; | ||||
Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle); | Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle); |
Wildfire Games · Phabricator