react-simple-game-engine 0.3.28 → 0.3.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,11 @@
1
- import { ReactElement, ReactNode } from "react";
1
+ import { MutableRefObject, ReactElement, ReactNode } from "react";
2
2
  import { IJoystickProps } from "./react-joystick-component/Joystick";
3
3
  declare type TouchEvent = {
4
4
  onPressed?: (container: HTMLDivElement, stick: HTMLButtonElement) => void;
5
5
  onReleased?: (container: HTMLDivElement, stick: HTMLButtonElement) => void;
6
6
  };
7
- export declare type MovementControlProps = TouchEvent & {
7
+ export declare type MovementControlProps = {
8
+ containerRef?: MutableRefObject<HTMLDivElement>;
8
9
  top?: number;
9
10
  left?: number;
10
11
  right?: number;
@@ -14,6 +15,6 @@ export declare type MovementControlProps = TouchEvent & {
14
15
  containerTouchEvent?: TouchEvent;
15
16
  props?: Omit<IJoystickProps, "start" | "move" | "stop">;
16
17
  };
17
- export declare function MovementControl({ render, top, left, right, bottom, props, containerTouchEvent, joystickTouchEvent, }: MovementControlProps): JSX.Element;
18
+ export declare function MovementControl({ render, top, left, right, bottom, props, containerTouchEvent, joystickTouchEvent, containerRef, }: MovementControlProps): JSX.Element;
18
19
  export {};
19
20
  //# sourceMappingURL=movement-control.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"movement-control.d.ts","sourceRoot":"","sources":["../../src/ui-components/movement-control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,SAAS,EAKV,MAAM,OAAO,CAAC;AAMf,OAAO,EACL,cAAc,EAEf,MAAM,qCAAqC,CAAC;AAE7C,aAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC1E,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC5E,CAAC;AACF,oBAAY,oBAAoB,GAAG,UAAU,GAAG;IAC9C,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,kBAAkB,CAAC,EAAE,UAAU,CAAC;IAChC,mBAAmB,CAAC,EAAE,UAAU,CAAC;IACjC,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,EACL,mBAAmB,EACnB,kBAAkB,GACnB,EAAE,oBAAoB,eAwGtB"}
1
+ {"version":3,"file":"movement-control.d.ts","sourceRoot":"","sources":["../../src/ui-components/movement-control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,YAAY,EACZ,SAAS,EAKV,MAAM,OAAO,CAAC;AAMf,OAAO,EACL,cAAc,EAEf,MAAM,qCAAqC,CAAC;AAE7C,aAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC1E,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC5E,CAAC;AACF,oBAAY,oBAAoB,GAAG;IACjC,YAAY,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAChD,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,kBAAkB,CAAC,EAAE,UAAU,CAAC;IAChC,mBAAmB,CAAC,EAAE,UAAU,CAAC;IACjC,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,EACL,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,GACb,EAAE,oBAAoB,eA4GtB"}
@@ -16,13 +16,18 @@ 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
- 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, containerTouchEvent = _a.containerTouchEvent, joystickTouchEvent = _a.joystickTouchEvent;
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, containerTouchEvent = _a.containerTouchEvent, joystickTouchEvent = _a.joystickTouchEvent, containerRef = _a.containerRef;
20
20
  var refJoyWrap = useRef(null);
21
21
  var refStick = useRef(null);
22
22
  var scene = useContext(UISceneContext);
23
23
  var defaultShow = useMemo(function () {
24
24
  return scene.getInitialData();
25
25
  }, [scene]).joystick;
26
+ useEffect(function () {
27
+ if (containerRef) {
28
+ containerRef.current = refJoyWrap.current;
29
+ }
30
+ }, [containerRef]);
26
31
  useEffect(function () {
27
32
  refStick.current = refJoyWrap.current.querySelectorAll("button")[0];
28
33
  if (!joystickTouchEvent) {
@@ -63,7 +68,7 @@ export function MovementControl(_a) {
63
68
  }
64
69
  };
65
70
  var joystick = (_jsx(Joystick, __assign({ size: 60, baseColor: "#2D2D2D", stickColor: "rgb(120,121,122)", throttle: 100 }, props, { start: onAction, move: onAction, stop: onAction })));
66
- return (_jsx("div", __assign({ onPointerDown: function (event) {
71
+ return (_jsx("div", __assign({ ref: refJoyWrap, onPointerDown: function (event) {
67
72
  var _a;
68
73
  event.target.setPointerCapture(event.pointerId);
69
74
  (_a = containerTouchEvent === null || containerTouchEvent === void 0 ? void 0 : containerTouchEvent.onPressed) === null || _a === void 0 ? void 0 : _a.call(containerTouchEvent, refJoyWrap.current, refStick.current);
@@ -71,9 +76,7 @@ export function MovementControl(_a) {
71
76
  var _a;
72
77
  event.target.releasePointerCapture(event.pointerId);
73
78
  (_a = containerTouchEvent === null || containerTouchEvent === void 0 ? void 0 : containerTouchEvent.onReleased) === null || _a === void 0 ? void 0 : _a.call(containerTouchEvent, refJoyWrap.current, refStick.current);
74
- }, ref: refJoyWrap, style: {
75
- "--stick-center-x": 0,
76
- "--stick-center-y": 0,
79
+ }, style: {
77
80
  position: "absolute",
78
81
  left: right != null ? undefined : left,
79
82
  right: right,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-game-engine",
3
- "version": "0.3.28",
3
+ "version": "0.3.29",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib",