react-simple-game-engine 0.3.25 → 0.3.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"movement-control.d.ts","sourceRoot":"","sources":["../../src/ui-components/movement-control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAOrE,OAAO,EACL,cAAc,EAEf,MAAM,qCAAqC,CAAC;AAE7C,oBAAY,oBAAoB,GAAG;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;CACzD,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,GAAG,EACH,IAAS,EACT,KAAK,EACL,MAAW,EACX,KAAK,GACN,EAAE,oBAAoB,eAwDtB"}
1
+ {"version":3,"file":"movement-control.d.ts","sourceRoot":"","sources":["../../src/ui-components/movement-control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,SAAS,EAMV,MAAM,OAAO,CAAC;AAOf,OAAO,EACL,cAAc,EAEf,MAAM,qCAAqC,CAAC;AAE7C,oBAAY,oBAAoB,GAAG;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;CACzD,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,GAAG,EACH,IAAS,EACT,KAAK,EACL,MAAW,EACX,KAAK,GACN,EAAE,oBAAoB,eAoFtB"}
@@ -10,17 +10,33 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { useContext, useMemo } from "react";
13
+ import { useCallback, useContext, useEffect, useMemo, useRef, } from "react";
14
14
  import { JoystickActionType } from "../export-enums";
15
15
  import { UISceneContext } from "../react-context";
16
16
  import { Watcher } from "../utilities";
17
17
  import { Joystick } from "./react-joystick-component";
18
18
  export function MovementControl(_a) {
19
19
  var render = _a.render, top = _a.top, _b = _a.left, left = _b === void 0 ? 50 : _b, right = _a.right, _c = _a.bottom, bottom = _c === void 0 ? 50 : _c, props = _a.props;
20
+ var refJoyWrap = useRef(null);
21
+ var refStick = useRef(null);
22
+ var refStickBasePosition = useRef(null);
20
23
  var scene = useContext(UISceneContext);
21
24
  var defaultShow = useMemo(function () {
22
25
  return scene.getInitialData();
23
26
  }, [scene]).joystick;
27
+ var debutStickPosition = useCallback(function (x, y) {
28
+ refJoyWrap.current.style.setProperty("--stick-center-x", x.toString());
29
+ refJoyWrap.current.style.setProperty("--stick-center-y", y.toString());
30
+ }, []);
31
+ useEffect(function () {
32
+ refStick.current = refJoyWrap.current.querySelectorAll("button")[0];
33
+ var _a = refStick.current.getBoundingClientRect(), left = _a.left, top = _a.top;
34
+ refStickBasePosition.current = {
35
+ x: left,
36
+ y: top,
37
+ };
38
+ debutStickPosition(left, top);
39
+ }, [debutStickPosition]);
24
40
  var el = useMemo(function () {
25
41
  var onAction = function (e) {
26
42
  if (e.type === JoystickActionType.MOVE) {
@@ -37,19 +53,24 @@ export function MovementControl(_a) {
37
53
  type: e.type,
38
54
  });
39
55
  }
56
+ var _a = refStick.current.getBoundingClientRect(), left = _a.left, top = _a.top;
57
+ var stickCenterX = left - refStickBasePosition.current.x;
58
+ var stickCenterY = top - refStickBasePosition.current.y;
59
+ debutStickPosition(stickCenterX, stickCenterY);
40
60
  };
41
- return (_jsx("div", __assign({ style: {
61
+ var joystick = (_jsx(Joystick, __assign({ size: 60, baseColor: "#2D2D2D", stickColor: "rgb(120,121,122)", throttle: 100 }, props, { start: onAction, move: onAction, stop: onAction })));
62
+ return (_jsx("div", __assign({ ref: refJoyWrap, style: {
42
63
  position: "absolute",
43
64
  left: right != null ? undefined : left,
44
65
  right: right,
45
66
  bottom: top != null ? undefined : bottom,
46
67
  top: top,
47
- } }, { children: _jsx(Joystick, __assign({ size: 60, baseColor: "#2D2D2D", stickColor: "rgb(120,121,122)", throttle: 100 }, props, { start: onAction, move: onAction, stop: onAction })) })));
48
- }, [props]);
68
+ } }, { children: render ? render(joystick) : joystick })));
69
+ }, [props, debutStickPosition]);
49
70
  return (_jsx(Watcher, __assign({ initialValues: {
50
71
  isShow: defaultShow,
51
72
  }, names: "control-visible" }, { children: function (_a) {
52
73
  var isShow = _a.isShow;
53
- return (isShow ? (render ? render(el) : el) : null);
74
+ return (isShow ? el : null);
54
75
  } })));
55
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-game-engine",
3
- "version": "0.3.25",
3
+ "version": "0.3.27",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib",