import { DataContext } from "server/src/utils/DataContext" ; import { Entity } from "server/src/utils/ecs" ; import { getFlights } from "server/src/utils/getFlights" ; import type Station from "server/src/classes/Station" ; import ThemePlugin from "server/src/classes/Plugins/Theme" ; import type { FlightClient } from "server/src/classes/FlightClient" ; export const subscriptions = { client : ( context , params ) => { if ( params && params . clientId !== context . clientId ) throw null ; const { id , name , connected } = context . server . clients [ context . clientId ] ; const { officersLog , id : _id , ... flightClient } = ( context . flightClient as FlightClient ) || { } ; return { id , name , connected , ... flightClient } ; } , flight ( context ) { const flight = context . flight ; if ( ! flight ) return null ; const { date , name , paused } = flight ; return { date , name , paused } ; } , ship ( context , params ) { if ( params ) { if ( "shipId" in params && params . shipId !== context . flightClient ?. shipId ) throw null ; if ( "clientId" in params && params . clientId !== context . clientId ) throw null ; } return context . ship as Entity ; } , station ( context , params ) { if ( params && params . clientId !== context . clientId ) throw null ; if ( context . flightClient ?. stationOverride ) return context . flightClient . stationOverride ; const station = context . ship ?. components . stationComplement ?. stations . find ( s => s . name === context . flightClient ?. stationId ) as unknown as Station ; return station || null ; } , theme ( context , params ) { if ( params && params . clientId !== context . clientId ) throw null ; const themeObj = context . server . plugins . filter ( plugin => context . flight ?. pluginIds . includes ( plugin . id ) ) . reduce ( ( acc , plugin ) => { if ( acc ) return acc ; if ( plugin . id !== context . ship ?. components . theme ?. pluginId ) return acc ; return ( plugin . aspects . themes . find ( t => t . name === context . ship ?. components . theme ?. themeId ) || null ) ; } , null ) ; return themeObj ; } , } ; export function dataStream ( entity , context ) { return true ; }