Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GuiInterface.js
Show First 20 Lines • Show All 1,821 Lines • ▼ Show 20 Lines | |||||||||||
* @param data.idleClasses Array of class names to include. | * @param data.idleClasses Array of class names to include. | ||||||||||
* @param data.prevUnit The previous idle unit, if calling a second time to iterate through units. May be left undefined. | * @param data.prevUnit The previous idle unit, if calling a second time to iterate through units. May be left undefined. | ||||||||||
* @param data.limit The number of idle units to return. May be left undefined (will return all idle units). | * @param data.limit The number of idle units to return. May be left undefined (will return all idle units). | ||||||||||
* @param data.excludeUnits Array of units to exclude. | * @param data.excludeUnits Array of units to exclude. | ||||||||||
* | * | ||||||||||
* Returns an array of idle units. | * Returns an array of idle units. | ||||||||||
* If multiple classes were supplied, and multiple items will be returned, the items will be sorted by class. | * If multiple classes were supplied, and multiple items will be returned, the items will be sorted by class. | ||||||||||
*/ | */ | ||||||||||
GuiInterface.prototype.FindIdleUnits = function(player, data) | GuiInterface.prototype.FindIdleUnits = function(player, data) | ||||||||||
FreagarachUnsubmitted Not Done Inline Actions
Freagarach: | |||||||||||
{ | { | ||||||||||
let idleUnits = []; | let idleUnits = []; | ||||||||||
// The general case is that only the 'first' idle unit is required; filtering would examine every unit. | // The general case is that only the 'first' idle unit is required; filtering would examine every unit. | ||||||||||
// This loop imitates a grouping/aggregation on the first matching idle class. | // This loop imitates a grouping/aggregation on the first matching idle class. | ||||||||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||||||||
for (let entity of cmpRangeManager.GetEntitiesByPlayer(player)) | for (let entity of cmpRangeManager.GetEntitiesByPlayer(player)) | ||||||||||
{ | { | ||||||||||
let filtered = this.IdleUnitFilter(entity, data.idleClasses, data.excludeUnits); | let filtered = this.IdleUnitFilter(entity, data.idleClasses, data.excludeUnits); | ||||||||||
Show All 32 Lines | |||||||||||
*/ | */ | ||||||||||
GuiInterface.prototype.HasIdleUnits = function(player, data) | GuiInterface.prototype.HasIdleUnits = function(player, data) | ||||||||||
{ | { | ||||||||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||||||||
return cmpRangeManager.GetEntitiesByPlayer(player).some(unit => this.IdleUnitFilter(unit, data.idleClasses, data.excludeUnits).idle); | return cmpRangeManager.GetEntitiesByPlayer(player).some(unit => this.IdleUnitFilter(unit, data.idleClasses, data.excludeUnits).idle); | ||||||||||
}; | }; | ||||||||||
/** | /** | ||||||||||
* Count the number of idle units. | |||||||||||
* | |||||||||||
* @param data.idleClasses Array of class names to include. | |||||||||||
* @param data.excludeUnits Array of units to exclude. | |||||||||||
* | |||||||||||
* Returns the number of idle units | |||||||||||
*/ | |||||||||||
GuiInterface.prototype.CountIdleUnits = function(player, data) | |||||||||||
{ | |||||||||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | |||||||||||
return cmpRangeManager.GetEntitiesByPlayer(player).filter(unit => this.IdleUnitFilter(unit, data.idleClasses, data.excludeUnits).idle).length; | |||||||||||
}; | |||||||||||
/** | |||||||||||
* Whether to filter an idle unit | * Whether to filter an idle unit | ||||||||||
* | * | ||||||||||
* @param unit The unit to filter. | * @param unit The unit to filter. | ||||||||||
* @param idleclasses Array of class names to include. | * @param idleclasses Array of class names to include. | ||||||||||
* @param excludeUnits Array of units to exclude. | * @param excludeUnits Array of units to exclude. | ||||||||||
* | * | ||||||||||
* Returns an object with the following fields: | * Returns an object with the following fields: | ||||||||||
* - idle - true if the unit is considered idle by the filter, false otherwise. | * - idle - true if the unit is considered idle by the filter, false otherwise. | ||||||||||
Show All 17 Lines | GuiInterface.prototype.IdleUnitFilter = function(unit, idleClasses, excludeUnits) | ||||||||||
if (!cmpIdentity) | if (!cmpIdentity) | ||||||||||
return { "idle": false }; | return { "idle": false }; | ||||||||||
let bucket = idleClasses.findIndex(elem => MatchesClassList(cmpIdentity.GetClassesList(), elem)); | let bucket = idleClasses.findIndex(elem => MatchesClassList(cmpIdentity.GetClassesList(), elem)); | ||||||||||
if (bucket == -1 || excludeUnits.indexOf(unit) > -1) | if (bucket == -1 || excludeUnits.indexOf(unit) > -1) | ||||||||||
return { "idle": false }; | return { "idle": false }; | ||||||||||
return { "idle": true, "bucket": bucket }; | return { "idle": true, "bucket": bucket }; | ||||||||||
}; | }; | ||||||||||
Not Done Inline Actions
Silier: | |||||||||||
GuiInterface.prototype.GetTradingRouteGain = function(player, data) | GuiInterface.prototype.GetTradingRouteGain = function(player, data) | ||||||||||
{ | { | ||||||||||
if (!data.firstMarket || !data.secondMarket) | if (!data.firstMarket || !data.secondMarket) | ||||||||||
return null; | return null; | ||||||||||
let cmpMarket = QueryMiragedInterface(data.firstMarket, IID_Market); | let cmpMarket = QueryMiragedInterface(data.firstMarket, IID_Market); | ||||||||||
return cmpMarket && cmpMarket.CalculateTraderGain(data.secondMarket, data.template); | return cmpMarket && cmpMarket.CalculateTraderGain(data.secondMarket, data.template); | ||||||||||
▲ Show 20 Lines • Show All 226 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator