Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GuiInterface.js
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | GuiInterface.prototype.GetEntityState = function(player, ent) | |||||||||||
let cmpPack = Engine.QueryInterface(ent, IID_Pack); | let cmpPack = Engine.QueryInterface(ent, IID_Pack); | |||||||||||
if (cmpPack) | if (cmpPack) | |||||||||||
ret.pack = { | ret.pack = { | |||||||||||
"packed": cmpPack.IsPacked(), | "packed": cmpPack.IsPacked(), | |||||||||||
"progress": cmpPack.GetProgress() | "progress": cmpPack.GetProgress() | |||||||||||
}; | }; | |||||||||||
let cmpPopulation = Engine.QueryInterface(ent, IID_Population); | ||||||||||||
if (cmpPopulation) | ||||||||||||
ret.population = { | ||||||||||||
FreagarachUnsubmitted Done Inline Actions
Freagarach: | ||||||||||||
"bonus": cmpPopulation.GetPopBonus() | ||||||||||||
}; | ||||||||||||
let cmpUpgrade = Engine.QueryInterface(ent, IID_Upgrade); | let cmpUpgrade = Engine.QueryInterface(ent, IID_Upgrade); | |||||||||||
if (cmpUpgrade) | if (cmpUpgrade) | |||||||||||
ret.upgrade = { | ret.upgrade = { | |||||||||||
"upgrades": cmpUpgrade.GetUpgrades(), | "upgrades": cmpUpgrade.GetUpgrades(), | |||||||||||
"progress": cmpUpgrade.GetProgress(), | "progress": cmpUpgrade.GetProgress(), | |||||||||||
"template": cmpUpgrade.GetUpgradingTo(), | "template": cmpUpgrade.GetUpgradingTo(), | |||||||||||
"isUpgrading": cmpUpgrade.IsUpgrading() | "isUpgrading": cmpUpgrade.IsUpgrading() | |||||||||||
}; | }; | |||||||||||
▲ Show 20 Lines • Show All 870 Lines • ▼ Show 20 Lines | ||||||||||||
* }, | * }, | |||||||||||
* ...] | * ...] | |||||||||||
* 'cost': { The total cost required for constructing all the pieces as listed above. | * 'cost': { The total cost required for constructing all the pieces as listed above. | |||||||||||
* 'food': ..., | * 'food': ..., | |||||||||||
* 'wood': ..., | * 'wood': ..., | |||||||||||
* 'stone': ..., | * 'stone': ..., | |||||||||||
* 'metal': ..., | * 'metal': ..., | |||||||||||
* 'population': ..., | * 'population': ..., | |||||||||||
* 'populationBonus': ..., | ||||||||||||
* } | * } | |||||||||||
* } | * } | |||||||||||
* | * | |||||||||||
* @param cmd.wallSet Object holding the set of wall piece template names. Set to an empty value to clear the preview. | * @param cmd.wallSet Object holding the set of wall piece template names. Set to an empty value to clear the preview. | |||||||||||
* @param cmd.start Starting point of the wall segment being created. | * @param cmd.start Starting point of the wall segment being created. | |||||||||||
* @param cmd.end (Optional) Ending point of the wall segment being created. If not defined, it is understood that only | * @param cmd.end (Optional) Ending point of the wall segment being created. If not defined, it is understood that only | |||||||||||
* the starting point of the wall is available at this time (e.g. while the player is still in the process | * the starting point of the wall is available at this time (e.g. while the player is still in the process | |||||||||||
* of picking a starting point), and that therefore only the first entity in the wall (a tower) should be | * of picking a starting point), and that therefore only the first entity in the wall (a tower) should be | |||||||||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | GuiInterface.prototype.SetWallPlacementPreview = function(player, cmd) | |||||||||||
// Clear the single-building preview entity (we'll be rolling our own). | // Clear the single-building preview entity (we'll be rolling our own). | |||||||||||
this.SetBuildingPlacementPreview(player, { "template": "" }); | this.SetBuildingPlacementPreview(player, { "template": "" }); | |||||||||||
// -------------------------------------------------------------------------------- | // -------------------------------------------------------------------------------- | |||||||||||
// Calculate wall placement and position preview entities. | // Calculate wall placement and position preview entities. | |||||||||||
let result = { | let result = { | |||||||||||
"pieces": [], | "pieces": [], | |||||||||||
"cost": { "population": 0, "populationBonus": 0, "time": 0 } | "cost": { "population": 0, "time": 0 } | |||||||||||
}; | }; | |||||||||||
for (let res of Resources.GetCodes()) | for (let res of Resources.GetCodes()) | |||||||||||
result.cost[res] = 0; | result.cost[res] = 0; | |||||||||||
let previewEntities = []; | let previewEntities = []; | |||||||||||
if (end.pos) | if (end.pos) | |||||||||||
// See helpers/Walls.js. | // See helpers/Walls.js. | |||||||||||
previewEntities = GetWallPlacement(this.placementWallEntities, wallSet, start, end); | previewEntities = GetWallPlacement(this.placementWallEntities, wallSet, start, end); | |||||||||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | if (allPiecesValid && !entInfo.excludeFromResult) | |||||||||||
"angle": entInfo.angle, | "angle": entInfo.angle, | |||||||||||
}); | }); | |||||||||||
this.placementWallLastAngle = entInfo.angle; | this.placementWallLastAngle = entInfo.angle; | |||||||||||
// Grab the cost of this wall piece and add it up (note; preview entities don't have their Cost components | // Grab the cost of this wall piece and add it up (note; preview entities don't have their Cost components | |||||||||||
// copied over, so we need to fetch it from the template instead). | // copied over, so we need to fetch it from the template instead). | |||||||||||
// TODO: We should really use a Cost object or at least some utility functions for this, this is mindless | // TODO: We should really use a Cost object or at least some utility functions for this, this is mindless | |||||||||||
// boilerplate that's probably duplicated in tons of places. | // boilerplate that's probably duplicated in tons of places. | |||||||||||
for (let res of Resources.GetCodes().concat(["population", "populationBonus", "time"])) | for (let res of Resources.GetCodes().concat(["population", "time"])) | |||||||||||
result.cost[res] += tplData.cost[res]; | result.cost[res] += tplData.cost[res]; | |||||||||||
} | } | |||||||||||
let canAfford = true; | let canAfford = true; | |||||||||||
let cmpPlayer = QueryPlayerIDInterface(player, IID_Player); | let cmpPlayer = QueryPlayerIDInterface(player, IID_Player); | |||||||||||
if (cmpPlayer && cmpPlayer.GetNeededResources(result.cost)) | if (cmpPlayer && cmpPlayer.GetNeededResources(result.cost)) | |||||||||||
canAfford = false; | canAfford = false; | |||||||||||
▲ Show 20 Lines • Show All 434 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator