Skip to content

Commit

Permalink
[MIRROR] Fixes TGUI debugging tools (#1921)
Browse files Browse the repository at this point in the history
* Fixes TGUI debugging tools (#82569)

This project doesn't interfere with the game logic and aims to fix
multiple debugging features that are currently broken. Unfortunately,
kitchen sink and debug layout became broken after migration to Redux.
This PR aims to fix those features.

* Fixes TGUI debugging tools

---------

Co-authored-by: Interception&? <[email protected]>
  • Loading branch information
2 people authored and StealsThePRs committed Apr 11, 2024
1 parent 2fee5e4 commit a11dce3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
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

0 comments on commit a11dce3

Please sign in to comment.