refactor: move setting blocks to welcomeBlocksData to canvas context
This commit is contained in:
parent
17dc511053
commit
53f81040be
3 changed files with 4 additions and 7 deletions
|
|
@ -35,7 +35,6 @@ function Blocks({ blocks, missingTexture, textures, coords, scale, version }: Pr
|
|||
useEffect(() => {
|
||||
const tilemap = new CompositeTilemap();
|
||||
tilemapRef.current = tilemap;
|
||||
tilemap.cullable = true;
|
||||
app.stage.addChildAt(tilemap, 0);
|
||||
|
||||
tileBlocks();
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ import CanvasBorder from "./CanvasBorder";
|
|||
import CursorInformation from "./information/Cursor";
|
||||
import CanvasInformation from "./information/Canvas";
|
||||
|
||||
import welcomeBlocksData from "@/data/welcome.json";
|
||||
|
||||
// Set scale mode to NEAREST
|
||||
PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
|
||||
|
||||
|
|
@ -460,8 +458,6 @@ function Canvas() {
|
|||
}, [stageContainerRef]);
|
||||
|
||||
useEffect(() => {
|
||||
setBlocks(welcomeBlocksData);
|
||||
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
window.addEventListener("keyup", onKeyUp);
|
||||
window.addEventListener("beforeunload", (e) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import React, { createContext, ReactNode, useMemo, useState } from "react";
|
||||
|
||||
import welcomeBlocksData from "@/data/welcome.json";
|
||||
|
||||
interface Context {
|
||||
stageSize: Dimension;
|
||||
canvasSize: BoundingBox;
|
||||
|
|
@ -21,8 +23,8 @@ interface Props {
|
|||
export const CanvasContext = createContext<Context>({} as Context);
|
||||
|
||||
export const CanvasProvider = ({ children }: Props) => {
|
||||
const [stageSize, setStageSize] = useState({ width: 0, height: 0 } as Dimension);
|
||||
const [blocks, setBlocks] = useState<Block[]>([]);
|
||||
const [stageSize, setStageSize] = useState<Dimension>({ width: 0, height: 0 });
|
||||
const [blocks, setBlocks] = useState<Block[]>(welcomeBlocksData);
|
||||
const [coords, setCoords] = useState<Position>({ x: 0, y: 0 });
|
||||
const [scale, setScale] = useState(1);
|
||||
const [version, setVersion] = useState(1214);
|
||||
|
|
|
|||
Loading…
Reference in a new issue