gaesup-world 0.8.2 → 0.8.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.
@@ -18,10 +18,10 @@ import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../world/contex
18
18
  export function GaeSupProps(_a) {
19
19
  var _b = _a.type, type = _b === void 0 ? "normal" : _b, text = _a.text, position = _a.position, children = _a.children;
20
20
  var groupRef = useRef(null);
21
- var minimap = useContext(GaesupWorldContext).minimap;
21
+ var _c = useContext(GaesupWorldContext), minimap = _c.minimap, clickerOption = _c.clickerOption;
22
22
  var dispatch = useContext(GaesupWorldDispatchContext);
23
23
  // clicker
24
- var moveClicker = useClicker().moveClicker;
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);
@@ -42,5 +42,17 @@ export function GaeSupProps(_a) {
42
42
  });
43
43
  }
44
44
  }, []);
45
- return (_jsx("group", { ref: groupRef, position: position, onPointerDown: function (e) { return moveClicker(e, false, type); }, onDoubleClick: function (e) { return moveClicker(e, true, type); }, children: children }));
45
+ return (_jsx("group", { ref: groupRef, position: position, onPointerDown: function (e) {
46
+ // Only the mesh closest to the camera will be processed
47
+ e.stopPropagation();
48
+ // You may optionally capture the target
49
+ e.target.setPointerCapture(e.pointerId);
50
+ moveClicker(e, false, type);
51
+ }, onPointerUp: function (e) {
52
+ e.stopPropagation();
53
+ // Optionally release capture
54
+ e.target.releasePointerCapture(e.pointerId);
55
+ }, onDoubleClick: function (e) {
56
+ moveDoubleClicker(e, true, type);
57
+ }, children: children }));
46
58
  }
@@ -1,4 +1,5 @@
1
1
  import { ThreeEvent } from "@react-three/fiber";
2
2
  export declare function useClicker(): {
3
3
  moveClicker: (e: ThreeEvent<MouseEvent>, isRun: boolean, type: "normal" | "ground") => void;
4
+ moveDoubleClicker: (e: ThreeEvent<MouseEvent>, isRun: boolean, type: "normal" | "ground") => void;
4
5
  };
@@ -1,24 +1,37 @@
1
- import { useContext, useEffect } from "react";
2
- import { V3 } from "../../utils";
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useContext } from "react";
13
+ import { V3, calcNorm } from "../../utils";
3
14
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
4
15
  export function useClicker() {
5
- var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker, mode = _a.mode;
16
+ var _a = useContext(GaesupWorldContext), activeState = _a.activeState, mode = _a.mode, clicker = _a.clicker, clickerOption = _a.clickerOption;
6
17
  var dispatch = useContext(GaesupWorldDispatchContext);
7
18
  var moveClicker = function (e, isRun, type) {
8
19
  if (mode.controller !== "clicker" || type !== "ground")
9
20
  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));
21
+ var u = activeState.position;
22
+ var v = V3(e.point.x, e.point.y, e.point.z);
23
+ var norm = calcNorm(u, v, false);
15
24
  if (norm < 2)
16
25
  return;
26
+ var gap = calcNorm(v, clicker.point, true);
27
+ if (gap < 1)
28
+ return;
29
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
17
30
  dispatch({
18
31
  type: "update",
19
32
  payload: {
20
33
  clicker: {
21
- point: V3(e.point.x, e.point.y, e.point.z),
34
+ point: v,
22
35
  angle: newAngle,
23
36
  isOn: true,
24
37
  isRun: isRun,
@@ -26,25 +39,18 @@ export function useClicker() {
26
39
  },
27
40
  });
28
41
  };
29
- // 거리 계산
30
- useEffect(function () {
31
- if (mode.controller !== "clicker")
42
+ var moveDoubleClicker = function (e, isRun, type) {
43
+ if (!clicker.isOn || !clickerOption.isRun)
32
44
  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]);
45
+ dispatch({
46
+ type: "update",
47
+ payload: {
48
+ clicker: __assign(__assign({}, clicker), { isRun: isRun }),
49
+ },
50
+ });
51
+ };
47
52
  return {
48
53
  moveClicker: moveClicker,
54
+ moveDoubleClicker: moveDoubleClicker,
49
55
  };
50
56
  }
@@ -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.2",
3
+ "version": "0.8.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",