Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Timer.js
Show All 14 Lines | |||||
* Returns time since the start of the game in milliseconds. | * Returns time since the start of the game in milliseconds. | ||||
*/ | */ | ||||
Timer.prototype.GetTime = function() | Timer.prototype.GetTime = function() | ||||
{ | { | ||||
return this.time; | return this.time; | ||||
}; | }; | ||||
/** | /** | ||||
* Gives the timers belonging to a specific entity. | |||||
* | |||||
Stan: Aren't you returning an object here ?
You could use Array.Filter | |||||
* @param {number} entity - The entity ID of the entity to return the timers for. | |||||
* | |||||
* @return {Object[]} - An array of the timers which the entity has. | |||||
*/ | |||||
Timer.prototype.GetTimers = function(entity) | |||||
{ | |||||
let timers = {}; | |||||
StanUnsubmitted Done Inline ActionsWhy not array then ? Stan: Why not array then ? | |||||
for (let [id, timer] of this.timers) | |||||
if (timer.entity == entity) | |||||
timers[id] = timer; | |||||
return timers; | |||||
}; | |||||
/** | |||||
* Transfers a timer from an entity to a new entity, e.g. when promoting. | |||||
* | |||||
* @param {number} timerID - The timer ID to be transfered. | |||||
* @param {number} newEnt - The entity ID of the entity to which the timer ought to be transferred. | |||||
*/ | |||||
Timer.prototype.TransferTimer = function(timerID, newEnt) | |||||
{ | |||||
for (let [id, timer] of this.timers) | |||||
if (id == timerID) | |||||
timer.entity = newEnt; | |||||
}; | |||||
/** | |||||
* Returns the duration of the latest turn in milliseconds. | * Returns the duration of the latest turn in milliseconds. | ||||
*/ | */ | ||||
Timer.prototype.GetLatestTurnLength = function() | Timer.prototype.GetLatestTurnLength = function() | ||||
{ | { | ||||
return this.turnLength; | return this.turnLength; | ||||
}; | }; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Aren't you returning an object here ?
You could use Array.Filter