Skip to content

Commit

Permalink
Merge pull request #552 from Thorium-Sim/interstellar-viewscreen-fix
Browse files Browse the repository at this point in the history
fix: Interstellar viewscreen no longer shows the Flight Director view.
  • Loading branch information
alexanderson1993 authored Feb 10, 2023
2 parents 945dd22 + 6fb2bdb commit bd4d415
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 82 deletions.
104 changes: 51 additions & 53 deletions client/react-test-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, {ReactNode, Suspense} from "react";
import {render as rtlRender, RenderOptions} from "@testing-library/react";
import {MemoryRouter as Router} from "react-router-dom";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
import {LiveQueryContext} from "@thorium/live-query/client/liveQueryContext";
import {
LiveQueryContext,
LiveQueryProvider,
} from "@thorium/live-query/client/liveQueryContext";
import {MockNetRequestContext} from "@thorium/live-query/client/mockContext";
import {AppRouter} from "@server/init/router";
import {inferRouterOutputs} from "@thorium/live-query/server/types";
Expand Down Expand Up @@ -44,8 +46,6 @@ interface OptionsInterface {
netRequestData?: DeepPartial<inferRouterOutputs<AppRouter>>;
}

const queryClient = new QueryClient();

async function render(
ui: Parameters<typeof rtlRender>[0],
options?: Omit<RenderOptions, "queries"> & OptionsInterface
Expand All @@ -54,58 +54,56 @@ async function render(
const Wrapper = ({children}: {children: ReactNode}) => {
return (
<Suspense fallback={<p>Suspended in test</p>}>
<LiveQueryContext.Provider value={{} as any}>
<QueryClientProvider client={queryClient}>
<MockNetRequestContext.Provider
value={{
client: {
get: {
id: "Test",
name: "Test Client",
connected: true,
loginName: "Test User",
},
} as any,
flight: null,
ship: {
get: {
id: 0,
components: {
isPlayerShip: {value: true},
identity: {name: "Test Ship"},
isShip: {
assets: {
logo: "",
},
category: "Cruiser",
registry: "NCC-2016-A",
shipClass: "Astra Cruiser",
<LiveQueryProvider getRequestContext={() => ({id: "test"})}>
<MockNetRequestContext.Provider
value={{
client: {
get: {
id: "Test",
name: "Test Client",
connected: true,
loginName: "Test User",
},
} as any,
flight: null,
ship: {
get: {
id: 0,
components: {
isPlayerShip: {value: true},
identity: {name: "Test Ship"},
isShip: {
assets: {
logo: "",
},
category: "Cruiser",
registry: "NCC-2016-A",
shipClass: "Astra Cruiser",
},
alertLevel: 5,
},
} as any,
station: {
get: {
name: "Test Station",
logo: "",
cards: [
{
icon: "",
name: "Test Card",
component: "Login",
},
],
},
} as any,
theme: null,
...options?.netRequestData,
}}
>
<Router initialEntries={initialRoutes}>{children}</Router>
</MockNetRequestContext.Provider>
</QueryClientProvider>
</LiveQueryContext.Provider>
alertLevel: 5,
},
} as any,
station: {
get: {
name: "Test Station",
logo: "",
cards: [
{
icon: "",
name: "Test Card",
component: "Login",
},
],
},
} as any,
theme: null,
...options?.netRequestData,
}}
>
<Router initialEntries={initialRoutes}>{children}</Router>
</MockNetRequestContext.Provider>
</LiveQueryProvider>
</Suspense>
);
};
Expand Down
55 changes: 30 additions & 25 deletions client/src/components/Starmap/InterstellarMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,40 @@ export function InterstellarMap({children}: {children: React.ReactNode}) {
const viewingMode = useStarmapStore(store => store.viewingMode);

const isStation = viewingMode === "station";
const isViewscreen = viewingMode === "viewscreen";

return (
<Suspense fallback={null}>
<Starfield radius={lightYearToLightMinute(INTERSTELLAR_MAX_DISTANCE)} />
<CameraControls
ref={orbitControls}
enabled={controlsEnabled}
maxDistance={lightYearToLightMinute(INTERSTELLAR_MAX_DISTANCE)}
minDistance={1}
mouseButtons={{
left: ACTION.TRUCK,
right: ACTION.ROTATE,
middle: ACTION.DOLLY,
wheel: ACTION.DOLLY,
}}
dollyToCursor={isStation}
dollySpeed={0.5}
/>
<PolarGrid
rotation={[0, (2 * Math.PI) / 12, 0]}
args={[
lightYearToLightMinute(INTERSTELLAR_MAX_DISTANCE),
12,
20,
64,
0xffffff,
0xffffff,
]}
/>
{!isViewscreen && (
<>
<CameraControls
ref={orbitControls}
enabled={controlsEnabled}
maxDistance={lightYearToLightMinute(INTERSTELLAR_MAX_DISTANCE)}
minDistance={1}
mouseButtons={{
left: ACTION.TRUCK,
right: ACTION.ROTATE,
middle: ACTION.DOLLY,
wheel: ACTION.DOLLY,
}}
dollyToCursor={isStation}
dollySpeed={0.5}
/>
<PolarGrid
rotation={[0, (2 * Math.PI) / 12, 0]}
args={[
lightYearToLightMinute(INTERSTELLAR_MAX_DISTANCE),
12,
20,
64,
0xffffff,
0xffffff,
]}
/>
</>
)}
{children}
</Suspense>
);
Expand Down
17 changes: 13 additions & 4 deletions shared/live-query/client/liveQueryContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {createContext, ReactNode, Suspense, useContext, useMemo} from "react";
import React, {
createContext,
ReactNode,
Suspense,
useContext,
useMemo,
} from "react";
import {useDataConnection} from "./useDataConnection";
import {ClientSocket} from "./clientSocket";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
Expand Down Expand Up @@ -47,6 +53,8 @@ export function processInterpolation(
});
}

const isTestEnv = process.env.NODE_ENV === "test";

function DataResponse() {
useDataResponse();
return null;
Expand All @@ -60,8 +68,9 @@ export function LiveQueryProvider({
}) {
const {socket, reconnectionState} = useDataConnection(getRequestContext);

useAnimationFrame(() =>
processInterpolation(socket?.SI.calcInterpolation("x y z r(quat)"))
useAnimationFrame(
() => processInterpolation(socket?.SI.calcInterpolation("x y z r(quat)")),
isTestEnv ? false : true
);
const value: ILiveQueryContext = useMemo(() => {
return {
Expand All @@ -82,7 +91,7 @@ export function LiveQueryProvider({
<ErrorBoundary fallback={<>Error Loading</>}>
<Suspense>{children}</Suspense>
</ErrorBoundary>
<DataResponse />
{!isTestEnv ? <DataResponse /> : null}
<ReactQueryDevtools position="bottom-right" />
</QueryClientProvider>
</LiveQueryContext.Provider>
Expand Down
4 changes: 4 additions & 0 deletions shared/live-query/client/useDataConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const connectClient = async <TContext extends RequestContext>(
) => {
socket.send(JSON.stringify({type: "clientConnect", ...context}));
};

const isTestEnv = process.env.NODE_ENV === "test";

export function useDataConnection<TContext extends RequestContext>(
getRequestContext: () => TContext | Promise<TContext>
) {
Expand Down Expand Up @@ -54,6 +57,7 @@ export function useDataConnection<TContext extends RequestContext>(
);

useEffect(() => {
if (isTestEnv) return;
startDataConnection();
return () => {
socket?.close();
Expand Down

0 comments on commit bd4d415

Please sign in to comment.