react-simple-game-engine 0.2.25 → 0.2.26

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.
@@ -0,0 +1,14 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { IJoystickProps } from "react-joystick-component/build/lib/Joystick";
3
+ import { Scene } from "../classes/scene";
4
+ export declare type ControlProps = {
5
+ scene: Scene;
6
+ top?: number;
7
+ left?: number;
8
+ right?: number;
9
+ bottom?: number;
10
+ render?: (el: ReactElement) => ReactNode;
11
+ props: IJoystickProps;
12
+ };
13
+ export declare function Control({ scene, render, top, left, right, bottom, props, }: ControlProps): JSX.Element;
14
+ //# sourceMappingURL=control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/ui-components/control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AACzD,OAAO,EACL,cAAc,EAEf,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIzC,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,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,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,MAAM,EACN,GAAG,EACH,IAAS,EACT,KAAK,EACL,MAAW,EACX,KAAK,GACN,EAAE,YAAY,eA4Bd"}
@@ -0,0 +1,28 @@
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 { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useMemo } from "react";
14
+ import { Joystick, } from "react-joystick-component/build/lib/Joystick";
15
+ import { Watcher } from "../utilities";
16
+ import { FloatContainer } from "./float-container";
17
+ export function Control(_a) {
18
+ var scene = _a.scene, 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;
19
+ var el = useMemo(function () {
20
+ return (_jsx("div", __assign({ style: { position: "absolute", top: top, left: left, right: right, bottom: bottom } }, { children: _jsx(Joystick, __assign({ size: 100, baseColor: "#2D2D2D", stickColor: "##303134", throttle: 500 }, props)) })));
21
+ }, [props]);
22
+ return (_jsx(FloatContainer, { children: _jsx(Watcher, __assign({ initialValues: {
23
+ isShow: true,
24
+ }, scene: scene, names: "control-visible" }, { children: function (_a) {
25
+ var isShow = _a.isShow;
26
+ return (isShow ? (render ? render(el) : el) : null);
27
+ } })) }));
28
+ }
@@ -0,0 +1,8 @@
1
+ import { CSSProperties, ReactNode } from "react";
2
+ declare type FloatContainerProps = {
3
+ style?: CSSProperties;
4
+ children: ReactNode;
5
+ };
6
+ export declare function FloatContainer({ children, style }: FloatContainerProps): JSX.Element;
7
+ export {};
8
+ //# sourceMappingURL=float-container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"float-container.d.ts","sourceRoot":"","sources":["../../src/ui-components/float-container.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjD,aAAK,mBAAmB,GAAG;IACzB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,mBAAmB,eAiBtE"}
@@ -0,0 +1,16 @@
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 { jsx as _jsx } from "react/jsx-runtime";
13
+ export function FloatContainer(_a) {
14
+ var children = _a.children, style = _a.style;
15
+ return (_jsx("div", __assign({ style: __assign({ position: "absolute", top: 0, left: 0, right: 0, bottom: 0 }, style) }, { children: _jsx("div", __assign({ style: { position: "relative", width: "100%", height: "100%" } }, { children: children })) })));
16
+ }
@@ -1,6 +1,7 @@
1
1
  import { ComponentType, ReactNode } from "react";
2
2
  import { AssetsFailBehavior, Scene } from "../classes/scene";
3
3
  import { LayoutMode } from "../export-enums";
4
+ import { ControlProps } from "./control";
4
5
  export declare type SceneRunnerPublicProps = {
5
6
  width: number;
6
7
  height: number;
@@ -9,10 +10,11 @@ export declare type SceneRunnerPublicProps = {
9
10
  assetsFailBehavior?: AssetsFailBehavior;
10
11
  layoutMode?: LayoutMode;
11
12
  voidSpace?: ReactNode;
13
+ joystick?: Omit<ControlProps, "scene">;
12
14
  };
13
15
  declare type SceneRunnerProps = SceneRunnerPublicProps & {
14
16
  current: Scene;
15
17
  };
16
- export declare function SceneRunner({ width, height, current, layoutMode, voidSpace, assetsDelay, assetsFailBehavior, assetsLoader: AssetsLoader, }: SceneRunnerProps): JSX.Element;
18
+ export declare function SceneRunner({ width, height, current, layoutMode, voidSpace, assetsDelay, assetsFailBehavior, assetsLoader: AssetsLoader, joystick, }: SceneRunnerProps): JSX.Element;
17
19
  export {};
18
20
  //# sourceMappingURL=scene-runner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scene-runner.d.ts","sourceRoot":"","sources":["../../src/ui-components/scene-runner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAKV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAI7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,oBAAY,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAiC,EAEjC,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,YAAY,EAAE,YAAY,GAC3B,EAAE,gBAAgB,eAmJlB"}
1
+ {"version":3,"file":"scene-runner.d.ts","sourceRoot":"","sources":["../../src/ui-components/scene-runner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAKV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAQ7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AAGlD,oBAAY,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAiC,EAEjC,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,YAAY,EAAE,YAAY,EAC1B,QAAQ,GACT,EAAE,gBAAgB,eA0IlB"}
@@ -11,15 +11,17 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
13
  import { useEffect, useMemo, useRef, useState, } from "react";
14
- import { useWindowSize } from "../utils";
15
- import { LayoutMode } from "../export-enums";
16
- import { ScalerContainer } from "./scaler-container";
17
14
  import { Scaler } from "../classes/scaler";
15
+ import { ScalerContainer } from "./scaler-container";
18
16
  import { Sketch } from "./sketch";
17
+ import { useWindowSize } from "../utils";
18
+ import { LayoutMode } from "../export-enums";
19
+ import { Control } from "./control";
20
+ import { FloatContainer } from "./float-container";
19
21
  export function SceneRunner(_a) {
20
22
  var width = _a.width, height = _a.height, current = _a.current, _b = _a.layoutMode, layoutMode = _b === void 0 ? LayoutMode.LANDSCAPE : _b,
21
23
  //
22
- voidSpace = _a.voidSpace, assetsDelay = _a.assetsDelay, assetsFailBehavior = _a.assetsFailBehavior, AssetsLoader = _a.assetsLoader;
24
+ voidSpace = _a.voidSpace, assetsDelay = _a.assetsDelay, assetsFailBehavior = _a.assetsFailBehavior, AssetsLoader = _a.assetsLoader, joystick = _a.joystick;
23
25
  var screenSize = useWindowSize();
24
26
  var refScaler = useRef(new Scaler(screenSize, { width: width, height: height }, layoutMode));
25
27
  var _c = useState(false), isBootDone = _c[0], setBootDone = _c[1];
@@ -71,22 +73,12 @@ export function SceneRunner(_a) {
71
73
  msUserSelect: "none",
72
74
  userSelect: "none",
73
75
  textSizeAdjust: "none",
74
- } }, { children: [_jsx("div", __assign({ style: {
75
- position: "absolute",
76
- top: 0,
77
- left: 0,
78
- width: "100%",
79
- height: "100%",
76
+ } }, { children: [_jsx(FloatContainer, __assign({ style: {
80
77
  zIndex: -1,
81
78
  backgroundColor: "rgb(41,41,41)",
82
79
  } }, { children: voidSpace })), _jsx(ScalerContainer, __assign({ value: refScaler.current.value, width: width, height: height }, { children: current.loadedAssets && (
83
80
  // canvas
84
- _jsx(Sketch, { onSetup: setup, onDraw: draw, scaler: refScaler.current })) })), _jsx("div", __assign({ style: {
85
- position: "absolute",
86
- top: 0,
87
- left: 0,
88
- width: "100%",
89
- height: "100%",
81
+ _jsx(Sketch, { onSetup: setup, onDraw: draw, scaler: refScaler.current })) })), _jsx(FloatContainer, __assign({ style: {
90
82
  zIndex: 2,
91
83
  } }, { children: !current.loadedAssets ? (_jsx(_Fragment, { children: current.renderAssetsFail
92
84
  ? (function () {
@@ -101,5 +93,5 @@ export function SceneRunner(_a) {
101
93
  }
102
94
  return rendered;
103
95
  })()
104
- : assetsLoader })) : (_jsx(_Fragment, { children: isBootDone ? (_jsx(ScalerContainer, __assign({ value: refScaler.current.value, height: height, width: width }, { children: _jsx(current.UI, __assign({ scene: current }, current.UIProps)) }))) : (_jsx("div", {})) })) }))] })));
96
+ : assetsLoader })) : (_jsx(_Fragment, { children: isBootDone ? (_jsxs(ScalerContainer, __assign({ value: refScaler.current.value, height: height, width: width }, { children: [joystick && _jsx(Control, __assign({ scene: current }, joystick)), _jsx(current.UI, __assign({ scene: current }, current.UIProps))] }))) : (_jsx("div", {})) })) }))] })));
105
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-game-engine",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib",
@@ -9,7 +9,8 @@
9
9
  "@types/matter-js": "^0.17.7",
10
10
  "@types/p5": "^1.4.2",
11
11
  "matter-js": "^0.18.0",
12
- "p5": "^1.4.1"
12
+ "p5": "^1.4.1",
13
+ "react-joystick-component": "^4.0.1"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@types/node": "^16.7.13",
@@ -36,6 +37,9 @@
36
37
  "react simple game engine",
37
38
  "reactjs game",
38
39
  "reactjs game engine",
40
+ "joystick game engine",
41
+ "joystick engine",
42
+ "joystick",
39
43
  "reactjs simple game engine"
40
44
  ]
41
45
  }