gaesup-world 0.8.26 → 0.8.27
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.
|
@@ -21,7 +21,7 @@ export function GaeSupProps(_a) {
|
|
|
21
21
|
var _c = useContext(GaesupWorldContext), minimap = _c.minimap, clickerOption = _c.clickerOption;
|
|
22
22
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
23
23
|
// clicker
|
|
24
|
-
var
|
|
24
|
+
var _d = useClicker(), moveClicker = _d.moveClicker, moveDoubleClicker = _d.moveDoubleClicker;
|
|
25
25
|
useEffect(function () {
|
|
26
26
|
if (groupRef.current) {
|
|
27
27
|
var box = new THREE.Box3().setFromObject(groupRef.current);
|
|
@@ -45,6 +45,6 @@ export function GaeSupProps(_a) {
|
|
|
45
45
|
return (_jsx("group", { ref: groupRef, position: position, onPointerDown: function (e) {
|
|
46
46
|
moveClicker(e, false, type);
|
|
47
47
|
}, onDoubleClick: function (e) {
|
|
48
|
-
e
|
|
48
|
+
moveDoubleClicker(e, true, type);
|
|
49
49
|
}, children: children }));
|
|
50
50
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="lodash" />
|
|
2
1
|
import { ThreeEvent } from "@react-three/fiber";
|
|
3
2
|
export declare function useClicker(): {
|
|
4
|
-
moveClicker:
|
|
3
|
+
moveClicker: (e: ThreeEvent<MouseEvent>, isRun: boolean, type: "normal" | "ground") => void;
|
|
4
|
+
moveDoubleClicker: (e: ThreeEvent<MouseEvent>, isRun: boolean, type: "normal" | "ground") => void;
|
|
5
5
|
};
|
|
@@ -1,32 +1,52 @@
|
|
|
1
|
-
import { throttle } from "lodash";
|
|
2
1
|
import { useContext } from "react";
|
|
3
2
|
import { V3, calcNorm } from "../../utils";
|
|
4
3
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
|
|
5
4
|
export function useClicker() {
|
|
6
|
-
var _a = useContext(GaesupWorldContext), activeState = _a.activeState,
|
|
5
|
+
var _a = useContext(GaesupWorldContext), activeState = _a.activeState, mode = _a.mode, clicker = _a.clicker, clickerOption = _a.clickerOption;
|
|
7
6
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
8
|
-
var moveClicker =
|
|
7
|
+
var moveClicker = function (e, isRun, type) {
|
|
9
8
|
if (mode.controller !== "clicker" || type !== "ground")
|
|
10
9
|
return;
|
|
11
10
|
var u = activeState.position;
|
|
12
11
|
var v = V3(e.point.x, e.point.y, e.point.z);
|
|
13
|
-
var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
|
|
14
12
|
var norm = calcNorm(u, v, false);
|
|
15
13
|
if (norm < 2)
|
|
16
14
|
return;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
|
|
16
|
+
clicker.point = v;
|
|
17
|
+
clicker.angle = newAngle;
|
|
18
|
+
clicker.isOn = true;
|
|
19
|
+
clicker.isRun = isRun;
|
|
20
|
+
// dispatch({
|
|
21
|
+
// type: "update",
|
|
22
|
+
// payload: {
|
|
23
|
+
// clicker: {
|
|
24
|
+
// point: v,
|
|
25
|
+
// angle: newAngle,
|
|
26
|
+
// isOn: true,
|
|
27
|
+
// isRun: isRun,
|
|
28
|
+
// },
|
|
29
|
+
// },
|
|
30
|
+
// });
|
|
31
|
+
};
|
|
32
|
+
var moveDoubleClicker = function (e, isRun, type) {
|
|
33
|
+
if (!clicker.isOn || !clickerOption.isRun)
|
|
34
|
+
return;
|
|
35
|
+
clicker.isRun = isRun;
|
|
36
|
+
// dispatch({
|
|
37
|
+
// type: "update",
|
|
38
|
+
// payload: {
|
|
39
|
+
// clicker: {
|
|
40
|
+
// point: v,
|
|
41
|
+
// angle: newAngle,
|
|
42
|
+
// isOn: true,
|
|
43
|
+
// isRun: isRun,
|
|
44
|
+
// },
|
|
45
|
+
// },
|
|
46
|
+
// });
|
|
47
|
+
};
|
|
29
48
|
return {
|
|
30
49
|
moveClicker: moveClicker,
|
|
50
|
+
moveDoubleClicker: moveDoubleClicker,
|
|
31
51
|
};
|
|
32
52
|
}
|