gaesup-world 0.8.31 → 0.8.34

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 _c = useContext(GaesupWorldContext), minimap = _c.minimap, clickerOption = _c.clickerOption;
21
+ var minimap = useContext(GaesupWorldContext).minimap;
22
22
  var dispatch = useContext(GaesupWorldDispatchContext);
23
23
  // clicker
24
- var _d = useClicker(), moveClicker = _d.moveClicker, moveDoubleClicker = _d.moveDoubleClicker;
24
+ var _c = useClicker(), moveClicker = _c.moveClicker, moveDoubleClicker = _c.moveDoubleClicker;
25
25
  useEffect(function () {
26
26
  if (groupRef.current) {
27
27
  var box = new THREE.Box3().setFromObject(groupRef.current);
@@ -43,19 +43,12 @@ export function GaeSupProps(_a) {
43
43
  }
44
44
  }, []);
45
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
- if (e.srcElement instanceof HTMLDivElement) {
46
+ if (e.srcElement instanceof HTMLDivElement)
51
47
  return;
52
- }
53
48
  moveClicker(e, false, type);
54
- }, onPointerUp: function (e) {
55
- e.stopPropagation();
56
- // Optionally release capture
57
- e.target.releasePointerCapture(e.pointerId);
58
49
  }, onDoubleClick: function (e) {
50
+ if (e.srcElement instanceof HTMLDivElement)
51
+ return;
59
52
  moveDoubleClicker(e, true, type);
60
53
  }, children: children }));
61
54
  }
@@ -9,26 +9,41 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { useContext } from "react";
13
- import { V3, calcNorm } from "../../utils";
12
+ import { useContext, useEffect } from "react";
13
+ import { V3 } from "../../utils";
14
14
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
15
15
  export function useClicker() {
16
16
  var _a = useContext(GaesupWorldContext), activeState = _a.activeState, mode = _a.mode, clicker = _a.clicker, clickerOption = _a.clickerOption;
17
17
  var dispatch = useContext(GaesupWorldDispatchContext);
18
+ // autoStart
19
+ useEffect(function () {
20
+ if (clickerOption.autoStart) {
21
+ var u = activeState.position;
22
+ var v = clickerOption.queue.shift();
23
+ if (clickerOption.loop) {
24
+ clickerOption.queue.push(v);
25
+ }
26
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
27
+ dispatch({
28
+ type: "update",
29
+ payload: {
30
+ clicker: __assign(__assign({}, clicker), { point: V3(v.x, 0, v.z), angle: newAngle, isOn: true }),
31
+ clickerOption: __assign({}, clickerOption),
32
+ },
33
+ });
34
+ }
35
+ }, [clickerOption.autoStart]);
18
36
  var moveClicker = function (e, isRun, type) {
19
37
  if (mode.controller !== "clicker" || type !== "ground")
20
38
  return;
21
39
  var u = activeState.position;
22
40
  var v = V3(e.point.x, e.point.y, e.point.z);
23
- var norm = calcNorm(u, v, false);
24
- if (norm < 2)
25
- return;
26
41
  var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
27
42
  dispatch({
28
43
  type: "update",
29
44
  payload: {
30
45
  clicker: {
31
- point: v,
46
+ point: V3(v.x, 0, v.z),
32
47
  angle: newAngle,
33
48
  isOn: true,
34
49
  isRun: isRun,
@@ -1,16 +1,14 @@
1
- import { useContext, useEffect } from "react";
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { useContext } from "react";
2
3
  import { V3 } from "../../utils";
3
4
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
4
5
  export function useMovePoint() {
5
6
  var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker;
6
7
  var dispatch = useContext(GaesupWorldDispatchContext);
7
8
  var move = function (position, isRun) {
8
- var originPoint = activeState.position;
9
- var newAngle = Math.atan2(position.z - originPoint.z, position.x - originPoint.x);
10
- var norm = Math.sqrt(Math.pow(position.z - originPoint.z, 2) +
11
- Math.pow(position.x - originPoint.x, 2));
12
- if (norm < 2)
13
- return;
9
+ var u = activeState.position;
10
+ var v = vec3(position);
11
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
14
12
  dispatch({
15
13
  type: "update",
16
14
  payload: {
@@ -23,22 +21,6 @@ export function useMovePoint() {
23
21
  },
24
22
  });
25
23
  };
26
- // 거리 계산
27
- useEffect(function () {
28
- var originPoint = activeState.position;
29
- var newPosition = clicker.point;
30
- var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
31
- Math.pow(newPosition.x - originPoint.x, 2));
32
- if (norm < 1) {
33
- clicker.isOn = false;
34
- dispatch({
35
- type: "update",
36
- payload: {
37
- clicker: clicker,
38
- },
39
- });
40
- }
41
- }, [activeState.position, clicker.point]);
42
24
  return {
43
25
  move: move,
44
26
  };
@@ -1,22 +1,5 @@
1
- import { joyStickInnerType } from "../../tools/joystick/type";
2
- import { activeStateType, clickerType, modeType } from "../../world/context/type";
1
+ import { gaesupWorldContextType } from "../../world/context/type";
3
2
  import { calcType } from "../type";
4
- export declare function orbitDirection({ activeState, control, mode, joystick, clicker, }: {
5
- activeState: activeStateType;
6
- mode: modeType;
7
- joystick: joyStickInnerType;
8
- clicker: clickerType;
9
- control: {
10
- [key: string]: boolean;
11
- };
12
- }): void;
13
- export declare function normalDirection({ activeState, control, mode, joystick, clicker, }: {
14
- activeState: activeStateType;
15
- mode: modeType;
16
- joystick: joyStickInnerType;
17
- clicker: clickerType;
18
- control: {
19
- [key: string]: boolean;
20
- };
21
- }): void;
3
+ export declare function orbitDirection({ activeState, control, mode, joystick, clicker, clickerOption, }: Partial<gaesupWorldContextType>): void;
4
+ export declare function normalDirection({ activeState, control, mode, joystick, clicker, clickerOption, }: Partial<gaesupWorldContextType>): void;
22
5
  export default function direction(prop: calcType): void;
@@ -1,6 +1,6 @@
1
1
  import { V3, calcAngleByVector } from "../../utils/vector";
2
2
  export function orbitDirection(_a) {
3
- var activeState = _a.activeState, control = _a.control, mode = _a.mode, joystick = _a.joystick, clicker = _a.clicker;
3
+ var activeState = _a.activeState, control = _a.control, mode = _a.mode, joystick = _a.joystick, clicker = _a.clicker, clickerOption = _a.clickerOption;
4
4
  var forward = control.forward, backward = control.backward, leftward = control.leftward, rightward = control.rightward;
5
5
  var dirX = Number(leftward) - Number(rightward);
6
6
  var dirZ = Number(forward) - Number(backward);
@@ -26,7 +26,7 @@ export function orbitDirection(_a) {
26
26
  activeState.dir = activeState.direction.normalize();
27
27
  }
28
28
  export function normalDirection(_a) {
29
- var activeState = _a.activeState, control = _a.control, mode = _a.mode, joystick = _a.joystick, clicker = _a.clicker;
29
+ var activeState = _a.activeState, control = _a.control, mode = _a.mode, joystick = _a.joystick, clicker = _a.clicker, clickerOption = _a.clickerOption;
30
30
  var forward = control.forward, backward = control.backward, leftward = control.leftward, rightward = control.rightward;
31
31
  if (mode.controller === "joystick") {
32
32
  if (joystick.joyStickOrigin.isCenter)
@@ -52,11 +52,11 @@ export function normalDirection(_a) {
52
52
  }
53
53
  }
54
54
  export default function direction(prop) {
55
- var _a = prop.worldContext, joystick = _a.joystick, mode = _a.mode, activeState = _a.activeState, control = _a.control, clicker = _a.clicker;
56
- if (mode.control === "normal") {
57
- normalDirection({ activeState: activeState, control: control, mode: mode, joystick: joystick, clicker: clicker });
55
+ var worldContext = prop.worldContext;
56
+ if (worldContext.mode.control === "normal") {
57
+ normalDirection(worldContext);
58
58
  }
59
- else if (mode.control === "orbit") {
60
- orbitDirection({ activeState: activeState, control: control, mode: mode, joystick: joystick, clicker: clicker });
59
+ else if (worldContext.mode.control === "orbit") {
60
+ orbitDirection(worldContext);
61
61
  }
62
62
  }
@@ -2,17 +2,28 @@ import { vec3 } from "@react-three/rapier";
2
2
  import { calcNorm } from "../../utils";
3
3
  export default function stop(prop) {
4
4
  var _a;
5
- var rigidBodyRef = prop.rigidBodyRef, _b = prop.worldContext, control = _b.control, clicker = _b.clicker, mode = _b.mode;
5
+ var rigidBodyRef = prop.rigidBodyRef, _b = prop.worldContext, control = _b.control, clicker = _b.clicker, mode = _b.mode, clickerOption = _b.clickerOption;
6
6
  var keyS = control.keyS;
7
7
  if (keyS && mode.controller === "clicker") {
8
8
  clicker.isOn = false;
9
9
  clicker.isRun = false;
10
10
  }
11
- // 목적지 도착
11
+ // 목적지 도착 (클리커 막기 로직)
12
12
  var u = vec3((_a = rigidBodyRef.current) === null || _a === void 0 ? void 0 : _a.translation());
13
13
  var norm = calcNorm(u, clicker.point, false);
14
14
  if (norm < 1 && mode.controller === "clicker") {
15
- clicker.isOn = false;
16
- clicker.isRun = false;
15
+ if (clickerOption.track && clickerOption.queue.length !== 0) {
16
+ clicker.point = clickerOption.queue.shift();
17
+ var v = vec3(clicker.point);
18
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
19
+ clicker.angle = newAngle;
20
+ if (clickerOption.loop) {
21
+ clickerOption.queue.push(clicker.point);
22
+ }
23
+ }
24
+ else {
25
+ clicker.isOn = false;
26
+ clicker.isRun = false;
27
+ }
17
28
  }
18
29
  }
@@ -1,8 +1,15 @@
1
- import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Line } from "@react-three/drei";
2
3
  import { useContext } from "react";
3
4
  import { GaesupWorldContext } from "../../world/context";
4
5
  export function Clicker(_a) {
5
6
  var onMarker = _a.onMarker, runMarker = _a.runMarker;
6
7
  var _b = useContext(GaesupWorldContext), clicker = _b.clicker, mode = _b.mode, clickerOption = _b.clickerOption;
7
- return (_jsx(_Fragment, { children: mode.controller === "clicker" && (_jsxs("group", { position: clicker.point, children: [clicker.isOn && onMarker, clicker.isOn && clickerOption.isRun && clicker.isRun && runMarker] })) }));
8
+ return (_jsxs(_Fragment, { children: [mode.controller === "clicker" && (_jsxs("group", { position: clicker.point, children: [clicker.isOn && onMarker, clicker.isOn && clickerOption.isRun && clicker.isRun && runMarker] })), clickerOption.line &&
9
+ clickerOption.queue.map(function (item, key) {
10
+ return (_jsxs("group", { position: [0, 1, 0], children: [key >= 1 && (_jsx(Line, { worldUnits: true, points: [
11
+ clickerOption.queue[key - 1],
12
+ clickerOption.queue[key],
13
+ ], color: "turquoise", transparent: true, opacity: 0.5, lineWidth: 0.4 })), _jsxs("mesh", { position: item, children: [_jsx("sphereGeometry", { args: [0.6, 30, 0.6] }), _jsx("meshStandardMaterial", { color: "turquoise", transparent: true, opacity: 0.8 })] }, key)] }));
14
+ })] }));
8
15
  }
@@ -48,7 +48,6 @@ export function Rideable(props) {
48
48
  var _a;
49
49
  var _b = useContext(GaesupWorldContext), states = _b.states, rideable = _b.rideable;
50
50
  var _c = useRideable(), initRideable = _c.initRideable, ride = _c.ride, landing = _c.landing;
51
- // const current = getRideable(props.objectkey);
52
51
  var _rideable = useState({
53
52
  position: props.position || V3(0, 0, 0),
54
53
  rotation: props.rotation || euler(),
@@ -125,6 +125,11 @@ export var gaesupWorldDefault = {
125
125
  clickerOption: {
126
126
  isRun: true,
127
127
  throttle: 100,
128
+ autoStart: false,
129
+ track: false,
130
+ loop: false,
131
+ queue: [],
132
+ line: false,
128
133
  },
129
134
  };
130
135
  export var GaesupWorldContext = createContext(null);
@@ -108,8 +108,13 @@ export type clickerType = {
108
108
  isRun: boolean;
109
109
  };
110
110
  export type clickerOptionType = {
111
- isRun: boolean;
112
- throttle: number;
111
+ autoStart?: boolean;
112
+ isRun?: boolean;
113
+ throttle?: number;
114
+ track?: boolean;
115
+ loop?: boolean;
116
+ queue?: THREE.Vector3[];
117
+ line?: boolean;
113
118
  };
114
119
  export type wheelStateType = {
115
120
  position: THREE.Vector3;
package/dist/index.js CHANGED
@@ -12,7 +12,6 @@ export { JumpPortal } from "./gaesup/tools/jumpPortal";
12
12
  export { KeyBoardToolTip } from "./gaesup/tools/keyBoardToolTip";
13
13
  export { MiniMap } from "./gaesup/tools/miniMap";
14
14
  export { Rideable } from "./gaesup/tools/rideable";
15
- // export { ZoomButton } from "./gaesup/tools/zoomButton";
16
15
  export { InnerHtml } from "./gaesup/utils/innerHtml";
17
16
  export { Elr, Qt, V3, V30, V31 } from "./gaesup/utils/vector";
18
17
  export { GaesupWorld } from "./gaesup/world";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaesup-world",
3
- "version": "0.8.31",
3
+ "version": "0.8.34",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",