Changeset View
Standalone View
binaries/data/mods/public/simulation/components/ProductionQueue.js
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
ProductionQueue.prototype.CalculateEntitiesList = function() | ProductionQueue.prototype.CalculateEntitiesList = function() | ||||
{ | { | ||||
this.entitiesList = []; | this.entitiesList = []; | ||||
if (!this.template.Entities) | if (!this.template.Entities) | ||||
return; | return; | ||||
var string = this.template.Entities._string; | var string = this.template.Entities._string; | ||||
if (!string) | if (!string) | ||||
return; | return; | ||||
Freagarach: Should be gone, we could want to start with the possibility to produce entities, but only after… | |||||
Done Inline Actionsah, good point, thanks. wraitii: ah, good point, thanks. | |||||
// Replace the "{civ}" codes with this entity's civ ID | // Replace the "{civ}" codes with this entity's civ ID | ||||
Not Done Inline ActionsCheck is after below, not sure if that has any influence. Stan: Check is after below, not sure if that has any influence. | |||||
Done Inline Actions? wraitii: ? | |||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
var cmpPlayer = QueryOwnerInterface(this.entity); | var cmpPlayer = QueryOwnerInterface(this.entity); | ||||
if (!cmpPlayer) | if (!cmpPlayer) | ||||
return; | return; | ||||
string = ApplyValueModificationsToEntity("ProductionQueue/Entities/Tokens", string, this.entity); | |||||
var entitiesList = string.replace(/\{civ\}/g, cmpPlayer.GetCiv()).split(/\s+/); | var entitiesList = string.replace(/\{civ\}/g, cmpPlayer.GetCiv()).split(/\s+/); | ||||
// filter out disabled and invalid entities | // filter out disabled and invalid entities | ||||
var disabledEntities = cmpPlayer.GetDisabledTemplates(); | var disabledEntities = cmpPlayer.GetDisabledTemplates(); | ||||
entitiesList = entitiesList.filter( | entitiesList = entitiesList.filter( | ||||
function(v) { return !disabledEntities[v] && cmpTemplateManager.TemplateExists(v); } | function(v) { return !disabledEntities[v] && cmpTemplateManager.TemplateExists(v); } | ||||
); | ); | ||||
Show All 14 Lines | ProductionQueue.prototype.CalculateEntitiesList = function() | ||||
for (let templateName of entitiesList) | for (let templateName of entitiesList) | ||||
this.entitiesList.push(upgradeTemplate(templateName)); | this.entitiesList.push(upgradeTemplate(templateName)); | ||||
for (let item of this.queue) | for (let item of this.queue) | ||||
if (item.unitTemplate) | if (item.unitTemplate) | ||||
item.unitTemplate = upgradeTemplate(item.unitTemplate); | item.unitTemplate = upgradeTemplate(item.unitTemplate); | ||||
}; | }; | ||||
Not Done Inline ActionsDon't use concat, it's very bad. At least two times slower than a foreach with push... cc @bb There seem to be a lot of split and join here, maybe it can be rewritten to be faster. Stan: Don't use concat, it's very bad. At least two times slower than a foreach with push... cc @bb… | |||||
Done Inline ActionsThanks for the note, I'll rewrite wraitii: Thanks for the note, I'll rewrite | |||||
Done Inline ActionsDid a few changes but it seems the tech call is by far the slowest bit. wraitii: Did a few changes but it seems the tech call is by far the slowest bit.
Seems to take around 30… | |||||
Not Done Inline Actions(Multiline?) Freagarach: (Multiline?) | |||||
Done Inline Actionsseems readable like that to me. wraitii: seems readable like that to me. | |||||
/* | /* | ||||
* Returns list of technologies that can be researched by this building. | * Returns list of technologies that can be researched by this building. | ||||
*/ | */ | ||||
ProductionQueue.prototype.GetTechnologiesList = function() | ProductionQueue.prototype.GetTechnologiesList = function() | ||||
{ | { | ||||
if (!this.template.Technologies) | if (!this.template.Technologies) | ||||
return []; | return []; | ||||
var string = this.template.Technologies._string; | var string = this.template.Technologies._string; | ||||
Not Done Inline Actionsinline? Stan: inline? | |||||
Not Done Inline Actions^ Freagarach: ^ | |||||
if (!string) | if (!string) | ||||
return []; | return []; | ||||
var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | ||||
if (!cmpTechnologyManager) | if (!cmpTechnologyManager) | ||||
return []; | return []; | ||||
var cmpPlayer = QueryOwnerInterface(this.entity); | var cmpPlayer = QueryOwnerInterface(this.entity); | ||||
var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | ||||
if (!cmpPlayer || !cmpIdentity) | if (!cmpPlayer || !cmpIdentity) | ||||
Not Done Inline ActionsI guess you can't use the one in Identity? Stan: I guess you can't use the one in Identity? | |||||
Done Inline Actionsnot sure what you mean? We explicitly want the civilisation of the player here, otherwise it's {native}. wraitii: not sure what you mean? We explicitly want the civilisation of the player here, otherwise it's… | |||||
return []; | return []; | ||||
var techs = string.split(/\s+/); | var techs = string.split(/\s+/); | ||||
Not Done Inline ActionsNot sure you need !! unless the value of the array can be falsy? Stan: Not sure you need !! unless the value of the array can be falsy? | |||||
// Remove any technologies that can't be researched by this civ | // Remove any technologies that can't be researched by this civ | ||||
techs = techs.filter(tech => { | techs = techs.filter(tech => { | ||||
let reqs = DeriveTechnologyRequirements(cmpTechnologyManager.GetTechnologyTemplate(tech), cmpPlayer.GetCiv()); | let reqs = DeriveTechnologyRequirements(cmpTechnologyManager.GetTechnologyTemplate(tech), cmpPlayer.GetCiv()); | ||||
return cmpTechnologyManager.CheckTechnologyRequirements(reqs, true); | return cmpTechnologyManager.CheckTechnologyRequirements(reqs, true); | ||||
}); | }); | ||||
var techList = []; | var techList = []; | ||||
▲ Show 20 Lines • Show All 658 Lines • ▼ Show 20 Lines | ProductionQueue.prototype.UnpauseProduction = function() | ||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", g_ProgressInterval, {}); | this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", g_ProgressInterval, {}); | ||||
}; | }; | ||||
ProductionQueue.prototype.OnValueModification = function(msg) | ProductionQueue.prototype.OnValueModification = function(msg) | ||||
{ | { | ||||
// if the promotion requirements of units is changed, | // if the promotion requirements of units is changed, | ||||
// update the entities list so that automatically promoted units are shown | // update the entities list so that automatically promoted units are shown | ||||
// appropriately in the list | // appropriately in the list | ||||
if (msg.component == "Promotion") | if (msg.component == "Promotion" || msg.component == "ProductionQueue") | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | |||||
Done Inline Actionscheck ? Stan: check ? | |||||
Done Inline ActionsAccording to the undying nephalim when an unit with an aura promotes this error is dispmayed a small problem it causes though.... units that promote that have an aura it now shows a huge error at the top of the screen <p class="error">ERROR: Script message handler OnValueModification failed</p> <p class="error">ERROR: Script message handler OnValueModification failed</p> <p class="error">ERROR: Script message handler OnGlobalValueModification failed</p> <p class="error">ERROR: JavaScript error: simulation/components/ProductionQueue.js line 843 TypeError: cmpPlayer is null ProductionQueue.prototype.OnValueModification@simulation/components/ProductionQueue.js:843:15 AuraManager.prototype.RemoveBonus@simulation/components/AuraManager.js:168:1 Auras.prototype.RemoveBonus@simulation/components/Auras.js:436:1 Auras.prototype.RegisterGlobalOwnershipChanged@simulation/components/Auras.js:326:1 AuraManager.prototype.OnGlobalOwnershipChanged@simulation/components/AuraManager.js:271:4</p> <p class="error">ERROR: Script message handler OnGlobalOwnershipChanged failed</p> Stan: According to the undying nephalim when an unit with an aura promotes this error is dispmayed… | |||||
Done Inline ActionsOnly global auras not range ones. Stan: Only global auras not range ones. | |||||
let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); | |||||
cmpGuiInterface.PushNotification({ | |||||
Done Inline ActionsWe should really have a convention for === Maybe @Krinkle has an opinion :) Stan: We should really have a convention for === Maybe @Krinkle has an opinion :) | |||||
"type": "forceselectionrefresh", | |||||
"players": [cmpPlayer.GetPlayerID()] | |||||
}); | |||||
Not Done Inline ActionsThis sounds very expensive if this is done for every OnValueModification of every component that ends up with a tooltip. I suppose we dont want a live-stream of events but only an update each turn? Consider the current game with 1600 units on the map in a 4v4 with 200 pop per player which is the current lobby mainland status quo. elexis: This sounds very expensive if this is done for every `OnValueModification` of every component… | |||||
Done Inline ActionsYou're right, a much better solution is to poll Gui Interface to recreate the selection. wraitii: You're right, a much better solution is to poll Gui Interface to recreate the selection.
I've… | |||||
}; | }; | ||||
ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg) | ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg) | ||||
{ | { | ||||
Not Done Inline Actionswhat does this mean? Silier: what does this mean? | |||||
Done Inline ActionsThe whole selection is dirtied anytime something may change, we don't actually check if something has changed. I'll clarify the comment. wraitii: The whole selection is dirtied anytime something may change, we don't actually check if… | |||||
// if the disabled templates of the player is changed, | // if the disabled templates of the player is changed, | ||||
// update the entities list so that this is reflected there | // update the entities list so that this is reflected there | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue); | Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue); |
Should be gone, we could want to start with the possibility to produce entities, but only after researching a tech. (So starting with an empty entity list.)