import { keepTrackApi } from '../api/keepTrackApi' ; import { CatalogManager , Colors , SatObject } from '../api/keepTrackTypes' ; import { ageOfElsetRules } from './ruleSets/ageOfElset' ; import { apogeeRules } from './ruleSets/apogee' ; import { countriesRules } from './ruleSets/countries' ; import { defaultRules } from './ruleSets/default' ; import { geoRules } from './ruleSets/geo' ; import { groupRules } from './ruleSets/group' ; import { leoRules } from './ruleSets/leo' ; import { lostobjectsRules } from './ruleSets/lostobjects' ; import { onlyFovRules } from './ruleSets/onlyFov' ; import { rcsRules } from './ruleSets/rcs' ; import { smallsatsRules } from './ruleSets/smallsat' ; import { sunlightRules } from './ruleSets/sunlight' ; import { velocityRules } from './ruleSets/velocity' ; export interface ObjectTypeFlags { payload : boolean ; radarData : boolean ; rocketBody : boolean ; debris : boolean ; facility : boolean ; sensor : boolean ; missile : boolean ; missileInview : boolean ; trusat : boolean ; inFOV : boolean ; inViewAlt : boolean ; starLow : boolean ; starMed : boolean ; starHi : boolean ; satLEO : boolean ; satGEO : boolean ; satLow : boolean ; satMed : boolean ; satHi : boolean ; satSmall : boolean ; rcsSmall : boolean ; rcsMed : boolean ; rcsLarge : boolean ; rcsUnknown : boolean ; velocitySlow : boolean ; velocityMed : boolean ; velocityFast : boolean ; ageNew : boolean ; ageMed : boolean ; ageOld : boolean ; ageLost : boolean ; countryUS : boolean ; countryPRC : boolean ; countryCIS : boolean ; countryOther : boolean ; } export interface ColorSchemeManager { colorBufferOneTime : boolean ; pickableBufferOneTime : boolean ; colorData : Float32Array ; pickableData : Float32Array ; pickableBuffer : WebGLBuffer ; colorBuffer : WebGLBuffer ; init : ( ) => void ; colorTheme : Colors ; resetObjectTypeFlags : ( ) => void ; reloadColors : ( ) => void ; currentColorScheme : ColorRuleSet ; iSensor : number ; lastCalculation : number ; default : ColorRuleSet ; onlyFOV : ColorRuleSet ; sunlight : ColorRuleSet ; apogee : ColorRuleSet ; smallsats : ColorRuleSet ; rcs : ColorRuleSet ; countries : ColorRuleSet ; ageOfElset : ColorRuleSet ; lostobjects : ColorRuleSet ; leo : ColorRuleSet ; geo : ColorRuleSet ; velocity : ColorRuleSet ; group : ColorRuleSet ; calculateColorBuffers : ( isForceRecolor ? : boolean ) => Promise < void > ; objectTypeFlags : ObjectTypeFlags ; satSet : CatalogManager ; } export interface ColorScheme { colorBuffer : WebGLBuffer ; colorData : any ; colorRuleSet : any ; colors : any ; gl : WebGL2RenderingContext ; hoverSat : any ; iSensor : number ; isSunlightColorScheme : boolean ; isVelocityColorScheme : boolean ; lastCalculation : number ; now : number ; pickableBuffer : WebGLBuffer ; pickableBufferOneTime : any ; pickableData : any ; satData : any ; satInSun : any ; satInView : any ; satSet : any ; satVel : any ; selectSat : any ; tempNumOfSats : number ; colorBufferOneTime : boolean ; colorBuf : any ; pickableBuf : any ; calculateColorBuffers : ( force : boolean ) => void ; } export enum Pickable { Yes = 1 , No = 0 } export type ColorInformation = { color : [ number , number , number , number ] ; marker ? : boolean ; pickable : Pickable ; } ; export type ColorRuleSet = ( sat : SatObject ) => ColorInformation ; export const colorSchemeManager = { objectTypeFlags : { payload : true , radarData : true , rocketBody : true , debris : true , facility : true , sensor : true , missile : true , missileInview : true , trusat : true , inFOV : true , inViewAlt : true , starLow : true , starMed : true , starHi : true , satLEO : true , satGEO : true , satLow : true , satMed : true , satHi : true , satSmall : true , rcsSmall : true , rcsMed : true , rcsLarge : true , rcsUnknown : true , velocitySlow : true , velocityMed : true , velocityFast : true , ageNew : true , ageMed : true , ageOld : true , ageLost : true , countryUS : true , countryPRC : true , countryCIS : true , countryOther : true , } , init : ( ) => { const { satSet } = keepTrackApi . programs ; const { gl } = keepTrackApi . programs . drawManager ; colorSchemeManager . colorTheme = settingsManager . colors ; colorSchemeManager . resetObjectTypeFlags ( ) ; colorSchemeManager . satSet = satSet ; keepTrackApi . register ( { method : 'onCruncherReady' , cbName : 'colorSchemeManager' , cb : ( ) : void => { colorSchemeManager . colorBuffer = gl . createBuffer ( ) ; colorSchemeManager . pickableBuffer = gl . createBuffer ( ) ; colorSchemeManager . colorData = new Float32Array ( satSet . numSats * 4 ) ; colorSchemeManager . pickableData = new Float32Array ( satSet . numSats ) ; } , } ) ; colorSchemeManager . default = defaultRules ; colorSchemeManager . onlyFOV = onlyFovRules ; colorSchemeManager . sunlight = sunlightRules ; colorSchemeManager . apogee = apogeeRules ; colorSchemeManager . smallsats = smallsatsRules ; colorSchemeManager . rcs = rcsRules ; colorSchemeManager . countries = countriesRules ; colorSchemeManager . ageOfElset = ageOfElsetRules ; colorSchemeManager . lostobjects = lostobjectsRules ; colorSchemeManager . leo = leoRules ; colorSchemeManager . geo = geoRules ; colorSchemeManager . velocity = velocityRules ; colorSchemeManager . group = groupRules ; } , currentColorScheme : null , iSensor : 0 , lastCalculation : 0 , calculateColorBuffers : async ( isForceRecolor ? ) : Promise < void > => { try { if ( ! colorSchemeManager . pickableData || ! colorSchemeManager . colorData ) return ; const { gl } = keepTrackApi . programs . drawManager ; const now = Date . now ( ) ; if ( ! isForceRecolor && now - colorSchemeManager . lastCalculation < settingsManager . reColorMinimumTime && colorSchemeManager . lastCalculation !== 0 ) return ; colorSchemeManager . lastCalculation = now ; const { satData } = keepTrackApi . programs . satSet ; const satInView = colorSchemeManager . satSet . getSatInView ( ) ; const satVel = colorSchemeManager . currentColorScheme === colorSchemeManager . velocity ? colorSchemeManager . satSet . getSatVel ( ) : null ; const satInSun = colorSchemeManager . satSet . getSatInSun ( ) ; colorSchemeManager . iSensor = 0 ; let colors = null ; for ( let i = 0 ; i < settingsManager . dotsOnScreen ; i ++ ) { if ( satInView ) { satData [ i ] . inView = satInView [ i ] ; } if ( satInSun ) { satData [ i ] . inSun = satInSun [ i ] ; } if ( satVel ) { satData [ i ] . velocity . total = Math . sqrt ( satVel [ i * 3 ] * satVel [ i * 3 ] + satVel [ i * 3 + 1 ] * satVel [ i * 3 + 1 ] + satVel [ i * 3 + 2 ] * satVel [ i * 3 + 2 ] ) ; } colors = colorSchemeManager . currentColorScheme ( satData [ i ] ) ; colorSchemeManager . colorData [ i * 4 ] = colors . color [ 0 ] ; colorSchemeManager . colorData [ i * 4 + 1 ] = colors . color [ 1 ] ; colorSchemeManager . colorData [ i * 4 + 2 ] = colors . color [ 2 ] ; colorSchemeManager . colorData [ i * 4 + 3 ] = colors . color [ 3 ] ; colorSchemeManager . pickableData [ i ] = colors . pickable ? Pickable . Yes : Pickable . No ; if ( i == keepTrackApi . programs . objectManager . selectedSat ) { colorSchemeManager . colorData [ i * 4 ] = settingsManager . selectedColor [ 0 ] ; colorSchemeManager . colorData [ i * 4 + 1 ] = settingsManager . selectedColor [ 1 ] ; colorSchemeManager . colorData [ i * 4 + 2 ] = settingsManager . selectedColor [ 2 ] ; colorSchemeManager . colorData [ i * 4 + 3 ] = settingsManager . selectedColor [ 3 ] ; } if ( i == keepTrackApi . programs . objectManager . hoveringSat ) { colorSchemeManager . colorData [ i * 4 ] = settingsManager . hoverColor [ 0 ] ; colorSchemeManager . colorData [ i * 4 + 1 ] = settingsManager . hoverColor [ 1 ] ; colorSchemeManager . colorData [ i * 4 + 2 ] = settingsManager . hoverColor [ 2 ] ; colorSchemeManager . colorData [ i * 4 + 3 ] = settingsManager . hoverColor [ 3 ] ; } } gl . bindBuffer ( gl . ARRAY_BUFFER , colorSchemeManager . colorBuffer ) ; if ( ! colorSchemeManager . colorBufferOneTime ) { gl . bufferData ( gl . ARRAY_BUFFER , colorSchemeManager . colorData , gl . DYNAMIC_DRAW ) ; colorSchemeManager . colorBufferOneTime = true ; } else { gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , colorSchemeManager . colorData ) ; } gl . bindBuffer ( gl . ARRAY_BUFFER , colorSchemeManager . pickableBuffer ) ; if ( ! colorSchemeManager . pickableBufferOneTime ) { gl . bufferData ( gl . ARRAY_BUFFER , colorSchemeManager . pickableData , gl . DYNAMIC_DRAW ) ; colorSchemeManager . pickableBufferOneTime = true ; } else { gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , colorSchemeManager . pickableData ) ; } } catch ( e ) { } } , resetObjectTypeFlags : ( ) => { colorSchemeManager . objectTypeFlags . payload = true ; colorSchemeManager . objectTypeFlags . radarData = true ; colorSchemeManager . objectTypeFlags . rocketBody = true ; colorSchemeManager . objectTypeFlags . debris = true ; colorSchemeManager . objectTypeFlags . facility = true ; colorSchemeManager . objectTypeFlags . sensor = true ; colorSchemeManager . objectTypeFlags . missile = true ; colorSchemeManager . objectTypeFlags . missileInview = true ; colorSchemeManager . objectTypeFlags . trusat = true ; colorSchemeManager . objectTypeFlags . inFOV = true ; colorSchemeManager . objectTypeFlags . inViewAlt = true ; colorSchemeManager . objectTypeFlags . starLow = true ; colorSchemeManager . objectTypeFlags . starMed = true ; colorSchemeManager . objectTypeFlags . starHi = true ; colorSchemeManager . objectTypeFlags . satLEO = true ; colorSchemeManager . objectTypeFlags . satGEO = true ; colorSchemeManager . objectTypeFlags . satLow = true ; colorSchemeManager . objectTypeFlags . satMed = true ; colorSchemeManager . objectTypeFlags . satHi = true ; colorSchemeManager . objectTypeFlags . satSmall = true ; colorSchemeManager . objectTypeFlags . rcsSmall = true ; colorSchemeManager . objectTypeFlags . rcsMed = true ; colorSchemeManager . objectTypeFlags . rcsLarge = true ; colorSchemeManager . objectTypeFlags . rcsUnknown = true ; colorSchemeManager . objectTypeFlags . velocitySlow = true ; colorSchemeManager . objectTypeFlags . velocityMed = true ; colorSchemeManager . objectTypeFlags . velocityFast = true ; colorSchemeManager . objectTypeFlags . ageNew = true ; colorSchemeManager . objectTypeFlags . ageMed = true ; colorSchemeManager . objectTypeFlags . ageOld = true ; colorSchemeManager . objectTypeFlags . ageLost = true ; } , reloadColors : ( ) => { colorSchemeManager . colorTheme = settingsManager . colors ; } , satSet : null , colorTheme : null , default : null , onlyFOV : null , sunlight : null , apogee : null , smallsats : null , rcs : null , countries : null , ageOfElset : null , lostobjects : null , leo : null , geo : null , velocity : null , group : null , pickableBuffer : null , colorBuffer : null , colorData : null , pickableData : null , colorBufferOneTime : false , pickableBufferOneTime : false , } ; export const isPayloadOff = ( sat ) => sat . type === 1 && colorSchemeManager . objectTypeFlags . payload === false ; export const isRocketBodyOff = ( sat ) => sat . type === 2 && colorSchemeManager . objectTypeFlags . rocketBody === false ; export const isDebrisOff = ( sat ) => sat . type === 3 && colorSchemeManager . objectTypeFlags . debris === false ; export const isInViewOff = ( sat ) => sat . inView === 1 && colorSchemeManager . objectTypeFlags . inFOV === false ;