Changeset View
Standalone View
binaries/data/mods/public/simulation/components/ProductionQueue.js
Show All 21 Lines | ProductionQueue.prototype.Schema = | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Technologies' a:help='Space-separated list of technology names that this building can research. When present, the special string \"{civ}\" will be automatically replaced either by the civ code of the building's owner if such a tech exists, or by \"generic\".'>" + | "<element name='Technologies' a:help='Space-separated list of technology names that this building can research. When present, the special string \"{civ}\" will be automatically replaced either by the civ code of the building's owner if such a tech exists, or by \"generic\".'>" + | ||||
"<attribute name='datatype'>" + | "<attribute name='datatype'>" + | ||||
"<value>tokens</value>" + | "<value>tokens</value>" + | ||||
"</attribute>" + | "</attribute>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<optional>" + | |||||
"<element name='AutoQueue' a:help='Enable Auto-Queue feature by default'>" + | |||||
Freagarach: What do you want to achieve with this template value? That autoqueue is on by default? You… | |||||
"<data type='boolean'/>" + | |||||
"</element>" + | |||||
"</optional>" + | |||||
FreagarachUnsubmitted Done Inline ActionsI feel like this part belongs in a version 2: D2658. Freagarach: I feel like this part belongs in a version 2: D2658.
What do you think? | |||||
"<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" + | "<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" + | ||||
Resources.BuildSchema("nonNegativeDecimal", ["time"]) + | Resources.BuildSchema("nonNegativeDecimal", ["time"]) + | ||||
"</element>"; | "</element>"; | ||||
ProductionQueue.prototype.ProgressInterval = 1000; | ProductionQueue.prototype.ProgressInterval = 1000; | ||||
ProductionQueue.prototype.MaxQueueSize = 16; | ProductionQueue.prototype.MaxQueueSize = 16; | ||||
ProductionQueue.prototype.Init = function() | ProductionQueue.prototype.Init = function() | ||||
Show All 20 Lines | ProductionQueue.prototype.Init = function() | ||||
// "id": 1, | // "id": 1, | ||||
// "player": 1, // who paid for this research; we need this to cope with refunds cleanly | // "player": 1, // who paid for this research; we need this to cope with refunds cleanly | ||||
// "technologyTemplate": "example_tech", | // "technologyTemplate": "example_tech", | ||||
// "resources": { "wood": 100, ... }, // resources needed for research | // "resources": { "wood": 100, ... }, // resources needed for research | ||||
// "productionStarted": false, // true iff production has started | // "productionStarted": false, // true iff production has started | ||||
// "timeTotal": 15000, // msecs | // "timeTotal": 15000, // msecs | ||||
// "timeRemaining": 10000, // msecs | // "timeRemaining": 10000, // msecs | ||||
// } | // } | ||||
this.autoqueue = this.template.AutoQueue == "true"; | |||||
}; | }; | ||||
/* | /* | ||||
* Returns list of entities that can be trained by this building. | * Returns list of entities that can be trained by this building. | ||||
*/ | */ | ||||
ProductionQueue.prototype.GetEntitiesList = function() | ProductionQueue.prototype.GetEntitiesList = function() | ||||
{ | { | ||||
return Array.from(this.entitiesMap.values()); | return Array.from(this.entitiesMap.values()); | ||||
}; | }; | ||||
/* | |||||
* Get current Auto-Queue status. | |||||
*/ | |||||
Done Inline ActionsMaybe something like: IsAutoQueueEnabled or IsAutoProducing. Now it sounds like the function returns the items that are automatically produced. Freagarach: Maybe something like: `IsAutoQueueEnabled` or `IsAutoProducing`. Now it sounds like the… | |||||
ProductionQueue.prototype.IsAutoQueueOn = function() | |||||
{ | |||||
return this.autoqueue; | |||||
}; | |||||
/* | |||||
* Turn on Auto-Queue. | |||||
*/ | |||||
ProductionQueue.prototype.TurnAutoQueueOn = function() | |||||
{ | |||||
this.autoqueue = true; | |||||
Done Inline ActionsNo need for the return value. (Also below.) Freagarach: No need for the return value. (Also below.) | |||||
}; | |||||
/* | |||||
* Turn off Auto-Queue. | |||||
*/ | |||||
ProductionQueue.prototype.TurnAutoQueueOff = function() | |||||
{ | |||||
this.autoqueue = false; | |||||
Done Inline Actionsdelete this.autoqueue;? Freagarach: `delete this.autoqueue;`? | |||||
wraitiiUnsubmitted Done Inline ActionsI would prefer autoqueuing wraitii: I would prefer `autoqueuing` | |||||
}; | |||||
/** | /** | ||||
* Calculate the new list of producible entities | * Calculate the new list of producible entities | ||||
* and update any entities currently being produced. | * and update any entities currently being produced. | ||||
*/ | */ | ||||
ProductionQueue.prototype.CalculateEntitiesMap = function() | ProductionQueue.prototype.CalculateEntitiesMap = function() | ||||
{ | { | ||||
// Don't reset the map, it's used below to update entities. | // Don't reset the map, it's used below to update entities. | ||||
if (!this.entitiesMap) | if (!this.entitiesMap) | ||||
this.entitiesMap = new Map(); | this.entitiesMap = new Map(); | ||||
if (!this.template.Entities) | if (!this.template.Entities) | ||||
return; | return; | ||||
Not Done Inline ActionsChanged this, because we don't need to read to the end of the function name to see what it does. Freagarach: Changed this, because we don't need to read to the end of the function name to see what it does. | |||||
let string = this.template.Entities._string; | let string = this.template.Entities._string; | ||||
// Tokens can be added -> process an empty list to get them. | // Tokens can be added -> process an empty list to get them. | ||||
let addedTokens = ApplyValueModificationsToEntity("ProductionQueue/Entities/_string", "", this.entity); | let addedTokens = ApplyValueModificationsToEntity("ProductionQueue/Entities/_string", "", this.entity); | ||||
if (!addedTokens && !string) | if (!addedTokens && !string) | ||||
return; | return; | ||||
addedTokens = addedTokens == "" ? [] : addedTokens.split(/\s+/); | addedTokens = addedTokens == "" ? [] : addedTokens.split(/\s+/); | ||||
▲ Show 20 Lines • Show All 681 Lines • ▼ Show 20 Lines | if (!item.productionStarted) | ||||
{ | { | ||||
cmpPlayer.BlockTraining(); | cmpPlayer.BlockTraining(); | ||||
return; | return; | ||||
} | } | ||||
this.SetAnimation("training"); | this.SetAnimation("training"); | ||||
cmpPlayer.UnBlockTraining(); | cmpPlayer.UnBlockTraining(); | ||||
Engine.PostMessage(this.entity, MT_TrainingStarted, { "entity": this.entity }); | Engine.PostMessage(this.entity, MT_TrainingStarted, { "entity": this.entity }); | ||||
} | } | ||||
if (item.technologyTemplate) | if (item.technologyTemplate) | ||||
{ | { | ||||
Not Done Inline ActionsTo clarify the decision we made. Freagarach: To clarify the decision we made. | |||||
let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | ||||
if (cmpTechnologyManager) | if (cmpTechnologyManager) | ||||
cmpTechnologyManager.StartedResearch(item.technologyTemplate, true); | cmpTechnologyManager.StartedResearch(item.technologyTemplate, true); | ||||
else | else | ||||
warn("Failed to start researching " + item.technologyTemplate + ": No TechnologyManager available."); | warn("Failed to start researching " + item.technologyTemplate + ": No TechnologyManager available."); | ||||
this.SetAnimation("researching"); | this.SetAnimation("researching"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (item.technologyTemplate) | ||||
{ | { | ||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | ||||
if (cmpSoundManager) | if (cmpSoundManager) | ||||
cmpSoundManager.PlaySoundGroup(template.soundComplete, this.entity); | cmpSoundManager.PlaySoundGroup(template.soundComplete, this.entity); | ||||
} | } | ||||
} | } | ||||
time -= item.timeRemaining; | time -= item.timeRemaining; | ||||
if (item.unitTemplate && this.autoqueue) | |||||
this.AddItem(item.unitTemplate, "unit", item.count, item.metadata); | |||||
Done Inline ActionsWe usually don't do this kind of ifs. But we check whether the conditions satisfy with an if and perform an action when it is. if (condition) doX It is a bit easier on the eye :) Freagarach: We usually don't do this kind of `if`s. But we check whether the conditions satisfy with an… | |||||
wraitiiUnsubmitted Done Inline ActionsProbably want a GUI notification of some sort if it fails. wraitii: Probably want a GUI notification of some sort if it fails. | |||||
FreagarachUnsubmitted Done Inline ActionsThere is the infinite resources notification. Freagarach: There is the infinite resources notification. | |||||
FreagarachUnsubmitted Done Inline Actions
s/infinite/insufficient Freagarach: > There is the infinite resources notification.
s/infinite/insufficient | |||||
wraitiiUnsubmitted Done Inline Actionss/infinite/insufficient :p But right never mind that's handled. wraitii: s/infinite/insufficient :p
But right never mind that's handled. | |||||
this.queue.shift(); | this.queue.shift(); | ||||
Engine.PostMessage(this.entity, MT_ProductionQueueChanged, null); | Engine.PostMessage(this.entity, MT_ProductionQueueChanged, null); | ||||
} | } | ||||
if (!this.queue.length) | if (!this.queue.length) | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |
What do you want to achieve with this template value? That autoqueue is on by default? You currently don't use it ;)