mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-11 15:57:33 +01:00
STANEK: FIX #3669 Clearing stanek grid using API could crash the page.
Fix #3669 - Query the "activegrid" at each re-rerendering of the Stanek Page. Rather than using React useState and passing it as Props. Tested with : ns.clearLog() ns.tail() await ns.sleep(2000) ns.print("Clearing gift") await ns.sleep(1000); ns.stanek.clearGift()
This commit is contained in:
parent
b2659318c8
commit
ce5fdb00af
@ -1,13 +1,13 @@
|
|||||||
import { TableBody, TableRow } from "@mui/material";
|
import { TableBody, TableRow } from "@mui/material";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ActiveFragment } from "../ActiveFragment";
|
import { ActiveFragment } from "../ActiveFragment";
|
||||||
|
import { calculateGrid } from "../Helper";
|
||||||
import { IStaneksGift } from "../IStaneksGift";
|
import { IStaneksGift } from "../IStaneksGift";
|
||||||
import { Cell } from "./Cell";
|
import { Cell } from "./Cell";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
activeGrid: number[][];
|
|
||||||
ghostGrid: number[][];
|
ghostGrid: number[][];
|
||||||
gift: IStaneksGift;
|
gift: IStaneksGift;
|
||||||
enter(i: number, j: number): void;
|
enter(i: number, j: number): void;
|
||||||
@ -32,11 +32,13 @@ function randomColor(fragment: ActiveFragment): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Grid(props: IProps): React.ReactElement {
|
export function Grid(props: IProps): React.ReactElement {
|
||||||
|
const activeGrid = calculateGrid(props.gift)
|
||||||
|
|
||||||
function color(worldX: number, worldY: number): string {
|
function color(worldX: number, worldY: number): string {
|
||||||
if (props.ghostGrid[worldX][worldY] && props.activeGrid[worldX][worldY]) return "red";
|
if (props.ghostGrid[worldX][worldY] && activeGrid[worldX][worldY]) return "red";
|
||||||
if (props.ghostGrid[worldX][worldY]) return "white";
|
if (props.ghostGrid[worldX][worldY]) return "white";
|
||||||
|
|
||||||
if (props.activeGrid[worldX][worldY]) {
|
if (activeGrid[worldX][worldY]) {
|
||||||
const fragment = props.gift.fragmentAt(worldX, worldY);
|
const fragment = props.gift.fragmentAt(worldX, worldY);
|
||||||
if (!fragment) throw new Error("ActiveFragment should not be null");
|
if (!fragment) throw new Error("ActiveFragment should not be null");
|
||||||
return randomColor(fragment);
|
return randomColor(fragment);
|
||||||
|
@ -18,7 +18,6 @@ interface IProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function MainBoard(props: IProps): React.ReactElement {
|
export function MainBoard(props: IProps): React.ReactElement {
|
||||||
const [grid, setGrid] = React.useState(calculateGrid(props.gift));
|
|
||||||
const [ghostGrid, setGhostGrid] = React.useState(zeros([props.gift.width(), props.gift.height()]));
|
const [ghostGrid, setGhostGrid] = React.useState(zeros([props.gift.width(), props.gift.height()]));
|
||||||
const [pos, setPos] = React.useState([0, 0]);
|
const [pos, setPos] = React.useState([0, 0]);
|
||||||
const [rotation, setRotation] = React.useState(0);
|
const [rotation, setRotation] = React.useState(0);
|
||||||
@ -54,12 +53,10 @@ export function MainBoard(props: IProps): React.ReactElement {
|
|||||||
if (!props.gift.canPlace(worldX, worldY, rotation, selectedFragment)) return;
|
if (!props.gift.canPlace(worldX, worldY, rotation, selectedFragment)) return;
|
||||||
props.gift.place(worldX, worldY, rotation, selectedFragment);
|
props.gift.place(worldX, worldY, rotation, selectedFragment);
|
||||||
}
|
}
|
||||||
setGrid(calculateGrid(props.gift));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear(): void {
|
function clear(): void {
|
||||||
props.gift.clear();
|
props.gift.clear();
|
||||||
setGrid(zeros([props.gift.width(), props.gift.height()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSelectedFragment(fragment: Fragment): void {
|
function updateSelectedFragment(fragment: Fragment): void {
|
||||||
@ -92,7 +89,6 @@ export function MainBoard(props: IProps): React.ReactElement {
|
|||||||
<Grid
|
<Grid
|
||||||
width={props.gift.width()}
|
width={props.gift.width()}
|
||||||
height={props.gift.height()}
|
height={props.gift.height()}
|
||||||
activeGrid={grid}
|
|
||||||
ghostGrid={ghostGrid}
|
ghostGrid={ghostGrid}
|
||||||
gift={props.gift}
|
gift={props.gift}
|
||||||
enter={(i, j) => moveGhost(i, j, rotation)}
|
enter={(i, j) => moveGhost(i, j, rotation)}
|
||||||
|
Loading…
Reference in New Issue
Block a user