Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Fixes TGUI debugging tools #2840

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tgui/packages/tgui/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@ type BackendState<TData> = {
shared: Record<string, any>;
suspending: boolean;
suspended: boolean;
debug?: {
debugLayout: boolean;
kitchenSink: boolean;
};
};

/**
Expand Down
9 changes: 5 additions & 4 deletions tgui/packages/tgui/debug/KitchenSink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* @license MIT
*/

import { useLocalState } from '../backend';
import { useState } from 'react';

import { Flex, Section, Tabs } from '../components';
import { Pane, Window } from '../layouts';

const r = require.context('../stories', false, /\.stories\.js$/);
const r = require.context('../stories', false, /\.stories\.jsx$/);

/**
* @returns {{
Expand All @@ -22,8 +23,8 @@ const getStories = () => r.keys().map((path) => r(path));

export const KitchenSink = (props) => {
const { panel } = props;
const [theme] = useLocalState('kitchenSinkTheme');
const [pageIndex, setPageIndex] = useLocalState('pageIndex', 0);
const [theme] = useState(null);
const [pageIndex, setPageIndex] = useState(0);
const stories = getStories();
const story = stories[pageIndex];
const Layout = panel ? Pane : Window;
Expand Down
8 changes: 3 additions & 5 deletions tgui/packages/tgui/layouts/Pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { classes } from 'common/react';
import { useBackend } from '../backend';
import { Box } from '../components';
import { BoxProps } from '../components/Box';
import { useDebug } from '../debug';
import { Layout } from './Layout';

type Props = Partial<{
Expand All @@ -18,11 +19,8 @@ type Props = Partial<{

export function Pane(props: Props) {
const { theme, children, className, ...rest } = props;
const { suspended, debug } = useBackend();
let debugLayout = false;
if (debug) {
debugLayout = debug.debugLayout;
}
const { suspended } = useBackend();
const { debugLayout = false } = useDebug();

return (
<Layout className={classes(['Window', className])} theme={theme} {...rest}>
Expand Down
16 changes: 5 additions & 11 deletions tgui/packages/tgui/layouts/Window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { globalStore } from '../backend';
import { Icon } from '../components';
import { BoxProps } from '../components/Box';
import { UI_DISABLED, UI_INTERACTIVE, UI_UPDATE } from '../constants';
import { useDebug } from '../debug';
import { toggleKitchenSink } from '../debug/actions';
import {
dragStartHandler,
Expand Down Expand Up @@ -48,10 +49,8 @@ export const Window = (props: Props) => {
height,
} = props;

const { config, suspended, debug } = useBackend();
if (suspended) {
return null;
}
const { config, suspended } = useBackend();
const { debugLayout = false } = useDebug();

useEffect(() => {
const updateGeometry = () => {
Expand Down Expand Up @@ -80,11 +79,6 @@ export const Window = (props: Props) => {
};
}, [width, height]);

let debugLayout = false;
if (debug) {
debugLayout = debug.debugLayout;
}

const dispatch = globalStore.dispatch;
const fancy = config.window?.fancy;

Expand All @@ -95,11 +89,11 @@ export const Window = (props: Props) => {
? config.status < UI_DISABLED
: config.status < UI_INTERACTIVE);

return (
return suspended ? null : (
<Layout className="Window" theme={theme}>
<TitleBar
className="Window__titleBar"
title={!suspended && (title || decodeHtmlEntities(config.title))}
title={title || decodeHtmlEntities(config.title)}
status={config.status}
fancy={fancy}
onDragStart={dragStartHandler}
Expand Down
7 changes: 5 additions & 2 deletions tgui/packages/tgui/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { useBackend } from './backend';
import { useDebug } from './debug';
import { LoadingScreen } from './interfaces/common/LoadingToolbox';
import { Window } from './layouts';

Expand Down Expand Up @@ -52,7 +53,9 @@ const RefreshingWindow = () => {

// Get the component for the current route
export const getRoutedComponent = () => {
const { suspended, config, debug } = useBackend();
const { suspended, config } = useBackend();
const { kitchenSink = false } = useDebug();

if (suspended) {
return SuspendedWindow;
}
Expand All @@ -61,7 +64,7 @@ export const getRoutedComponent = () => {
}
if (process.env.NODE_ENV !== 'production') {
// Show a kitchen sink
if (debug?.kitchenSink) {
if (kitchenSink) {
return require('./debug').KitchenSink;
}
}
Expand Down
Loading