Skip to content

Commit

Permalink
v0.12.6: Add game debug page to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Nov 14, 2024
1 parent 99984e3 commit c5e2ffb
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ Join our community of developers.

## Changelog

### Wed Nov 13 17:18:00 2024

- Version 0.12.6
- Add game debug page to utils

### Tue Nov 12 23:15:00 2024

- Version 0.12.5
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
"@mui/icons-material": "^6.1.3",
"@mui/material": "^6.1.3",
"chart.js": "^4.4.5",
"highlight.js": "^11.10.0",
"module-alias": "^2.2.3",
"react": "18.3.1",
"react-chartjs-2": "^5.2.0",
"react-color": "^2.19.3",
"react-dom": "18.3.1",
"react-router-dom": "^6.27.0",
"react-virtualized": "^9.22.5",
"react-window": "^1.8.10",
"semver": "^7.6.3",
"uuid": "^10.0.0"
Expand Down Expand Up @@ -71,6 +73,7 @@
"@types/react": "^18.3.11",
"@types/react-color": "^3.0.12",
"@types/react-dom": "18.3.0",
"@types/react-virtualized": "^9.21.30",
"@types/react-window": "^1.8.8",
"@types/uuid": "^10.0.0",
"babel-jest": "^29.7.0",
Expand Down
75 changes: 75 additions & 0 deletions src/components/GameDebug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ScrollableContainer from '@/components/ScrollableContainer';
import hljs from 'highlight.js/lib/core';
import json from 'highlight.js/lib/languages/json';
import { List, AutoSizer, ListRowProps } from 'react-virtualized';

import 'highlight.js/styles/github-dark.css';
hljs.registerLanguage('json', json);

interface GameDebugProps {
value: string;
}

interface GameDebugState {
loading: boolean;
}

export default function Code({ children, language }: CodeProps) {
const html = hljs.highlight(children, { language }).value;
return (
<pre
className="px-4 py-4"
style={{
display: 'block',
backgroundColor: 'black',
boxSizing: 'border-box',
margin: 0,
padding: 0,
}}
>
<code
className="block overflow-x-auto text-slate-100"
style={{ whiteSpace: 'pre-wrap', margin: 0, padding: 0 }}
dangerouslySetInnerHTML={{ __html: html }}
/>
</pre>
);
}

export type CodeProps = { children: string; language: string };

export class GameDebug extends Component<GameDebugProps, GameDebugState> {
static propTypes = {
value: PropTypes.string.isRequired,
};

renderRow = ({ index, key, style }: ListRowProps) => {
const lines = this.props.value.split('\n');
return (
<div key={key} style={{ ...style, backgroundColor: 'black', padding: 0, margin: 0 }}>
<Code language="json">{lines[index]}</Code>
</div>
);
};

render() {
const lines = this.props.value.split('\n');
return (
<ScrollableContainer>
<AutoSizer>
{({ height, width }) => (
<List
height={height}
width={width}
rowCount={lines.length}
rowHeight={20}
rowRenderer={this.renderRow}
/>
)}
</AutoSizer>
</ScrollableContainer>
);
}
}
12 changes: 12 additions & 0 deletions src/components/screens/UtilsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { rebuildGameTimeHistory, rebuildTurnStatisticsCache } from '@/game/domin
import { deepClone } from '@/game/utils';
import { IGame } from '@/game/interfaces/game';
import { CurrentStep } from '@/game/enumerations/current-step';
import { GameDebug } from '@/components/GameDebug';

const StyledContainer = styled(Box)(({ theme }) => ({
display: 'flex',
Expand All @@ -17,6 +18,7 @@ const StyledContainer = styled(Box)(({ theme }) => ({

export const UtilsScreen: FC = () => {
const { gameState, setGameState } = useGameContext();
const [showGameDebug, setShowGameDebug] = React.useState<boolean>(false);

const handleRebuildGameTime = () => {
setGameState((prevState) => {
Expand Down Expand Up @@ -45,6 +47,10 @@ export const UtilsScreen: FC = () => {
});
};

const handleToggleGameDebug = () => {
setShowGameDebug((prevShowGameDebug) => !prevShowGameDebug);
};

return (
<StyledContainer>
<TabTitle>Utilities</TabTitle>
Expand All @@ -57,6 +63,11 @@ export const UtilsScreen: FC = () => {
<ListItem>
<Link onClick={handleRebuildTurnStatistics}>Rebuild Turn Statistics</Link>
</ListItem>
<ListItem>
<Link onClick={handleToggleGameDebug}>
{showGameDebug ? 'Hide Game Debug' : 'Show Game Debug'}
</Link>
</ListItem>
</List>
)}
{gameState.currentStep !== CurrentStep.Game &&
Expand All @@ -66,6 +77,7 @@ export const UtilsScreen: FC = () => {
state.
</Box>
)}
{showGameDebug && <GameDebug value={JSON.stringify(gameState, null, 2)} />}
</StyledContainer>
);
};
2 changes: 1 addition & 1 deletion src/game/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IRisingSunFeatures } from '@/game/interfaces/set-features/rising-sun';
import { IExpansionsEnabled } from '@/game/interfaces/expansions-enabled';
import { calculateInitialSunTokens } from '@/game/interfaces/set-mats/prophecy';

export const VERSION_NUMBER = '0.12.5';
export const VERSION_NUMBER = '0.12.6';
export const LAST_COMPATIBLE_SAVE_VERSION = '0.12.0';

export const MIN_PLAYERS = 2;
Expand Down
39 changes: 37 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,14 @@
dependencies:
"@types/react" "*"

"@types/react-virtualized@^9.21.30":
version "9.21.30"
resolved "https://registry.yarnpkg.com/@types/react-virtualized/-/react-virtualized-9.21.30.tgz#ba39821bcb2487512a8a2cdd9fbdb5e6fc87fedb"
integrity sha512-4l2TFLQ8BCjNDQlvH85tU6gctuZoEdgYzENQyZHpgTHU7hoLzYgPSOALMAeA58LOWua8AzC6wBivPj1lfl6JgQ==
dependencies:
"@types/prop-types" "*"
"@types/react" "*"

"@types/react-window@^1.8.8":
version "1.8.8"
resolved "https://registry.yarnpkg.com/@types/react-window/-/react-window-1.8.8.tgz#c20645414d142364fbe735818e1c1e0a145696e3"
Expand Down Expand Up @@ -4376,6 +4384,11 @@ clone@^1.0.2:
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"
integrity sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==

clsx@^1.0.4:
version "1.2.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==

clsx@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
Expand Down Expand Up @@ -5088,7 +5101,7 @@ dom-accessibility-api@^0.6.3:
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz#993e925cc1d73f2c662e7d75dd5a5445259a8fd8"
integrity sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==

dom-helpers@^5.0.1:
dom-helpers@^5.0.1, dom-helpers@^5.1.3:
version "5.2.1"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.2.1.tgz#d9400536b2bf8225ad98fe052e029451ac40e902"
integrity sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==
Expand Down Expand Up @@ -6465,6 +6478,11 @@ he@^1.2.0:
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

highlight.js@^11.10.0:
version "11.10.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-11.10.0.tgz#6e3600dc4b33d6dc23d5bd94fbf72405f5892b92"
integrity sha512-SYVnVFswQER+zu1laSya563s+F8VDGt7o35d4utbamowvUNLLMovFqwCLSocpZTz3MgaSRA1IbqRWZv97dtErQ==

hoist-non-react-statics@^3.3.1:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
Expand Down Expand Up @@ -9215,7 +9233,7 @@ prompts@^2.0.1, prompts@^2.4.1:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.5.10, prop-types@^15.6.2, prop-types@^15.8.1:
prop-types@^15.5.10, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -9360,6 +9378,11 @@ react-is@^18.0.0, react-is@^18.3.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==

react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==

react-refresh@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.10.0.tgz#2f536c9660c0b9b1d500684d9e52a65e7404f7e3"
Expand Down Expand Up @@ -9390,6 +9413,18 @@ react-transition-group@^4.4.5:
loose-envify "^1.4.0"
prop-types "^15.6.2"

react-virtualized@^9.22.5:
version "9.22.5"
resolved "https://registry.yarnpkg.com/react-virtualized/-/react-virtualized-9.22.5.tgz#bfb96fed519de378b50d8c0064b92994b3b91620"
integrity sha512-YqQMRzlVANBv1L/7r63OHa2b0ZsAaDp1UhVNEdUaXI8A5u6hTpA5NYtUueLH2rFuY/27mTGIBl7ZhqFKzw18YQ==
dependencies:
"@babel/runtime" "^7.7.2"
clsx "^1.0.4"
dom-helpers "^5.1.3"
loose-envify "^1.4.0"
prop-types "^15.7.2"
react-lifecycles-compat "^3.0.4"

react-window@^1.8.10:
version "1.8.10"
resolved "https://registry.yarnpkg.com/react-window/-/react-window-1.8.10.tgz#9e6b08548316814b443f7002b1cf8fd3a1bdde03"
Expand Down

0 comments on commit c5e2ffb

Please sign in to comment.