import { Actor , Component , Property } from 'satisfactory-json' ; let actorByPathName = { } ; let componentByPathName = { } ; /**
 * refresh the two dictionaries above that are used to quickly look up actors and components by their path name
 *
 * needs to be called whenever the indices of window.data.actors or window.data.components change
 */ export function refreshActorComponentDictionary ( ) { actorByPathName = { } ; componentByPathName = { } ; if ( window . data === undefined ) return ; for ( let i = 0 ; i < window . data . actors . length ; i ++ ) { const actor = window . data . actors [ i ] ; actorByPathName [ actor . pathName ] = i ; } for ( let i = 0 ; i < window . data . components . length ; i ++ ) { const component = window . data . components [ i ] ; componentByPathName [ component . pathName ] = i ; } } export function getProperty ( actor , propertyName ) { if ( actor . entity !== undefined ) { if ( actor . entity . properties !== undefined ) { for ( let i = 0 ; i < actor . entity . properties . length ; i ++ ) { const property = actor . entity . properties [ i ] ; if ( property . name === propertyName ) { return property ; } } } } return undefined ; } export function getPropertyFromComponent ( component , propertyName ) { if ( component . entity !== undefined ) { if ( component . entity . properties !== undefined ) { for ( let i = 0 ; i < component . entity . properties . length ; i ++ ) { const property = component . entity . properties [ i ] ; if ( property . name === propertyName ) { return property ; } } } } return undefined ; } export function findActorByName ( pathName ) { if ( window . data !== undefined ) { const index = actorByPathName [ pathName ] ; if ( index !== undefined ) { return window . data . actors [ index ] ; } } return undefined ; } export function indexOfActor ( pathName ) { if ( window . data !== undefined ) { const index = actorByPathName [ pathName ] ; return index ; } return - 1 ; } export function findComponentByName ( pathName ) { if ( window . data !== undefined ) { const index = componentByPathName [ pathName ] ; if ( index !== undefined ) { return window . data . components [ index ] ; } } return undefined ; } export function indexOfComponent ( pathName ) { if ( window . data !== undefined ) { const index = componentByPathName [ pathName ] ; return index ; } return - 1 ; } param actor export function isConveyorBelt ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorBeltMk1/Build_ConveyorBeltMk1.Build_ConveyorBeltMk1_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorBeltMk2/Build_ConveyorBeltMk2.Build_ConveyorBeltMk2_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorBeltMk3/Build_ConveyorBeltMk3.Build_ConveyorBeltMk3_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorBeltMk4/Build_ConveyorBeltMk4.Build_ConveyorBeltMk4_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorBeltMk5/Build_ConveyorBeltMk5.Build_ConveyorBeltMk5_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorBeltMk6/Build_ConveyorBeltMk6.Build_ConveyorBeltMk6_C' ) ; } export function isConveyorLift ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorLiftMk1/Build_ConveyorLiftMk1.Build_ConveyorLiftMk1_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorLiftMk2/Build_ConveyorLiftMk2.Build_ConveyorLiftMk2_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorLiftMk3/Build_ConveyorLiftMk3.Build_ConveyorLiftMk3_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorLiftMk4/Build_ConveyorLiftMk4.Build_ConveyorLiftMk4_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/ConveyorLiftMk5/Build_ConveyorLiftMk5.Build_ConveyorLiftMk5_C' ) ; } export function isRailroadTrack ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/Train/Track/Build_RailroadTrack.Build_RailroadTrack_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/Train/Track/Build_RailroadTrackIntegrated.Build_RailroadTrackIntegrated_C' ) ; } export function isPowerLine ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/PowerLine/Build_PowerLine.Build_PowerLine_C' || actor . className === '/Game/FactoryGame/Events/Christmas/Buildings/PowerLineLights/Build_XmassLightsLine.Build_XmassLightsLine_C' ) ; } export function isPipe ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/Pipeline/Build_Pipeline.Build_Pipeline_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/PipeHyper/Build_PipeHyper.Build_PipeHyper_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/PipelineMk2/Build_PipelineMK2.Build_PipelineMK2_C' ) ; } export function isSpline ( actor ) { return isConveyorBelt ( actor ) || isRailroadTrack ( actor ) || isPipe ( actor ) ; } export function isPowerPoleWallDouble ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/PowerPoleWallDouble/Build_PowerPoleWallDouble_Mk2.Build_PowerPoleWallDouble_Mk2_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/PowerPoleWallDouble/Build_PowerPoleWallDouble_Mk3.Build_PowerPoleWallDouble_Mk3_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/PowerPoleWallDouble/Build_PowerPoleWallDouble.Build_PowerPoleWallDouble_C' ) ; } export function isPipeSupport ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/PipeHyperSupport/Build_PipeHyperSupport.Build_PipeHyperSupport_C' || actor . className === '/Game/FactoryGame/Buildable/Factory/PipelineSupport/Build_PipelineSupport.Build_PipelineSupport_C' ) ; } export function isLadder ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Building/Ladder/Build_Ladder.Build_Ladder_C' ) ; } export function isAdjustableJumpPad ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/JumpPad/Build_JumpPadAdjustable.Build_JumpPadAdjustable_C' ) ; } export function isPowerSwitch ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/PowerSwitch/Build_PowerSwitch.Build_PowerSwitch_C' ) ; } export function isLightsControlPanel ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/LightsControlPanel/Build_LightsControlPanel.Build_LightsControlPanel_C' ) ; } export function isFloodlightPole ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/Floodlight/Build_FloodlightPole.Build_FloodlightPole_C' ) ; } export function isFloodlightWall ( actor ) { return ( actor . className === '/Game/FactoryGame/Buildable/Factory/Floodlight/Build_FloodlightWall.Build_FloodlightWall_C' ) ; }