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 32 Lines | |||||
/** | /** | ||||
* Adds a builder to the counter. | * Adds a builder to the counter. | ||||
*/ | */ | ||||
Foundation.prototype.AddBuilder = function(builderEnt) | Foundation.prototype.AddBuilder = function(builderEnt) | ||||
{ | { | ||||
if (this.builders.has(builderEnt)) | if (this.builders.has(builderEnt)) | ||||
return; | return; | ||||
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 ;) | |||||
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); | ||||
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(); | ||||
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); | ||||
Done Inline Actionsremove one but Silier: remove one but | |||||
Engine.PostMessage(this.entity, MT_FoundationBuildersChanged, { "to": Array.from(this.builders.keys()) }); | Engine.PostMessage(this.entity, MT_FoundationBuildersChanged, { "to": Array.from(this.builders.keys()) }); | ||||
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.RemoveBuilder = function(builderEnt) | Foundation.prototype.RemoveBuilder = function(builderEnt) | ||||
Done Inline ActionsDocumentation for the param? Stan: Documentation for the param? | |||||
{ | { | ||||
if (!this.builders.has(builderEnt)) | if (!this.builders.has(builderEnt)) | ||||
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 | |||||
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.totalBuilderRate -= this.builders.get(builderEnt); | this.totalBuilderRate -= this.builders.get(builderEnt); | ||||
this.builders.delete(builderEnt); | this.builders.delete(builderEnt); | ||||
this.SetBuildMultiplier(); | this.SetBuildMultiplier(); | ||||
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); | ||||
▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
just wondering if changed = changed && this.AddSingleBuilder(builder) would not be better than if here