react-simple-game-engine 0.1.61 → 0.1.64

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.
Files changed (103) hide show
  1. package/lib/classes/animations/animation.d.ts +14 -0
  2. package/lib/classes/animations/animation.d.ts.map +1 -0
  3. package/lib/classes/animations/animation.js +35 -0
  4. package/lib/classes/animations/avatar.animation.d.ts +16 -0
  5. package/lib/classes/animations/avatar.animation.d.ts.map +1 -0
  6. package/lib/classes/animations/avatar.animation.js +45 -0
  7. package/lib/classes/animations/color.animation.d.ts +9 -0
  8. package/lib/classes/animations/color.animation.d.ts.map +1 -0
  9. package/lib/classes/animations/color.animation.js +33 -0
  10. package/lib/classes/camera.d.ts +14 -0
  11. package/lib/classes/camera.d.ts.map +1 -0
  12. package/lib/classes/camera.js +34 -0
  13. package/lib/classes/entities/circle.entity.d.ts +15 -0
  14. package/lib/classes/entities/circle.entity.d.ts.map +1 -0
  15. package/lib/classes/entities/circle.entity.js +55 -0
  16. package/lib/classes/entities/entity-sult.d.ts +34 -0
  17. package/lib/classes/entities/entity-sult.d.ts.map +1 -0
  18. package/lib/classes/entities/entity-sult.js +108 -0
  19. package/lib/classes/entities/entity.d.ts +55 -0
  20. package/lib/classes/entities/entity.d.ts.map +1 -0
  21. package/lib/classes/entities/entity.js +180 -0
  22. package/lib/classes/entities/rect.entity.d.ts +17 -0
  23. package/lib/classes/entities/rect.entity.d.ts.map +1 -0
  24. package/lib/classes/entities/rect.entity.js +56 -0
  25. package/lib/classes/logic-component.d.ts +16 -0
  26. package/lib/classes/logic-component.d.ts.map +1 -0
  27. package/lib/classes/logic-component.js +77 -0
  28. package/lib/classes/p5.d.ts +11 -0
  29. package/lib/classes/p5.d.ts.map +1 -0
  30. package/lib/classes/p5.js +58 -0
  31. package/lib/classes/particle-system.d.ts +30 -0
  32. package/lib/classes/particle-system.d.ts.map +1 -0
  33. package/lib/classes/particle-system.js +98 -0
  34. package/lib/classes/particle.d.ts +35 -0
  35. package/lib/classes/particle.d.ts.map +1 -0
  36. package/lib/classes/particle.js +117 -0
  37. package/lib/classes/prefab.d.ts +7 -0
  38. package/lib/classes/prefab.d.ts.map +1 -0
  39. package/lib/classes/prefab.js +24 -0
  40. package/lib/classes/saver.d.ts +11 -0
  41. package/lib/classes/saver.d.ts.map +1 -0
  42. package/lib/classes/saver.js +33 -0
  43. package/lib/classes/scene-management.d.ts +22 -0
  44. package/lib/classes/scene-management.d.ts.map +1 -0
  45. package/lib/classes/scene-management.js +58 -0
  46. package/lib/classes/scene.d.ts +75 -0
  47. package/lib/classes/scene.d.ts.map +1 -0
  48. package/lib/classes/scene.js +433 -0
  49. package/lib/classes/sound-watcher.d.ts +16 -0
  50. package/lib/classes/sound-watcher.d.ts.map +1 -0
  51. package/lib/classes/sound-watcher.js +33 -0
  52. package/lib/classes/sound.d.ts +14 -0
  53. package/lib/classes/sound.d.ts.map +1 -0
  54. package/lib/classes/sound.js +119 -0
  55. package/lib/classes/sprites/avatar.sprite.d.ts +20 -0
  56. package/lib/classes/sprites/avatar.sprite.d.ts.map +1 -0
  57. package/lib/classes/sprites/avatar.sprite.js +89 -0
  58. package/lib/classes/sprites/color.sprite.d.ts +7 -0
  59. package/lib/classes/sprites/color.sprite.d.ts.map +1 -0
  60. package/lib/classes/sprites/color.sprite.js +40 -0
  61. package/lib/classes/sprites/sprite.d.ts +26 -0
  62. package/lib/classes/sprites/sprite.d.ts.map +1 -0
  63. package/lib/classes/sprites/sprite.js +70 -0
  64. package/lib/classes/watcher.d.ts +11 -0
  65. package/lib/classes/watcher.d.ts.map +1 -0
  66. package/lib/classes/watcher.js +44 -0
  67. package/lib/classes/world-management.d.ts +28 -0
  68. package/lib/classes/world-management.d.ts.map +1 -0
  69. package/lib/classes/world-management.js +160 -0
  70. package/lib/decorators/scene-tag.decor.d.ts +6 -0
  71. package/lib/decorators/scene-tag.decor.d.ts.map +1 -0
  72. package/lib/decorators/scene-tag.decor.js +5 -0
  73. package/lib/decorators/scene-ui.decor.d.ts +7 -0
  74. package/lib/decorators/scene-ui.decor.d.ts.map +1 -0
  75. package/lib/decorators/scene-ui.decor.js +5 -0
  76. package/lib/decorators/sound-from.decor.d.ts +6 -0
  77. package/lib/decorators/sound-from.decor.d.ts.map +1 -0
  78. package/lib/decorators/sound-from.decor.js +17 -0
  79. package/lib/decorators/sprite-from.decor.d.ts +4 -0
  80. package/lib/decorators/sprite-from.decor.d.ts.map +1 -0
  81. package/lib/decorators/sprite-from.decor.js +13 -0
  82. package/lib/export-enums.d.ts.map +1 -0
  83. package/lib/export-enums.js +5 -0
  84. package/lib/export-interfaces.d.ts.map +1 -0
  85. package/lib/export-interfaces.js +1 -0
  86. package/lib/export-types.d.ts.map +1 -0
  87. package/lib/export-types.js +1 -0
  88. package/lib/index.d.ts.map +1 -0
  89. package/lib/ui-components/SceneRunner.d.ts +14 -0
  90. package/lib/ui-components/SceneRunner.d.ts.map +1 -0
  91. package/lib/ui-components/SceneRunner.js +43 -0
  92. package/lib/ui-components/ScenesProcess.d.ts +9 -0
  93. package/lib/ui-components/ScenesProcess.d.ts.map +1 -0
  94. package/lib/ui-components/ScenesProcess.js +46 -0
  95. package/lib/ui-components/Sketch.d.ts +12 -0
  96. package/lib/ui-components/Sketch.d.ts.map +1 -0
  97. package/lib/ui-components/Sketch.js +33 -0
  98. package/lib/utilities.d.ts.map +1 -0
  99. package/lib/utilities.js +2 -0
  100. package/lib/utils.d.ts +8 -0
  101. package/lib/utils.d.ts.map +1 -0
  102. package/lib/utils.js +97 -0
  103. package/package.json +2 -6
@@ -0,0 +1,43 @@
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, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useEffect, useMemo, useState, } from "react";
14
+ import { Sketch } from "./Sketch";
15
+ export function SceneRunner(_a) {
16
+ var assetsDelay = _a.assetsDelay, current = _a.current, width = _a.width, height = _a.height, AssetsLoader = _a.assetsLoader;
17
+ var _b = useState(false), isBootDone = _b[0], setBootDone = _b[1];
18
+ useEffect(function () {
19
+ current.loadAssets(assetsDelay);
20
+ }, [current, assetsDelay]);
21
+ var setup = function (camera) {
22
+ current.bootstrap(camera);
23
+ setBootDone(true);
24
+ };
25
+ var draw = function () {
26
+ current.action();
27
+ };
28
+ var assetsLoader = useMemo(function () {
29
+ if (typeof AssetsLoader === "function") {
30
+ return _jsx(AssetsLoader, {});
31
+ }
32
+ return (AssetsLoader !== null && AssetsLoader !== void 0 ? AssetsLoader : _jsx("div", { children: "Assets loading..." }));
33
+ }, [AssetsLoader]);
34
+ return current.loadedAssets ? (_jsxs("div", __assign({ style: { width: width, height: height, position: "relative" } }, { children: [_jsx(Sketch, { width: width, height: height, onSetup: setup, onDraw: draw }), _jsx("div", __assign({ style: {
35
+ position: "absolute",
36
+ top: 0,
37
+ bottom: 0,
38
+ left: 0,
39
+ right: 0,
40
+ userSelect: "none",
41
+ zIndex: 2,
42
+ } }, { children: isBootDone ? (_jsx(current.UI, __assign({ scene: current }, current.UIProps))) : (_jsx("div", {})) }))] }))) : (assetsLoader);
43
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { SceneClass } from "../classes/scene-management";
3
+ import { SceneRunnerPublicProps } from "./SceneRunner";
4
+ declare type WorldViewProps = SceneRunnerPublicProps & {
5
+ list: SceneClass[];
6
+ };
7
+ export declare function ScenesProcess({ list, ...props }: WorldViewProps): JSX.Element;
8
+ export {};
9
+ //# sourceMappingURL=ScenesProcess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScenesProcess.d.ts","sourceRoot":"","sources":["../../src/ui-components/ScenesProcess.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAmB,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAe,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEpE,aAAK,cAAc,GAAG,sBAAsB,GAAG;IAC7C,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,eA8B/D"}
@@ -0,0 +1,46 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { useEffect, useMemo, useState } from "react";
25
+ import { SceneManagement } from "../classes/scene-management";
26
+ import { SceneRunner } from "./SceneRunner";
27
+ export function ScenesProcess(_a) {
28
+ var list = _a.list, props = __rest(_a, ["list"]);
29
+ var sceneManagement = useMemo(function () {
30
+ return new SceneManagement(list);
31
+ }, [list]);
32
+ var _b = useState(sceneManagement.currentScene), currentScene = _b[0], setCurrentScene = _b[1];
33
+ var _c = useState(currentScene.loadedAssets), setLoadedAssets = _c[1];
34
+ useEffect(function () {
35
+ sceneManagement.onChangeScene(function (scene) {
36
+ setCurrentScene(scene);
37
+ setLoadedAssets(scene.loadedAssets);
38
+ });
39
+ }, [sceneManagement]);
40
+ useEffect(function () {
41
+ currentScene.onLoadAssetNotify(function (isLoaded) {
42
+ setLoadedAssets(isLoaded);
43
+ });
44
+ }, [currentScene]);
45
+ return (_jsx(SceneRunner, __assign({ current: currentScene }, props), currentScene.sessionId));
46
+ }
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { Camera } from "../classes/camera";
3
+ declare type SketchProps = {
4
+ onSetup: (camera: Camera) => void;
5
+ onDraw: () => void;
6
+ onPreload?: () => void;
7
+ width: number;
8
+ height: number;
9
+ };
10
+ export declare function Sketch({ onSetup, onDraw, onPreload, width, height, }: SketchProps): JSX.Element;
11
+ export {};
12
+ //# sourceMappingURL=Sketch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sketch.d.ts","sourceRoot":"","sources":["../../src/ui-components/Sketch.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,aAAK,WAAW,GAAG;IACjB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,MAAM,CAAC,EACrB,OAAO,EACP,MAAM,EACN,SAAS,EACT,KAAK,EACL,MAAM,GACP,EAAE,WAAW,eAgCb"}
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { Camera } from "../classes/camera";
4
+ import { P5 } from "../classes/p5";
5
+ export function Sketch(_a) {
6
+ var onSetup = _a.onSetup, onDraw = _a.onDraw, onPreload = _a.onPreload, width = _a.width, height = _a.height;
7
+ var refContainer = useRef(null);
8
+ useEffect(function () {
9
+ var sketch = function (s) {
10
+ var camera = new Camera(width, height);
11
+ s.preload = function () {
12
+ return onPreload === null || onPreload === void 0 ? void 0 : onPreload();
13
+ };
14
+ s.setup = function () {
15
+ s.createCanvas(width, height).parent(refContainer.current);
16
+ onSetup(camera);
17
+ };
18
+ s.draw = function () {
19
+ s.scale(camera.scaleX, camera.scaleY);
20
+ s.background(0);
21
+ s.imageMode(s.CENTER);
22
+ s.rectMode(s.CENTER);
23
+ onDraw();
24
+ };
25
+ };
26
+ var p5 = new P5(sketch);
27
+ return function () {
28
+ p5.remove();
29
+ };
30
+ // eslint-disable-next-line
31
+ }, []);
32
+ return _jsx("div", { style: { backgroundColor: "#000" }, ref: refContainer });
33
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./classes/watcher";
2
+ export * from "./classes/sound-watcher";
package/lib/utils.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Sound } from "./classes/sound";
2
+ import { SoundType } from "./export-enums";
3
+ import { Avatar } from "./export-types";
4
+ export declare function createAssetImage(src: string): Promise<Avatar>;
5
+ export declare function createAssetSound(src: string, type?: SoundType): Promise<Sound>;
6
+ export declare function tick(delay?: number): Promise<unknown>;
7
+ export declare function copyProperties(source: Record<string, any>, target: Record<string, any>): void;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAiBxC,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAInE;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,KAAK,CAAC,CAWhB;AAED,wBAAsB,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,oBAQxC;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAO5B"}
package/lib/utils.js ADDED
@@ -0,0 +1,97 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import OutofScopeP5 from "p5";
38
+ import { Sound } from "./classes/sound";
39
+ var outofScopeP5;
40
+ document.addEventListener("DOMContentLoaded", function () {
41
+ var noop = document.createElement("div");
42
+ noop.style.position = "absolute";
43
+ noop.style.zIndex = "-1";
44
+ noop.style.top = "-100%";
45
+ noop.style.left = "-100%";
46
+ document.body.appendChild(noop);
47
+ setTimeout(function () {
48
+ outofScopeP5 = new OutofScopeP5(function (skt) { }, noop);
49
+ }, 0);
50
+ });
51
+ export function createAssetImage(src) {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ return __generator(this, function (_a) {
54
+ return [2 /*return*/, new Promise(function (res, rej) {
55
+ outofScopeP5.loadImage(src, res, rej);
56
+ })];
57
+ });
58
+ });
59
+ }
60
+ export function createAssetSound(src, type) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var media;
63
+ return __generator(this, function (_a) {
64
+ media = new Sound(type);
65
+ return [2 /*return*/, new Promise(function (res, rej) {
66
+ media.native.onloadedmetadata = function () {
67
+ res(media);
68
+ };
69
+ media.native.onerror = function (error) {
70
+ rej(error);
71
+ };
72
+ media.native.src = src;
73
+ })];
74
+ });
75
+ });
76
+ }
77
+ export function tick(delay) {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ return __generator(this, function (_a) {
80
+ return [2 /*return*/, new Promise(function (res) {
81
+ if (delay != null) {
82
+ setTimeout(res, delay);
83
+ }
84
+ else {
85
+ // wait forever
86
+ }
87
+ })];
88
+ });
89
+ });
90
+ }
91
+ export function copyProperties(source, target) {
92
+ for (var key in target) {
93
+ if (target[key] !== undefined) {
94
+ source[key] = target[key];
95
+ }
96
+ }
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-game-engine",
3
- "version": "0.1.61",
3
+ "version": "0.1.64",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib",
@@ -21,11 +21,7 @@
21
21
  "build": "rm -rf lib && tsc -p ."
22
22
  },
23
23
  "files": [
24
- "/lib/index.d.ts",
25
- "/lib/utilities.d.ts",
26
- "/lib/export-types.d.ts",
27
- "/lib/export-interfaces.d.ts",
28
- "/lib/export-enums.d.ts"
24
+ "/lib"
29
25
  ],
30
26
  "keywords": [
31
27
  "game engine",