-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameWindow.js
139 lines (132 loc) · 4.03 KB
/
gameWindow.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from "react";
import { Progress } from "antd";
import "./gameWindow.css";
import "antd/dist/antd.css";
import { Zoom } from "@vx/zoom";
import { localPoint } from "@vx/event";
class GameWindow extends React.Component {
// Reference: https://dev.to/leonardoschmittk/how-to-make-a-mouse-ripple-click-effect-with-css-js-and-html-in-2-steps-2fcf
applyCursorRippleEffect = (e) => {
const ripple = document.createElement("div");
ripple.className = "ripple";
document.body.appendChild(ripple);
ripple.style.left = `${e.clientX}px`;
ripple.style.top = `${e.clientY}px`;
ripple.style.animation = "ripple-effect .4s linear";
ripple.onanimationend = () => document.body.removeChild(ripple);
};
render() {
const {
isLoading,
frameSrc,
progress,
imageL,
imageR,
width,
height,
sendMouseData,
borderColor,
} = this.props;
return (
<Zoom>
{(zoom) => (
// for ripple effect add an onclick function to the div and call applyCursorRippleEffect()
<div className="container">
{imageL ? (
<div className="imageContainer">
{
<img
src={imageL}
className="imageComponent"
alt="imageLeft"
width="400px"
height="400px"
/>
}
</div>
) : null}
<div
className="gameWindow"
style={{
border:
borderColor !== "default"
? borderColor === null
? "none"
: "solid " + borderColor
: "solid #1890ff",
}}
onMouseDown={(event) => {
event.preventDefault();
const point = localPoint(event);
sendMouseData(
"mouse down",
point.x,
point.y - 0.65625,
event.buttons
);
}}
onMouseMove={(event) => {
event.preventDefault();
const point = localPoint(event);
sendMouseData(
"mouse move",
point.x,
point.y - 0.65625,
event.buttons
);
}}
onMouseUp={(event) => {
event.preventDefault();
const point = localPoint(event);
sendMouseData(
"mouse up",
point.x,
point.y - 0.65625,
event.buttons
);
}}
// prevent context menu from popping up when right mouse button is clicked in the gamewindow
onContextMenu={(event) => {
event.preventDefault();
return false;
}}
>
{isLoading || !frameSrc ? (
<div className="progressBar">
<Progress
width={80}
type="circle"
percent={Math.round(progress)}
/>
<p className="promptText">
The robot is about to start the game, please wait ...
</p>
</div>
) : (
<img
className="gameContent"
src={frameSrc}
alt="frame"
width={width}
height={height}
/>
)}
</div>
{imageR ? (
<div className="imageContainer">
<img
src={imageR}
className="imageComponent"
alt="imageRight"
width="400px"
height="400px"
/>
</div>
) : null}
</div>
)}
</Zoom>
);
}
}
export default GameWindow;