Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Foundation.js
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | Foundation.prototype.GetBuildProgress = function() | ||||
return hitpoints / maxHitpoints; | return hitpoints / maxHitpoints; | ||||
}; | }; | ||||
Foundation.prototype.GetBuildPercentage = function() | Foundation.prototype.GetBuildPercentage = function() | ||||
{ | { | ||||
return Math.floor(this.GetBuildProgress() * 100); | return Math.floor(this.GetBuildProgress() * 100); | ||||
}; | }; | ||||
/** | |||||
* Returns the current builders. | |||||
* | |||||
* @return {number[]} - An array containing the entity IDs of assigned builders. | |||||
*/ | |||||
Foundation.prototype.GetBuilders = function() | |||||
{ | |||||
return Array.from(this.builders.keys()); | |||||
}; | |||||
Foundation.prototype.GetNumBuilders = function() | Foundation.prototype.GetNumBuilders = function() | ||||
{ | { | ||||
return this.builders.size; | return this.builders.size; | ||||
}; | }; | ||||
Foundation.prototype.IsFinished = function() | Foundation.prototype.IsFinished = function() | ||||
{ | { | ||||
return (this.GetBuildProgress() == 1.0); | return (this.GetBuildProgress() == 1.0); | ||||
Show All 26 Lines | if (scaled) | ||||
var cmpStatisticsTracker = QueryPlayerIDInterface(this.owner, IID_StatisticsTracker); | var cmpStatisticsTracker = QueryPlayerIDInterface(this.owner, IID_StatisticsTracker); | ||||
if (cmpStatisticsTracker) | if (cmpStatisticsTracker) | ||||
cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -scaled); | cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -scaled); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Adds a builder to the counter. | * Adds an array of builders. | ||||
* | |||||
* @param {number[]} builders - An array containing the entity IDs of builders to assign. | |||||
*/ | */ | ||||
Foundation.prototype.AddBuilder = function(builderEnt) | Foundation.prototype.AddBuilders = function(builders) | ||||
{ | |||||
for (let builder of builders) | |||||
this.AddSingleBuilder(builder); | |||||
Silier: just wondering if `changed = changed && this.AddSingleBuilder(builder)` would not be better… | |||||
Done Inline ActionsIt won't ever become true then, right? Freagarach: It won't ever become `true` then, right? | |||||
Done Inline Actionsyeah, my bad :) || is correct Silier: yeah, my bad :) || is correct | |||||
Done Inline ActionsOh, sorry my comment was not supposed to be placed ;) Freagarach: Oh, sorry my comment was not supposed to be placed ;) | |||||
Engine.PostMessage(this.entity, MT_FoundationBuildersChanged, { "to": Array.from(this.builders.keys()) }); | |||||
}; | |||||
/** | |||||
* Adds a single builder to this entity. | |||||
* Split because adding multiple builders can reuse the functionality | |||||
* but still send but one message. | |||||
SilierUnsubmitted Done Inline Actionsremove one but Silier: remove one but | |||||
* | |||||
* @param {number} builderEnt - The entity to add. | |||||
Done Inline Actionsideally this should not be here, but instead inform that function calling this needs to send message, or something in way that this one is not sending the message Silier: ideally this should not be here, but instead inform that function calling this needs to send… | |||||
Done Inline ActionsThe message wasn't sent here anymore anyway :) Freagarach: The message wasn't sent here anymore anyway :) | |||||
*/ | |||||
Foundation.prototype.AddSingleBuilder = function(builderEnt) | |||||
{ | { | ||||
if (this.builders.has(builderEnt)) | if (this.builders.has(builderEnt)) | ||||
return; | return; | ||||
Done Inline Actionsjust thinking maybe AddBuilderHelper ? Silier: just thinking maybe AddBuilderHelper ? | |||||
Done Inline ActionsSounds wonky but still better than AddSingleBuilder ;) Freagarach: Sounds wonky but still better than `AddSingleBuilder` ;) | |||||
this.builders.set(builderEnt, Engine.QueryInterface(builderEnt, IID_Builder).GetRate()); | this.builders.set(builderEnt, Engine.QueryInterface(builderEnt, IID_Builder).GetRate()); | ||||
this.totalBuilderRate += this.builders.get(builderEnt); | this.totalBuilderRate += this.builders.get(builderEnt); | ||||
SilierUnsubmitted Done Inline Actionswhile here, reuse Engine.QueryInterface(builderEnt, IID_Builder).GetRate() Silier: while here, reuse Engine.QueryInterface(builderEnt, IID_Builder).GetRate() | |||||
this.SetBuildMultiplier(); | this.SetBuildMultiplier(); | ||||
SilierUnsubmitted Done Inline Actionsthis can be computed once per inserting too, move it to functions calling this one pls Silier: this can be computed once per inserting too, move it to functions calling this one pls | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
cmpVisual.SetVariable("numbuilders", this.builders.size); | cmpVisual.SetVariable("numbuilders", this.builders.size); | ||||
} | |||||
/** | |||||
* Adds a builder to the counter. | |||||
*/ | |||||
Foundation.prototype.AddBuilder = function(builderEnt) | |||||
StanUnsubmitted Done Inline ActionsDocumentation for the param? Stan: Documentation for the param? | |||||
{ | |||||
this.AddSingleBuilder(builderEnt); | |||||
SilierUnsubmitted Done Inline Actionsbetter to return true/false and send message below only when true Silier: better to return true/false and send message below only when true | |||||
Engine.PostMessage(this.entity, MT_FoundationBuildersChanged, { "to": Array.from(this.builders.keys()) }); | Engine.PostMessage(this.entity, MT_FoundationBuildersChanged, { "to": Array.from(this.builders.keys()) }); | ||||
}; | }; | ||||
Foundation.prototype.RemoveBuilder = function(builderEnt) | Foundation.prototype.RemoveBuilder = function(builderEnt) | ||||
{ | { | ||||
if (!this.builders.has(builderEnt)) | if (!this.builders.has(builderEnt)) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
just wondering if changed = changed && this.AddSingleBuilder(builder) would not be better than if here