react-simple-game-engine 0.3.25 → 0.3.26
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,
|
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;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,eA0FtB"}
|
@@ -10,17 +10,28 @@ 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 { 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
|
+
useEffect(function () {
|
28
|
+
refStick.current = refJoyWrap.current.querySelectorAll("button")[0];
|
29
|
+
var _a = refStick.current.getBoundingClientRect(), left = _a.left, top = _a.top;
|
30
|
+
refStickBasePosition.current = {
|
31
|
+
x: left,
|
32
|
+
y: top,
|
33
|
+
};
|
34
|
+
}, []);
|
24
35
|
var el = useMemo(function () {
|
25
36
|
var onAction = function (e) {
|
26
37
|
if (e.type === JoystickActionType.MOVE) {
|
@@ -37,19 +48,27 @@ export function MovementControl(_a) {
|
|
37
48
|
type: e.type,
|
38
49
|
});
|
39
50
|
}
|
51
|
+
var _a = refStick.current.getBoundingClientRect(), left = _a.left, top = _a.top;
|
52
|
+
var stickBaseX = left - refStickBasePosition.current.x;
|
53
|
+
var stickBaseY = top - refStickBasePosition.current.y;
|
54
|
+
refJoyWrap.current.style.setProperty("--stick-base-x", stickBaseX.toString());
|
55
|
+
refJoyWrap.current.style.setProperty("--stick-base-y", stickBaseY.toString());
|
40
56
|
};
|
41
|
-
|
57
|
+
var joystick = (_jsx(Joystick, __assign({ size: 60, baseColor: "#2D2D2D", stickColor: "rgb(120,121,122)", throttle: 100 }, props, { start: onAction, move: onAction, stop: onAction })));
|
58
|
+
return (_jsx("div", __assign({ ref: refJoyWrap, style: {
|
59
|
+
"--stick-base-x": refStickBasePosition.current.x,
|
60
|
+
"--stick-base-y": refStickBasePosition.current.y,
|
42
61
|
position: "absolute",
|
43
62
|
left: right != null ? undefined : left,
|
44
63
|
right: right,
|
45
64
|
bottom: top != null ? undefined : bottom,
|
46
65
|
top: top,
|
47
|
-
} }, { children:
|
66
|
+
} }, { children: render ? render(joystick) : joystick })));
|
48
67
|
}, [props]);
|
49
68
|
return (_jsx(Watcher, __assign({ initialValues: {
|
50
69
|
isShow: defaultShow,
|
51
70
|
}, names: "control-visible" }, { children: function (_a) {
|
52
71
|
var isShow = _a.isShow;
|
53
|
-
return (isShow ?
|
72
|
+
return (isShow ? el : null);
|
54
73
|
} })));
|
55
74
|
}
|