generated from ModusCreateOrg/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.tsx
48 lines (41 loc) · 1.06 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { useRef, FC, useContext, useState, useEffect } from "react";
import { EVENTS, TILE_SETS } from "../../constants";
import { GlobalContext } from "../../contexts";
import { useSprite } from "../../hooks";
import "./style.css";
const WIDTH = 64;
const HEIGHT = 64;
const TILE_X = 992;
type CellarDoorProps = { top: number; left: number };
const CellarDoor: FC<CellarDoorProps> = ({ top, left }) => {
const { setEvent } = useContext(GlobalContext);
const [isOpen, setIsOpen] = useState(false);
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
setEvent(EVENTS.LEVER_ON, () => {
setIsOpen(true);
});
setEvent(EVENTS.LEVER_OFF, () => {
setIsOpen(false);
});
}, [setEvent]);
useSprite({
canvasRef,
left,
top,
tileSet: TILE_SETS.World,
width: WIDTH,
height: HEIGHT,
tileX: isOpen ? TILE_X + WIDTH : TILE_X,
tileY: 160,
});
return (
<canvas
ref={canvasRef}
id="cellar-door-canvas"
width={WIDTH}
height={HEIGHT}
></canvas>
);
};
export default CellarDoor;