gaesup-world 0.8.24 → 0.8.26

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.
@@ -42,21 +42,8 @@ export function GaeSupProps(_a) {
42
42
  });
43
43
  }
44
44
  }, []);
45
- var lastClickTime = 0;
46
- function handleClick(e, cb, gap) {
47
- var currentTime = new Date().getTime();
48
- var timeDiff = currentTime - lastClickTime;
49
- if (timeDiff < gap) {
50
- e.preventDefault();
51
- return;
52
- }
53
- else {
54
- cb(e);
55
- lastClickTime = currentTime;
56
- }
57
- }
58
45
  return (_jsx("group", { ref: groupRef, position: position, onPointerDown: function (e) {
59
- handleClick(e, moveClicker, clickerOption.throttle || 100);
46
+ moveClicker(e, false, type);
60
47
  }, onDoubleClick: function (e) {
61
48
  e.stopPropagation();
62
49
  }, children: children }));
@@ -1,4 +1,5 @@
1
+ /// <reference types="lodash" />
1
2
  import { ThreeEvent } from "@react-three/fiber";
2
3
  export declare function useClicker(): {
3
- moveClicker: (e: ThreeEvent<MouseEvent>, isRun: boolean, type: "normal" | "ground") => void;
4
+ moveClicker: import("lodash").DebouncedFunc<(e: ThreeEvent<MouseEvent>, isRun: boolean, type: "normal" | "ground") => void>;
4
5
  };
@@ -1,49 +1,31 @@
1
- import { useContext, useEffect } from "react";
2
- import { V3 } from "../../utils";
1
+ import { throttle } from "lodash";
2
+ import { useContext } from "react";
3
+ import { V3, calcNorm } from "../../utils";
3
4
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
4
5
  export function useClicker() {
5
- var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker, mode = _a.mode;
6
+ var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker, mode = _a.mode, clickerOption = _a.clickerOption;
6
7
  var dispatch = useContext(GaesupWorldDispatchContext);
7
- var moveClicker = function (e, isRun, type) {
8
+ var moveClicker = throttle(function (e, isRun, type) {
8
9
  if (mode.controller !== "clicker" || type !== "ground")
9
10
  return;
10
- var originPoint = activeState.position;
11
- var newPosition = e.point;
12
- var newAngle = Math.atan2(newPosition.z - originPoint.z, newPosition.x - originPoint.x);
13
- var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
14
- Math.pow(newPosition.x - originPoint.x, 2));
11
+ var u = activeState.position;
12
+ 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
+ var norm = calcNorm(u, v, false);
15
15
  if (norm < 2)
16
16
  return;
17
17
  dispatch({
18
18
  type: "update",
19
19
  payload: {
20
20
  clicker: {
21
- point: V3(e.point.x, e.point.y, e.point.z),
21
+ point: v,
22
22
  angle: newAngle,
23
23
  isOn: true,
24
24
  isRun: isRun,
25
25
  },
26
26
  },
27
27
  });
28
- };
29
- // 거리 계산
30
- useEffect(function () {
31
- if (mode.controller !== "clicker")
32
- return;
33
- var originPoint = activeState.position;
34
- var newPosition = clicker.point;
35
- var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
36
- Math.pow(newPosition.x - originPoint.x, 2));
37
- if (norm < 1) {
38
- clicker.isOn = false;
39
- dispatch({
40
- type: "update",
41
- payload: {
42
- clicker: clicker,
43
- },
44
- });
45
- }
46
- }, [activeState.position, clicker.point]);
28
+ }, clickerOption.throttle || 500);
47
29
  return {
48
30
  moveClicker: moveClicker,
49
31
  };
@@ -1,8 +1,18 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { calcNorm } from "../../utils";
1
3
  export default function stop(prop) {
2
- var _a = prop.worldContext, control = _a.control, clicker = _a.clicker, mode = _a.mode;
4
+ var _a;
5
+ var rigidBodyRef = prop.rigidBodyRef, _b = prop.worldContext, control = _b.control, clicker = _b.clicker, mode = _b.mode;
3
6
  var keyS = control.keyS;
4
7
  if (keyS && mode.controller === "clicker") {
5
8
  clicker.isOn = false;
6
9
  clicker.isRun = false;
7
10
  }
11
+ // 목적지 도착
12
+ var u = vec3((_a = rigidBodyRef.current) === null || _a === void 0 ? void 0 : _a.translation());
13
+ var norm = calcNorm(u, clicker.point, false);
14
+ if (norm < 1 && mode.controller === "clicker") {
15
+ clicker.isOn = false;
16
+ clicker.isRun = false;
17
+ }
8
18
  }
@@ -1,5 +1,6 @@
1
1
  import * as THREE from "three";
2
2
  export declare function isVectorNonZero(v: THREE.Vector3): boolean;
3
+ export declare function calcNorm(u: THREE.Vector3, v: THREE.Vector3, calcZ: boolean): number;
3
4
  export declare function isValidOrZero(condision: boolean, vector: THREE.Vector3): THREE.Vector3;
4
5
  export declare function isValidOrOne(condision: boolean, vector: THREE.Vector3): THREE.Vector3;
5
6
  export declare function V3(x?: number, y?: number, z?: number): THREE.Vector3;
@@ -2,6 +2,11 @@ import * as THREE from "three";
2
2
  export function isVectorNonZero(v) {
3
3
  return v.toArray().every(function (value) { return value !== 0; });
4
4
  }
5
+ export function calcNorm(u, v, calcZ) {
6
+ return Math.sqrt(Math.pow(u.x - v.x, 2) +
7
+ (calcZ && Math.pow(u.y - v.y, 2)) +
8
+ Math.pow(u.z - v.z, 2));
9
+ }
5
10
  export function isValidOrZero(condision, vector) {
6
11
  return condision ? vector : new THREE.Vector3(0, 0, 0);
7
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaesup-world",
3
- "version": "0.8.24",
3
+ "version": "0.8.26",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",