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(() => {
|
useEffect(() => {
|
||||||
const tilemap = new CompositeTilemap();
|
const tilemap = new CompositeTilemap();
|
||||||
tilemapRef.current = tilemap;
|
tilemapRef.current = tilemap;
|
||||||
tilemap.cullable = true;
|
|
||||||
app.stage.addChildAt(tilemap, 0);
|
app.stage.addChildAt(tilemap, 0);
|
||||||
|
|
||||||
tileBlocks();
|
tileBlocks();
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ import CanvasBorder from "./CanvasBorder";
|
||||||
import CursorInformation from "./information/Cursor";
|
import CursorInformation from "./information/Cursor";
|
||||||
import CanvasInformation from "./information/Canvas";
|
import CanvasInformation from "./information/Canvas";
|
||||||
|
|
||||||
import welcomeBlocksData from "@/data/welcome.json";
|
|
||||||
|
|
||||||
// Set scale mode to NEAREST
|
// Set scale mode to NEAREST
|
||||||
PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
|
PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
|
||||||
|
|
||||||
|
|
@ -460,8 +458,6 @@ function Canvas() {
|
||||||
}, [stageContainerRef]);
|
}, [stageContainerRef]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setBlocks(welcomeBlocksData);
|
|
||||||
|
|
||||||
window.addEventListener("keydown", onKeyDown);
|
window.addEventListener("keydown", onKeyDown);
|
||||||
window.addEventListener("keyup", onKeyUp);
|
window.addEventListener("keyup", onKeyUp);
|
||||||
window.addEventListener("beforeunload", (e) => {
|
window.addEventListener("beforeunload", (e) => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import React, { createContext, ReactNode, useMemo, useState } from "react";
|
import React, { createContext, ReactNode, useMemo, useState } from "react";
|
||||||
|
|
||||||
|
import welcomeBlocksData from "@/data/welcome.json";
|
||||||
|
|
||||||
interface Context {
|
interface Context {
|
||||||
stageSize: Dimension;
|
stageSize: Dimension;
|
||||||
canvasSize: BoundingBox;
|
canvasSize: BoundingBox;
|
||||||
|
|
@ -21,8 +23,8 @@ interface Props {
|
||||||
export const CanvasContext = createContext<Context>({} as Context);
|
export const CanvasContext = createContext<Context>({} as Context);
|
||||||
|
|
||||||
export const CanvasProvider = ({ children }: Props) => {
|
export const CanvasProvider = ({ children }: Props) => {
|
||||||
const [stageSize, setStageSize] = useState({ width: 0, height: 0 } as Dimension);
|
const [stageSize, setStageSize] = useState<Dimension>({ width: 0, height: 0 });
|
||||||
const [blocks, setBlocks] = useState<Block[]>([]);
|
const [blocks, setBlocks] = useState<Block[]>(welcomeBlocksData);
|
||||||
const [coords, setCoords] = useState<Position>({ x: 0, y: 0 });
|
const [coords, setCoords] = useState<Position>({ x: 0, y: 0 });
|
||||||
const [scale, setScale] = useState(1);
|
const [scale, setScale] = useState(1);
|
||||||
const [version, setVersion] = useState(1214);
|
const [version, setVersion] = useState(1214);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue