react-simple-game-engine 0.0.8 → 0.0.9

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.
@@ -4,10 +4,11 @@ export declare type SceneRunnerPublicProps = {
4
4
  width: number;
5
5
  height: number;
6
6
  assetsLoader?: ReactNode | ComponentType;
7
+ assetsDelay?: number;
7
8
  };
8
9
  declare type SceneRunnerProps = SceneRunnerPublicProps & {
9
10
  current: Scene;
10
11
  };
11
- export declare function SceneRunner({ current, width, height, assetsLoader: AssetsLoader, }: SceneRunnerProps): JSX.Element;
12
+ export declare function SceneRunner({ assetsDelay, current, width, height, assetsLoader: AssetsLoader, }: SceneRunnerProps): JSX.Element;
12
13
  export {};
13
14
  //# sourceMappingURL=SceneRunner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SceneRunner.d.ts","sourceRoot":"","sources":["../../src/ui-components/SceneRunner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAGV,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,oBAAY,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;CAC1C,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,OAAO,EACP,KAAK,EACL,MAAM,EACN,YAAY,EAAE,YAAY,GAC3B,EAAE,gBAAgB,eAwClB"}
1
+ {"version":3,"file":"SceneRunner.d.ts","sourceRoot":"","sources":["../../src/ui-components/SceneRunner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAGV,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIzC,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;CACtB,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,WAAW,EACX,OAAO,EACP,KAAK,EACL,MAAM,EACN,YAAY,EAAE,YAAY,GAC3B,EAAE,gBAAgB,eA8ClB"}
@@ -9,14 +9,69 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
12
48
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
49
  import { useEffect, useMemo, } from "react";
14
50
  import { Sketch } from "./Sketch";
51
+ import { tick } from "../utils";
15
52
  export function SceneRunner(_a) {
16
- var current = _a.current, width = _a.width, height = _a.height, AssetsLoader = _a.assetsLoader;
53
+ var assetsDelay = _a.assetsDelay, current = _a.current, width = _a.width, height = _a.height, AssetsLoader = _a.assetsLoader;
17
54
  useEffect(function () {
18
- current.loadAssets();
19
- }, [current]);
55
+ (function () {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ if (!(assetsDelay != null)) return [3 /*break*/, 2];
61
+ // assetsDelay = 0, will wait forever
62
+ return [4 /*yield*/, tick(assetsDelay || undefined)];
63
+ case 1:
64
+ // assetsDelay = 0, will wait forever
65
+ _a.sent();
66
+ _a.label = 2;
67
+ case 2:
68
+ current.loadAssets();
69
+ return [2 /*return*/];
70
+ }
71
+ });
72
+ });
73
+ })();
74
+ }, [current, assetsDelay]);
20
75
  var setup = function (camera) {
21
76
  current.bootstrap(camera);
22
77
  };
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Avatar, Sound } from "./export-types";
2
2
  export declare function createAssetImage(src: string): Promise<Avatar>;
3
3
  export declare function createAssetSound(src: string): Promise<Sound>;
4
+ export declare function tick(delay?: number): Promise<unknown>;
4
5
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAiB/C,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAInE;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAWlE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAiB/C,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAInE;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAWlE;AAED,wBAAsB,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,oBAQxC"}
package/lib/utils.js CHANGED
@@ -73,3 +73,17 @@ export function createAssetSound(src) {
73
73
  });
74
74
  });
75
75
  }
76
+ export function tick(delay) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ return __generator(this, function (_a) {
79
+ return [2 /*return*/, new Promise(function (res) {
80
+ if (delay != null) {
81
+ setTimeout(res, delay);
82
+ }
83
+ else {
84
+ // wait forever
85
+ }
86
+ })];
87
+ });
88
+ });
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-game-engine",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib",