Y7VEWZEPUKX2WWPTQCUSIF7YMRUC6JZQNUU5OX3HQDB4GSDSTQZAC
6MT2I7DD6YK53IHJTULXSFIFLFM2E7QFRXH2V2A7ZG3QZ4UOO7RAC
YHYMDE5P7LYLMUCYEW666U2UGY7ADLLC6QRNKIYHSO3P6I4XPM5QC
KU5Z5AYZH72HK7ZMFK5264ZVIZWYC35ON7TXDJYFCK5CGBD2HP6QC
5EU4IUPMLQQEQNNQB2YTJR6ZD54GIQ5IDBJ3PJPDJ76HMNZSCKVAC
EMED7UWAGESRTWJJWVXRL27O4XMBGZDDAU4LNVF3MQAYKFKRDNXQC
HXHNGFB2VCXB6YXDND35HJI22GBJC3QTSUR2TK3M3LXGJHVNXVHAC
VGU4VI6EMYILKHN3TFRCEGU7LL6NM6PW6RHRC726YUKO6RBORBQQC
5BA7VZ3D36S2TC7NZ64R3O364TGXPY5BJUJTGCFZHWZ6JWAXJMUQC
YNOQHSPKQHAODMORMW4GKQZK5SCC2LYAFLJHH3GEMZTDM7N52JAAC
L26AGXYEPA36JG2HC35KLZNJUXE5UX7CJY2ECOUKYQCYMTTPZCKQC
IYRYOO3B2EFA2O3JJKOQLEQ6WWDCCGEH3LSFCZJUMBXTVYFZS44QC
ZHOSSPNKGFIKSFPDXCGLMSYMMX2J433VU2BUUWBKUH7TOLQUBSPQC
## GameContext possible issues
If too many frequent changes, will trigger all components that use the GameContext to re-render.
https://github.com/facebook/react/issues/15156
const [focusedNode, setFocusedNode] = useState({ chunk: null, node: null });
const [focusedNode, setFocusedNode] = useState < { chunk: Chunk, node: Vector2 }>();
const uiState = useMemo(() => ({ focusedNode }), [focusedNode]);
const game = useMemo(() => ({}),[])
{/* <header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header> */}
<PixiComponent onFocusedNodeChange={handleFocusedNodeChange} />
<NodeDetail focusedNode={focusedNode} />
<GameContext.Provider value={game}>
<UIContext.Provider value={uiState}>
<PixiComponent onFocusedNodeChange={handleFocusedNodeChange} />
<NodeDetail focusedNode={focusedNode} />
</UIContext.Provider>
</GameContext.Provider>
export function NodeDetail({ focusedNode }: { focusedNode: {chunk: any, node: any} }) {
const [history, setHistory] = useState<{ chunk: any, node: any }[]>([]);
console.log(focusedNode);
export function NodeDetail({
focusedNode,
}: {
focusedNode?: { chunk: any; node: any };
}) {
const [history, setHistory] = useState<{ chunk: any; node: any }[]>([]);
<h1>Current</h1>
<h3>Chunk: {focusedNode.chunk?.id}</h3>
<h3>X: {focusedNode.node?.x}</h3>
<h3>Y: {focusedNode.node?.y}</h3>
<h2>Previous</h2>
{history
.map(({ chunk, node }, i) => {
return (
<div key={i}>
Chunk {chunk?.id} at {node?.x},{node?.y}
</div>
);
})
.reverse()}
{focusedNode && focusedNode.chunk && (
<>
<h1>Current</h1>
<h3>
Chunk: {focusedNode.chunk.location.x},
{focusedNode.chunk.location.y}
</h3>
<h3>X: {focusedNode.node.x}</h3>
<h3>Y: {focusedNode.node.y}</h3>
<h2>Previous</h2>
{history
.slice(0, -1)
.map(({ chunk, node }, i) => {
return (
<div key={i}>
Chunk ({chunk.location.x},{chunk.location.y}) at ({node.x},
{node.y})
</div>
);
})
.reverse()}
</>
)}
import React from "react";
import { Vector2 } from "./lib/util/geometry/vector2";
import { Chunk } from "./pixi/Chunk";
export const GameContext = React.createContext<{
[k: string]: any;
}>({});
export const UIContext = React.createContext<{
focusedNode?: { chunk: Chunk; node: Vector2 };
}>({});