gaesup-world 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/gaesup/animation/actions.ts +1 -1
- package/src/gaesup/camera/control/normal.ts +1 -1
- package/src/gaesup/camera/control/orbit.ts +1 -1
- package/src/gaesup/camera/index.tsx +3 -3
- package/src/gaesup/component/gltf/AirplaneGltf.tsx +1 -1
- package/src/gaesup/component/gltf/CharacterGltf.tsx +1 -1
- package/src/gaesup/component/gltf/VehicleGltf.tsx +1 -1
- package/src/gaesup/component/gltf/WheelJoint.tsx +1 -1
- package/src/gaesup/component/ref/airplane.tsx +1 -1
- package/src/gaesup/component/ref/character.tsx +1 -1
- package/src/gaesup/component/ref/vehicle.tsx +1 -1
- package/src/gaesup/component/setInit.ts +2 -2
- package/src/gaesup/{stores/context/controller → controller/context}/index.ts +3 -2
- package/src/gaesup/{stores/context/controller → controller/context}/type.ts +22 -2
- package/src/gaesup/controller/index.tsx +4 -3
- package/src/gaesup/controller/type.ts +3 -5
- package/src/gaesup/gaesupProps/index.tsx +1 -1
- package/src/gaesup/initial/callback/index.ts +1 -1
- package/src/gaesup/initial/callback/type.ts +6 -4
- package/src/gaesup/initial/controller/index.ts +3 -2
- package/src/gaesup/initial/gaesupWorld/collider/index.ts +1 -1
- package/src/gaesup/initial/gaesupWorld/index.ts +33 -33
- package/src/gaesup/initial/gaesupWorld/type.ts +11 -14
- package/src/gaesup/physics/airplane/direction.ts +0 -2
- package/src/gaesup/physics/airplane/turn.ts +0 -1
- package/src/gaesup/physics/character/direction.ts +12 -11
- package/src/gaesup/physics/index.ts +5 -4
- package/src/gaesup/physics/type.ts +3 -6
- package/src/gaesup/tools/context.ts +6 -0
- package/src/gaesup/tools/gameboy/GameBoyButton.tsx +6 -4
- package/src/gaesup/{stores/gameboy/index.ts → tools/gameboy/default.ts} +1 -1
- package/src/gaesup/tools/gameboy/index.tsx +6 -4
- package/src/gaesup/tools/gameboy/style.css.ts +2 -2
- package/src/gaesup/tools/gamepad/GamePadButton.tsx +21 -4
- package/src/gaesup/tools/gamepad/default.ts +3 -0
- package/src/gaesup/tools/gamepad/index.tsx +18 -7
- package/src/gaesup/tools/gamepad/style.css.ts +62 -7
- package/src/gaesup/tools/gamepad/type.ts +9 -0
- package/src/gaesup/tools/index.tsx +64 -43
- package/src/gaesup/{stores/joystick/index.ts → tools/joystick/default.ts} +11 -9
- package/src/gaesup/tools/joystick/index.tsx +94 -63
- package/src/gaesup/tools/joystick/style.css.ts +11 -8
- package/src/gaesup/{stores → tools}/joystick/type.ts +8 -7
- package/src/gaesup/tools/jumpPoint/index.tsx +2 -2
- package/src/gaesup/tools/keyBoardToolTip/constant.ts +1 -17
- package/src/gaesup/tools/keyBoardToolTip/default.ts +14 -0
- package/src/gaesup/tools/keyBoardToolTip/index.tsx +27 -20
- package/src/gaesup/tools/keyBoardToolTip/type.ts +37 -0
- package/src/gaesup/{stores/minimap/index.ts → tools/minimap/default.ts} +4 -0
- package/src/gaesup/tools/minimap/index.tsx +23 -5
- package/src/gaesup/{stores → tools}/minimap/type.ts +6 -1
- package/src/gaesup/{stores/control → tools/pushKey}/index.ts +1 -8
- package/src/gaesup/tools/reducer.ts +21 -0
- package/src/gaesup/tools/type.ts +26 -0
- package/src/gaesup/world/context/index.ts +124 -0
- package/src/gaesup/{stores/context/gaesupworld → world/context}/reducer.ts +1 -1
- package/src/gaesup/world/context/type.ts +137 -0
- package/src/gaesup/world/index.tsx +1 -4
- package/src/gaesup/world/type.ts +1 -1
- package/src/gaesup/stores/active/index.ts +0 -19
- package/src/gaesup/stores/active/type.ts +0 -16
- package/src/gaesup/stores/airplane/index.ts +0 -22
- package/src/gaesup/stores/airplane/type.ts +0 -22
- package/src/gaesup/stores/animation/index.ts +0 -18
- package/src/gaesup/stores/animation/type.ts +0 -9
- package/src/gaesup/stores/collider/index.ts +0 -55
- package/src/gaesup/stores/context/gaesupworld/index.ts +0 -11
- package/src/gaesup/stores/context/gaesupworld/type.ts +0 -71
- package/src/gaesup/stores/control/type.ts +0 -11
- package/src/gaesup/stores/point/type.ts +0 -6
- package/src/gaesup/stores/states/index.tsx +0 -10
- package/src/gaesup/stores/states/type.ts +0 -10
- package/src/gaesup/stores/url/index.ts +0 -6
- package/src/gaesup/stores/url/type.ts +0 -6
- /package/src/gaesup/{stores/context/controller → controller/context}/reducer.ts +0 -0
- /package/src/gaesup/{stores → tools}/gameboy/type.ts +0 -0
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useContext, useState } from "react";
|
|
2
|
+
import { GaesupToolsContext } from "../context";
|
|
3
|
+
import { usePushKey } from "../pushKey";
|
|
2
4
|
import * as style from "./style.css";
|
|
3
5
|
|
|
4
|
-
export default function GamePadButton({
|
|
6
|
+
export default function GamePadButton({
|
|
7
|
+
value,
|
|
8
|
+
name,
|
|
9
|
+
}: {
|
|
10
|
+
value: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}) {
|
|
13
|
+
const {
|
|
14
|
+
gamepad: { gamepadButtonStyle },
|
|
15
|
+
} = useContext(GaesupToolsContext);
|
|
16
|
+
const [isClicked, setIsClicked] = useState(false);
|
|
5
17
|
const { pushKey } = usePushKey();
|
|
6
18
|
|
|
7
19
|
const onMouseDown = () => {
|
|
8
20
|
pushKey(value, true);
|
|
21
|
+
setIsClicked(true);
|
|
9
22
|
};
|
|
10
23
|
|
|
11
24
|
const onMouseLeave = () => {
|
|
12
25
|
pushKey(value, false);
|
|
26
|
+
setIsClicked(false);
|
|
13
27
|
};
|
|
14
28
|
|
|
15
29
|
return (
|
|
16
30
|
<button
|
|
17
|
-
className={`${style.
|
|
31
|
+
className={`${style.padButton({
|
|
32
|
+
isClicked: isClicked,
|
|
33
|
+
})}`}
|
|
18
34
|
onMouseDown={() => onMouseDown()}
|
|
19
35
|
onMouseUp={() => onMouseLeave()}
|
|
20
36
|
onMouseLeave={() => onMouseLeave()}
|
|
@@ -24,8 +40,9 @@ export default function GamePadButton({ value }: { value: string }) {
|
|
|
24
40
|
}}
|
|
25
41
|
onPointerDown={() => onMouseDown()}
|
|
26
42
|
onPointerUp={() => onMouseLeave()}
|
|
43
|
+
style={gamepadButtonStyle}
|
|
27
44
|
>
|
|
28
|
-
{
|
|
45
|
+
{name}
|
|
29
46
|
</button>
|
|
30
47
|
);
|
|
31
48
|
}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
-
import { GaesupWorldContext } from "../../
|
|
2
|
+
import { GaesupWorldContext } from "../../world/context";
|
|
3
|
+
import { GaesupToolsContext } from "../context";
|
|
3
4
|
import GamePadButton from "./GamePadButton";
|
|
4
5
|
import * as style from "./style.css";
|
|
5
6
|
|
|
6
7
|
type gameBoyDirectionType = {
|
|
7
8
|
tag: string;
|
|
8
9
|
value: string;
|
|
10
|
+
name: string;
|
|
9
11
|
icon: JSX.Element;
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
export default function GamePad() {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
+
const {
|
|
16
|
+
gamepad: { gamepadStyle, gamepadGridStyle },
|
|
17
|
+
keyboardToolTip: { keyBoardLabel },
|
|
18
|
+
} = useContext(GaesupToolsContext);
|
|
19
|
+
const { control, mode } = useContext(GaesupWorldContext);
|
|
15
20
|
const GamePadDirections = Object.keys(control)
|
|
16
21
|
.map((key) => {
|
|
22
|
+
const name = keyBoardLabel[key] || key;
|
|
17
23
|
if (
|
|
18
24
|
key !== "forward" &&
|
|
19
25
|
key !== "backward" &&
|
|
@@ -23,6 +29,7 @@ export default function GamePad() {
|
|
|
23
29
|
return {
|
|
24
30
|
tag: key,
|
|
25
31
|
value: key,
|
|
32
|
+
name: name,
|
|
26
33
|
};
|
|
27
34
|
})
|
|
28
35
|
.filter((item) => item !== undefined)
|
|
@@ -32,10 +39,14 @@ export default function GamePad() {
|
|
|
32
39
|
);
|
|
33
40
|
|
|
34
41
|
return (
|
|
35
|
-
<div className={style.gamePad}>
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
<div className={style.gamePad} style={gamepadStyle}>
|
|
43
|
+
<div className={style.gamePadGrid} style={gamepadGridStyle}>
|
|
44
|
+
{GamePadDirections.map((item: gameBoyDirectionType, key: number) => {
|
|
45
|
+
return (
|
|
46
|
+
<GamePadButton key={key} value={item.value} name={item.name} />
|
|
47
|
+
);
|
|
48
|
+
})}
|
|
49
|
+
</div>
|
|
39
50
|
</div>
|
|
40
51
|
);
|
|
41
52
|
}
|
|
@@ -1,16 +1,71 @@
|
|
|
1
1
|
import { style } from "@vanilla-extract/css";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { recipe } from "@vanilla-extract/recipes";
|
|
3
|
+
import { fixed, grid } from "../../../styles/recipe/index.css";
|
|
4
|
+
import { vars } from "../../../styles/theme.css";
|
|
4
5
|
|
|
5
6
|
export const gamePad = style([
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
fixed({
|
|
8
|
+
south_east: true,
|
|
8
9
|
}),
|
|
9
10
|
{
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
marginRight: "5rem",
|
|
12
|
+
width: "12rem",
|
|
12
13
|
zIndex: 10000,
|
|
13
14
|
},
|
|
14
15
|
]);
|
|
15
16
|
|
|
16
|
-
export const
|
|
17
|
+
export const gamePadGrid = style([
|
|
18
|
+
grid({
|
|
19
|
+
row: "center",
|
|
20
|
+
}),
|
|
21
|
+
{
|
|
22
|
+
gridTemplateColumns: "repeat(2, 1fr)",
|
|
23
|
+
gridTemplateRows: "repeat(3, 1fr)",
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
export const padButton = recipe({
|
|
28
|
+
base: [
|
|
29
|
+
{
|
|
30
|
+
display: "flex",
|
|
31
|
+
justifyContent: "center",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
position: "relative",
|
|
34
|
+
width: "5rem",
|
|
35
|
+
height: "5rem",
|
|
36
|
+
borderRadius: "50%",
|
|
37
|
+
fontSize: "1rem",
|
|
38
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
39
|
+
color: "white",
|
|
40
|
+
boxShadow: "0 0 0.5rem rgba(0, 0, 0, 0.5)",
|
|
41
|
+
cursor: "pointer",
|
|
42
|
+
transition: "all 0.3s ease-in",
|
|
43
|
+
margin: "0.5rem",
|
|
44
|
+
":hover": {
|
|
45
|
+
boxShadow: "0 0 1rem rgba(0, 0, 0, 0.5)",
|
|
46
|
+
},
|
|
47
|
+
":after": {
|
|
48
|
+
content: "''",
|
|
49
|
+
position: "absolute",
|
|
50
|
+
width: "4rem",
|
|
51
|
+
height: "4rem",
|
|
52
|
+
borderRadius: "50%",
|
|
53
|
+
background: "rgba(0, 0, 0, 0.2)",
|
|
54
|
+
zIndex: 100000,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
variants: {
|
|
59
|
+
isClicked: {
|
|
60
|
+
true: {
|
|
61
|
+
background: vars.gradient.red,
|
|
62
|
+
boxShadow: "0 0 1rem rgba(245,177,97,1)",
|
|
63
|
+
color: "black",
|
|
64
|
+
transition: "all 0.3s ease-in",
|
|
65
|
+
":hover": {
|
|
66
|
+
boxShadow: "0 0 2rem rrgba(245,177,97,1)",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
@@ -1,61 +1,82 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useContext,
|
|
3
|
+
import { useContext, useMemo, useReducer } from "react";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
GaesupWorldDispatchContext,
|
|
8
|
-
} from "../stores/context/gaesupworld";
|
|
5
|
+
import { GaesupWorldContext } from "../world/context";
|
|
6
|
+
import { GaesupToolsContext, GaesupToolsDispatchContext } from "./context";
|
|
9
7
|
import GameBoy from "./gameboy";
|
|
8
|
+
import { gameboyDefault } from "./gameboy/default";
|
|
10
9
|
import GamePad from "./gamepad";
|
|
10
|
+
import { gamepadDefault } from "./gamepad/default";
|
|
11
11
|
import JoyStick from "./joystick";
|
|
12
|
+
import { joyStickDefault } from "./joystick/default";
|
|
12
13
|
import JumpPoint from "./jumpPoint";
|
|
13
14
|
import KeyBoardToolTip from "./keyBoardToolTip";
|
|
15
|
+
import { keyboardToolTipDefault } from "./keyBoardToolTip/default";
|
|
14
16
|
import MiniMap from "./minimap";
|
|
17
|
+
import { minimapDefault } from "./minimap/default";
|
|
18
|
+
import { gaesupToolsReducer } from "./reducer";
|
|
15
19
|
import * as style from "./style.css";
|
|
20
|
+
import { gaesupToolsPartialPropType } from "./type";
|
|
16
21
|
export default function GaeSupTools({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const keyboard = keyboardMap.reduce((maps, keyboardMapItem) => {
|
|
26
|
-
maps[keyboardMapItem.name] = false;
|
|
27
|
-
return maps;
|
|
28
|
-
}, {});
|
|
29
|
-
const assignedControl = Object.assign(control, keyboard);
|
|
22
|
+
keyboardToolTip,
|
|
23
|
+
joystick,
|
|
24
|
+
minimap,
|
|
25
|
+
gameboy,
|
|
26
|
+
gamepad,
|
|
27
|
+
}: gaesupToolsPartialPropType) {
|
|
28
|
+
const worldContext = useContext(GaesupWorldContext);
|
|
29
|
+
const { mode } = worldContext;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
|
|
31
|
+
const [tools, toolsDispatch] = useReducer(gaesupToolsReducer, {
|
|
32
|
+
keyboardToolTip: Object.assign(
|
|
33
|
+
keyboardToolTipDefault,
|
|
34
|
+
keyboardToolTip || {}
|
|
35
|
+
),
|
|
36
|
+
joystick: Object.assign(joyStickDefault, joystick || {}),
|
|
37
|
+
minimap: Object.assign(minimapDefault, minimap || {}),
|
|
38
|
+
gameboy: Object.assign(gameboyDefault, gameboy || {}),
|
|
39
|
+
gamepad: Object.assign(gamepadDefault, gamepad || {}),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const gaesupTool = useMemo(
|
|
43
|
+
() => ({
|
|
44
|
+
value: tools,
|
|
45
|
+
dispatch: toolsDispatch,
|
|
46
|
+
}),
|
|
47
|
+
[
|
|
48
|
+
tools.keyboardToolTip,
|
|
49
|
+
tools.joystick,
|
|
50
|
+
tools.minimap,
|
|
51
|
+
tools.gameboy,
|
|
52
|
+
tools.gamepad,
|
|
53
|
+
]
|
|
54
|
+
);
|
|
40
55
|
|
|
41
56
|
return (
|
|
42
|
-
|
|
43
|
-
<
|
|
44
|
-
<div className={style.
|
|
45
|
-
{
|
|
46
|
-
mode.controller === "
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
<GaesupToolsContext.Provider value={gaesupTool.value}>
|
|
58
|
+
<GaesupToolsDispatchContext.Provider value={gaesupTool.dispatch}>
|
|
59
|
+
<div className={style.footer}>
|
|
60
|
+
<div className={style.footerUpper}>
|
|
61
|
+
{(mode.controller === "joystick" ||
|
|
62
|
+
mode.controller === "gameboy") &&
|
|
63
|
+
gaesupTool.value.gamepad.on && <GamePad />}
|
|
64
|
+
</div>
|
|
65
|
+
<div className={style.footerLower}>
|
|
66
|
+
{mode.controller === "joystick" && gaesupTool.value.joystick.on && (
|
|
67
|
+
<JoyStick />
|
|
68
|
+
)}
|
|
69
|
+
{mode.controller === "gameboy" && gaesupTool.value.gameboy.on && (
|
|
70
|
+
<GameBoy />
|
|
71
|
+
)}
|
|
72
|
+
{mode.controller === "keyboard" &&
|
|
73
|
+
gaesupTool.value.keyboardToolTip.on && <KeyBoardToolTip />}
|
|
74
|
+
{gaesupTool.value.minimap.on && <MiniMap />}
|
|
75
|
+
</div>
|
|
55
76
|
</div>
|
|
56
|
-
</div>
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
78
|
+
<JumpPoint />
|
|
79
|
+
</GaesupToolsDispatchContext.Provider>
|
|
80
|
+
</GaesupToolsContext.Provider>
|
|
60
81
|
);
|
|
61
82
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
4
|
GaesupWorldContext,
|
|
4
5
|
GaesupWorldDispatchContext,
|
|
5
|
-
} from "
|
|
6
|
+
} from "../../world/context";
|
|
6
7
|
import { joyStickBallType, joyStickOriginType } from "./type";
|
|
7
8
|
|
|
8
9
|
export const joyStickBallDefault = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
position: "absolute",
|
|
12
|
-
background: "rgba(0, 0, 0, 0.5)",
|
|
13
|
-
boxShadow: "0 0 10px rgba(0, 0, 0, 0.5)",
|
|
10
|
+
top: "50%",
|
|
11
|
+
left: "50%",
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
export const joyStickOriginDefault = {
|
|
@@ -21,16 +19,20 @@ export const joyStickOriginDefault = {
|
|
|
21
19
|
originRadius: 0,
|
|
22
20
|
isIn: true,
|
|
23
21
|
isOn: false,
|
|
24
|
-
isCenter: true,
|
|
25
22
|
isUp: true,
|
|
23
|
+
isCenter: true,
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
export const
|
|
29
|
-
on:
|
|
26
|
+
export const joyStickInnerDefault = {
|
|
27
|
+
on: true,
|
|
30
28
|
joyStickBall: joyStickBallDefault,
|
|
31
29
|
joyStickOrigin: joyStickOriginDefault,
|
|
32
30
|
};
|
|
33
31
|
|
|
32
|
+
export const joyStickDefault = {
|
|
33
|
+
on: true,
|
|
34
|
+
};
|
|
35
|
+
|
|
34
36
|
export default function useJoyStick() {
|
|
35
37
|
const { joystick } = useContext(GaesupWorldContext);
|
|
36
38
|
const dispatch = useContext(GaesupWorldDispatchContext);
|
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
TouchEventHandler,
|
|
6
6
|
useCallback,
|
|
7
7
|
useContext,
|
|
8
|
+
useEffect,
|
|
8
9
|
useRef,
|
|
9
10
|
useState,
|
|
10
11
|
} from "react";
|
|
11
12
|
import { vars } from "../../../styles/theme.css";
|
|
12
|
-
import {
|
|
13
|
-
import useJoyStick from "
|
|
13
|
+
import { GaesupToolsContext } from "../context";
|
|
14
|
+
import useJoyStick from "./default";
|
|
14
15
|
import * as style from "./style.css";
|
|
15
16
|
|
|
16
17
|
export default function JoyStick() {
|
|
17
|
-
const { joystick } = useContext(GaesupWorldContext);
|
|
18
18
|
return (
|
|
19
|
-
<div className={style.joyStick}
|
|
19
|
+
<div className={style.joyStick}>
|
|
20
20
|
<JoyBall />
|
|
21
21
|
</div>
|
|
22
22
|
);
|
|
@@ -24,10 +24,15 @@ export default function JoyStick() {
|
|
|
24
24
|
|
|
25
25
|
export function JoyBall() {
|
|
26
26
|
const outerRef = useRef<HTMLDivElement>(null);
|
|
27
|
-
const
|
|
27
|
+
const childRef = useRef<HTMLDivElement>(null);
|
|
28
|
+
const {
|
|
29
|
+
joystick: { joyStickBallStyle, joyStickInnerStyle, joyStickStyle },
|
|
30
|
+
} = useContext(GaesupToolsContext);
|
|
28
31
|
const { joyStickBall, joyStickOrigin, setBall, setOrigin } = useJoyStick();
|
|
29
32
|
const [mouseDown, setMouseDown] = useState(false);
|
|
30
33
|
const [touchDown, setTouchDown] = useState(false);
|
|
34
|
+
const [background, setBackground] = useState("rgba(0, 0, 0, 0.5)");
|
|
35
|
+
const [boxShadow, setBoxShadow] = useState("0 0 10px rgba(0, 0, 0, 0.5)");
|
|
31
36
|
|
|
32
37
|
const calcOriginBall = <T extends MouseEvent | TouchEvent>(
|
|
33
38
|
e: T,
|
|
@@ -43,7 +48,6 @@ export function JoyBall() {
|
|
|
43
48
|
const normY = (joyStickOrigin.y - Y) ** 2;
|
|
44
49
|
const currentRadius = Math.sqrt(normX + normY);
|
|
45
50
|
const originRadius = Math.sqrt((width / 2) ** 2 + (height / 2) ** 2);
|
|
46
|
-
|
|
47
51
|
setOrigin({
|
|
48
52
|
x: left + width / 2,
|
|
49
53
|
y: bottom - height / 2,
|
|
@@ -55,23 +59,22 @@ export function JoyBall() {
|
|
|
55
59
|
isCenter: currentRadius < originRadius / 4,
|
|
56
60
|
isUp: top > Y - height / 2,
|
|
57
61
|
});
|
|
62
|
+
setBoxShadow("0 0 10px rgba(99,251,215,1)");
|
|
63
|
+
setBackground(
|
|
64
|
+
currentRadius > originRadius / 2
|
|
65
|
+
? vars.gradient.lightGreen
|
|
66
|
+
: vars.gradient.green
|
|
67
|
+
);
|
|
58
68
|
setBall({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
position: "fixed",
|
|
62
|
-
background:
|
|
63
|
-
currentRadius > originRadius / 2
|
|
64
|
-
? vars.gradient.lightGreen
|
|
65
|
-
: vars.gradient.green,
|
|
66
|
-
boxShadow: "0 0 10px rgba(99,251,215,1)",
|
|
69
|
+
top: `${Y}px`,
|
|
70
|
+
left: `${X}px`,
|
|
67
71
|
});
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
const initialize = (e) => {
|
|
71
75
|
const outer = e.target as HTMLDivElement;
|
|
72
76
|
const parent = outer.parentElement as HTMLDivElement;
|
|
73
|
-
const {
|
|
74
|
-
parent.getBoundingClientRect();
|
|
77
|
+
const { left, bottom, width, height } = parent.getBoundingClientRect();
|
|
75
78
|
const x = left + width / 2;
|
|
76
79
|
const y = bottom - height / 2;
|
|
77
80
|
setOrigin({
|
|
@@ -85,13 +88,7 @@ export function JoyBall() {
|
|
|
85
88
|
isCenter: true,
|
|
86
89
|
isUp: true,
|
|
87
90
|
});
|
|
88
|
-
|
|
89
|
-
x: `${-x}px`,
|
|
90
|
-
y: `${-y}px`,
|
|
91
|
-
position: "absolute",
|
|
92
|
-
background: "rgba(0, 0, 0, 0.5)",
|
|
93
|
-
boxShadow: "0 0 10px rgba(0, 0, 0, 0.5)",
|
|
94
|
-
});
|
|
91
|
+
initBall();
|
|
95
92
|
};
|
|
96
93
|
|
|
97
94
|
const handleMouseOver: MouseEventHandler = useCallback(
|
|
@@ -99,7 +96,17 @@ export function JoyBall() {
|
|
|
99
96
|
if (!mouseDown) return;
|
|
100
97
|
calcOriginBall<MouseEvent<Element>>(e, e.pageX, e.pageY);
|
|
101
98
|
},
|
|
102
|
-
[
|
|
99
|
+
[
|
|
100
|
+
joyStickBall,
|
|
101
|
+
joyStickOrigin,
|
|
102
|
+
setBall,
|
|
103
|
+
setOrigin,
|
|
104
|
+
mouseDown,
|
|
105
|
+
boxShadow,
|
|
106
|
+
background,
|
|
107
|
+
setBoxShadow,
|
|
108
|
+
setBackground,
|
|
109
|
+
]
|
|
103
110
|
);
|
|
104
111
|
|
|
105
112
|
const handleTouchMove: TouchEventHandler = useCallback(
|
|
@@ -111,59 +118,83 @@ export function JoyBall() {
|
|
|
111
118
|
e.touches[0].pageY
|
|
112
119
|
);
|
|
113
120
|
},
|
|
114
|
-
[touchDown]
|
|
121
|
+
[touchDown, boxShadow, background, setBoxShadow, setBackground]
|
|
115
122
|
);
|
|
116
123
|
|
|
117
|
-
const handleTouchEnd = useCallback(
|
|
124
|
+
const handleTouchEnd: TouchEventHandler = useCallback(
|
|
118
125
|
(e) => {
|
|
126
|
+
setTouchDown(false);
|
|
119
127
|
return initialize(e);
|
|
120
128
|
},
|
|
121
|
-
[
|
|
129
|
+
[
|
|
130
|
+
touchDown,
|
|
131
|
+
setTouchDown,
|
|
132
|
+
boxShadow,
|
|
133
|
+
background,
|
|
134
|
+
setBoxShadow,
|
|
135
|
+
setBackground,
|
|
136
|
+
]
|
|
122
137
|
);
|
|
123
|
-
const handleMouseOut = useCallback(
|
|
138
|
+
const handleMouseOut: MouseEventHandler = useCallback(
|
|
124
139
|
(e) => {
|
|
140
|
+
setMouseDown(false);
|
|
125
141
|
return initialize(e);
|
|
126
142
|
},
|
|
127
|
-
[
|
|
143
|
+
[
|
|
144
|
+
setBall,
|
|
145
|
+
setMouseDown,
|
|
146
|
+
setOrigin,
|
|
147
|
+
mouseDown,
|
|
148
|
+
boxShadow,
|
|
149
|
+
background,
|
|
150
|
+
setBoxShadow,
|
|
151
|
+
setBackground,
|
|
152
|
+
]
|
|
128
153
|
);
|
|
129
154
|
|
|
155
|
+
const initBall = () => {
|
|
156
|
+
if (outerRef.current) {
|
|
157
|
+
const { top, left, width, height } = outerRef.current.getClientRects()[0];
|
|
158
|
+
setBoxShadow("0 0 10px rgba(0, 0, 0, 0.5)");
|
|
159
|
+
setBackground("rgba(0, 0, 0, 0.5)");
|
|
160
|
+
setBall({
|
|
161
|
+
top: `${top + height / 2}px`,
|
|
162
|
+
left: `${left + width / 2}px`,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
initBall();
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
130
171
|
return (
|
|
131
|
-
|
|
132
|
-
<div
|
|
172
|
+
<div className={style.joyStick} style={joyStickStyle}>
|
|
173
|
+
<div
|
|
174
|
+
className={style.joyStickInner}
|
|
175
|
+
style={joyStickInnerStyle}
|
|
176
|
+
ref={outerRef}
|
|
177
|
+
onMouseDown={() => setMouseDown(true)}
|
|
178
|
+
onMouseUp={() => setMouseDown(false)}
|
|
179
|
+
onMouseMove={handleMouseOver}
|
|
180
|
+
onMouseLeave={(e) => handleMouseOut(e)}
|
|
181
|
+
onTouchStart={() => setTouchDown(true)}
|
|
182
|
+
onTouchEnd={(e) => handleTouchEnd(e)}
|
|
183
|
+
onTouchMove={handleTouchMove}
|
|
184
|
+
onTouchCancel={handleTouchEnd}
|
|
185
|
+
>
|
|
133
186
|
<div
|
|
134
|
-
className={style.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
handleMouseOut(e);
|
|
187
|
+
className={`${style.joystickBall}`}
|
|
188
|
+
ref={childRef}
|
|
189
|
+
style={{
|
|
190
|
+
background: joyStickBallStyle?.background || background,
|
|
191
|
+
boxShadow: joyStickBallStyle?.boxShadow || boxShadow,
|
|
192
|
+
top: joyStickBall.top,
|
|
193
|
+
left: joyStickBall.left,
|
|
194
|
+
...joyStickBallStyle,
|
|
143
195
|
}}
|
|
144
|
-
|
|
145
|
-
onTouchEnd={(e) => {
|
|
146
|
-
setTouchDown(false);
|
|
147
|
-
handleTouchEnd(e);
|
|
148
|
-
}}
|
|
149
|
-
onTouchMove={handleTouchMove}
|
|
150
|
-
onTouchCancel={handleTouchEnd}
|
|
151
|
-
>
|
|
152
|
-
<div
|
|
153
|
-
className={`${style.joystickBall}`}
|
|
154
|
-
style={{
|
|
155
|
-
position: joyStickBall.position as "fixed" | "absolute",
|
|
156
|
-
background:
|
|
157
|
-
joystick.joyStickBallStyle?.background ||
|
|
158
|
-
joyStickBall.background,
|
|
159
|
-
boxShadow:
|
|
160
|
-
joystick.joyStickBallStyle?.boxShadow || joyStickBall.boxShadow,
|
|
161
|
-
top: joyStickBall.y,
|
|
162
|
-
left: joyStickBall.x,
|
|
163
|
-
}}
|
|
164
|
-
/>
|
|
165
|
-
</div>
|
|
196
|
+
/>
|
|
166
197
|
</div>
|
|
167
|
-
|
|
198
|
+
</div>
|
|
168
199
|
);
|
|
169
200
|
}
|
|
@@ -18,21 +18,24 @@ export const joyStickInner = style([
|
|
|
18
18
|
row: "center",
|
|
19
19
|
}),
|
|
20
20
|
{
|
|
21
|
-
margin: "
|
|
22
|
-
padding: "
|
|
21
|
+
margin: "5rem",
|
|
22
|
+
padding: "1rem",
|
|
23
|
+
width: "12rem",
|
|
24
|
+
height: "12rem",
|
|
23
25
|
borderRadius: "50%",
|
|
24
26
|
background: "rgba(0, 0, 0, 0.5)",
|
|
25
27
|
boxShadow: "0 0 10px rgba(0, 0, 0, 0.5)",
|
|
28
|
+
":after": {
|
|
29
|
+
content: "''",
|
|
30
|
+
width: "10rem",
|
|
31
|
+
height: "10rem",
|
|
32
|
+
borderRadius: "50%",
|
|
33
|
+
background: "rgba(0, 0, 0, 0.2)",
|
|
34
|
+
},
|
|
26
35
|
},
|
|
27
36
|
]);
|
|
28
37
|
|
|
29
38
|
export const joystickBall = style([
|
|
30
|
-
fixed({
|
|
31
|
-
south_east: true,
|
|
32
|
-
}),
|
|
33
|
-
flex({
|
|
34
|
-
column: "7",
|
|
35
|
-
}),
|
|
36
39
|
{
|
|
37
40
|
position: "fixed",
|
|
38
41
|
width: "5rem",
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { CSSProperties } from "react";
|
|
2
2
|
|
|
3
3
|
export type joyStickBallType = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
position: string;
|
|
7
|
-
background: string;
|
|
8
|
-
boxShadow: string;
|
|
4
|
+
left: string;
|
|
5
|
+
top: string;
|
|
9
6
|
};
|
|
10
7
|
|
|
11
8
|
export type joyStickOriginType = {
|
|
@@ -16,14 +13,18 @@ export type joyStickOriginType = {
|
|
|
16
13
|
originRadius: number;
|
|
17
14
|
isIn: boolean;
|
|
18
15
|
isOn: boolean;
|
|
19
|
-
isCenter: boolean;
|
|
20
16
|
isUp: boolean;
|
|
17
|
+
isCenter: boolean;
|
|
21
18
|
};
|
|
22
19
|
|
|
23
|
-
export type
|
|
20
|
+
export type joyStickInnerType = {
|
|
24
21
|
on?: boolean;
|
|
25
22
|
joyStickBall?: joyStickBallType;
|
|
26
23
|
joyStickOrigin?: joyStickOriginType;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type joyStickType = {
|
|
27
|
+
on?: boolean;
|
|
27
28
|
joyStickStyle?: CSSProperties;
|
|
28
29
|
joyBallStyle?: CSSProperties;
|
|
29
30
|
joyStickInnerStyle?: CSSProperties;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
-
import { GaesupWorldContext } from "../../
|
|
3
|
-
import { pointType } from "../../
|
|
2
|
+
import { GaesupWorldContext } from "../../world/context";
|
|
3
|
+
import { pointType } from "../../world/context/type";
|
|
4
4
|
import * as style from "./style.css";
|
|
5
5
|
|
|
6
6
|
export default function JumpPoint() {
|