import ENABLED_UPGRADES from "./enabled_upgrades" ; import data from "./data.json" ; import { IDataUpgrade , IAllRaces } from "./interfaces" ; import { iconSortUpgradeFunction } from "./icon_order" ; const ABILITY_TO_UPGRADES = { } ; data . Ability . forEach ( ( ability ) => { const target = ability . target ; if ( typeof target !== "string" ) { const research = target . Research ; if ( research ) { ABILITY_TO_UPGRADES [ ability . id ] = research . upgrade ; } } } ) ; const upgrade_data = { } ; data . Upgrade . forEach ( ( upgrade ) => { upgrade_data [ upgrade . id ] = upgrade ; } ) ; const UPGRADES = [ ] ; const alreadyUsedIds = new Set ( ) ; data . Unit . forEach ( ( unit ) => { unit . abilities . forEach ( ( ability , _index ) => { const upgrade_id = ABILITY_TO_UPGRADES [ ability . ability ] ; if ( ENABLED_UPGRADES . has ( upgrade_id ) && ! alreadyUsedIds . has ( upgrade_id ) ) { alreadyUsedIds . add ( upgrade_id ) ; const upgrade = upgrade_data [ upgrade_id ] ; upgrade . race = unit . race . toLowerCase ( ) as IAllRaces ; UPGRADES . push ( upgrade ) ; } return ; } ) ; } ) ; UPGRADES . sort ( iconSortUpgradeFunction ) ; const UPGRADE_NAMES_BY_RACE = { protoss : new Set ( ) , terran : new Set ( ) , zerg : new Set ( ) , } ; UPGRADES . forEach ( ( item ) => { if ( item . race === "terran" ) { UPGRADE_NAMES_BY_RACE . terran . add ( item . name ) ; } if ( item . race === "protoss" ) { UPGRADE_NAMES_BY_RACE . protoss . add ( item . name ) ; } if ( item . race === "zerg" ) { UPGRADE_NAMES_BY_RACE . zerg . add ( item . name ) ; } } ) ; console . assert ( Object . keys ( UPGRADES ) . length === 89 , `${ Object . keys ( UPGRADES ) . length } is not 89` ) ; export { UPGRADES , UPGRADE_NAMES_BY_RACE } ;