Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js
Show First 20 Lines • Show All 621 Lines • ▼ Show 20 Lines | g_SelectionPanels.Research = { | ||||
{ | { | ||||
return 10; | return 10; | ||||
}, | }, | ||||
"rowLength": 10, | "rowLength": 10, | ||||
"getItems": function(unitEntStates) | "getItems": function(unitEntStates) | ||||
{ | { | ||||
let ret = []; | let ret = []; | ||||
if (unitEntStates.length == 1) | if (unitEntStates.length == 1) | ||||
return !unitEntStates[0].production || !unitEntStates[0].production.technologies ? ret : | return !unitEntStates[0].researcher || !unitEntStates[0].researcher.technologies ? ret : | ||||
unitEntStates[0].production.technologies.map(tech => ({ | unitEntStates[0].researcher.technologies.map(tech => ({ | ||||
"tech": tech, | "tech": tech, | ||||
"techCostMultiplier": unitEntStates[0].production.techCostMultiplier, | "techCostMultiplier": unitEntStates[0].researcher.techCostMultiplier, | ||||
"researchFacilityId": unitEntStates[0].id, | "researchFacilityId": unitEntStates[0].id, | ||||
"isUpgrading": !!unitEntStates[0].upgrade && unitEntStates[0].upgrade.isUpgrading | "isUpgrading": !!unitEntStates[0].upgrade && unitEntStates[0].upgrade.isUpgrading | ||||
})); | })); | ||||
let sortedEntStates = unitEntStates.sort((a, b) => | let sortedEntStates = unitEntStates.sort((a, b) => | ||||
(!b.upgrade || !b.upgrade.isUpgrading) - (!a.upgrade || !a.upgrade.isUpgrading) || | (!b.upgrade || !b.upgrade.isUpgrading) - (!a.upgrade || !a.upgrade.isUpgrading) || | ||||
(!a.production ? 0 : a.production.queue.length) - (!b.production ? 0 : b.production.queue.length) | (!a.production ? 0 : a.production.queue.length) - (!b.production ? 0 : b.production.queue.length) | ||||
); | ); | ||||
for (let state of sortedEntStates) | for (let state of sortedEntStates) | ||||
{ | { | ||||
if (!state.production || !state.production.technologies) | if (!state.researcher || !state.researcher.technologies) | ||||
continue; | continue; | ||||
// Remove the techs we already have in ret (with the same name and techCostMultiplier) | // Remove the techs we already have in ret (with the same name and techCostMultiplier) | ||||
let filteredTechs = state.production.technologies.filter( | const filteredTechs = state.researcher.technologies.filter( | ||||
tech => tech != null && !ret.some( | tech => tech != null && !ret.some( | ||||
item => | item => | ||||
(item.tech == tech || | (item.tech == tech || | ||||
item.tech.pair && | item.tech.pair && | ||||
tech.pair && | tech.pair && | ||||
item.tech.bottom == tech.bottom && | item.tech.bottom == tech.bottom && | ||||
item.tech.top == tech.top) && | item.tech.top == tech.top) && | ||||
Object.keys(item.techCostMultiplier).every( | Object.keys(item.techCostMultiplier).every( | ||||
k => item.techCostMultiplier[k] == state.production.techCostMultiplier[k]) | k => item.techCostMultiplier[k] == state.researcher.techCostMultiplier[k]) | ||||
)); | )); | ||||
if (filteredTechs.length + ret.length <= this.getMaxNumberOfItems() && | if (filteredTechs.length + ret.length <= this.getMaxNumberOfItems() && | ||||
getNumberOfRightPanelButtons() <= this.getMaxNumberOfItems() * (filteredTechs.some(tech => !!tech.pair) ? 1 : 2)) | getNumberOfRightPanelButtons() <= this.getMaxNumberOfItems() * (filteredTechs.some(tech => !!tech.pair) ? 1 : 2)) | ||||
ret = ret.concat(filteredTechs.map(tech => ({ | ret = ret.concat(filteredTechs.map(tech => ({ | ||||
"tech": tech, | "tech": tech, | ||||
"techCostMultiplier": state.production.techCostMultiplier, | "techCostMultiplier": state.researcher.techCostMultiplier, | ||||
"researchFacilityId": state.id, | "researchFacilityId": state.id, | ||||
"isUpgrading": !!state.upgrade && state.upgrade.isUpgrading | "isUpgrading": !!state.upgrade && state.upgrade.isUpgrading | ||||
}))); | }))); | ||||
} | } | ||||
return ret; | return ret; | ||||
}, | }, | ||||
"hideItem": function(i, rowLength) // Called when no item is found | "hideItem": function(i, rowLength) // Called when no item is found | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 609 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator