react-simple-game-engine 0.1.16 → 0.1.19
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.
- package/lib/classes/scene-management.d.ts +10 -7
- package/lib/classes/scene-management.d.ts.map +1 -1
- package/lib/classes/scene-management.js +27 -6
- package/lib/ui-components/ScenesProcess.d.ts.map +1 -1
- package/lib/ui-components/ScenesProcess.js +2 -0
- package/lib/ui-components/Sketch.d.ts.map +1 -1
- package/lib/ui-components/Sketch.js +5 -1
- package/package.json +1 -1
@@ -1,19 +1,22 @@
|
|
1
1
|
import { Scene } from "./scene";
|
2
|
+
declare type SceneClass = {
|
3
|
+
new (): Scene;
|
4
|
+
tag?: string;
|
5
|
+
};
|
2
6
|
declare type ChangeSceneListener = (scene: Scene) => void;
|
3
7
|
export declare class SceneManagement {
|
4
8
|
private Scenes;
|
5
9
|
private _currentScene;
|
6
10
|
private changeSceneListener;
|
7
|
-
static getTag(Scene:
|
8
|
-
|
9
|
-
}): string | undefined;
|
10
|
-
constructor(Scenes: {
|
11
|
-
new (): Scene;
|
12
|
-
tag?: string;
|
13
|
-
}[]);
|
11
|
+
static getTag(Scene: SceneClass): string | undefined;
|
12
|
+
constructor(Scenes: SceneClass[]);
|
14
13
|
get currentScene(): Scene<any>;
|
15
14
|
onChangeScene(func: ChangeSceneListener): void;
|
15
|
+
canNext(): boolean;
|
16
|
+
next(): void;
|
17
|
+
replay(): void;
|
16
18
|
gotoScene(tag: string): void;
|
19
|
+
private startScene;
|
17
20
|
}
|
18
21
|
export {};
|
19
22
|
//# sourceMappingURL=scene-management.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"scene-management.d.ts","sourceRoot":"","sources":["../../src/classes/scene-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,aAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAClD,qBAAa,eAAe;IAOd,OAAO,CAAC,MAAM;IAN1B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,mBAAmB,CAAuB;IAClD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE
|
1
|
+
{"version":3,"file":"scene-management.d.ts","sourceRoot":"","sources":["../../src/classes/scene-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,aAAK,UAAU,GAAG;IAAE,QAAQ,KAAK,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElD,aAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAClD,qBAAa,eAAe;IAOd,OAAO,CAAC,MAAM;IAN1B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,mBAAmB,CAAuB;IAClD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU;gBAIX,MAAM,EAAE,UAAU,EAAE;IAKxC,IAAI,YAAY,eAEf;IAED,aAAa,CAAC,IAAI,EAAE,mBAAmB;IAIvC,OAAO;IAQP,IAAI;IAUJ,MAAM;IAIN,SAAS,CAAC,GAAG,EAAE,MAAM;IAarB,OAAO,CAAC,UAAU;CAMnB"}
|
@@ -17,22 +17,43 @@ var SceneManagement = /** @class */ (function () {
|
|
17
17
|
SceneManagement.prototype.onChangeScene = function (func) {
|
18
18
|
this.changeSceneListener = func;
|
19
19
|
};
|
20
|
+
SceneManagement.prototype.canNext = function () {
|
21
|
+
var _this = this;
|
22
|
+
var currentIndex = this.Scenes.findIndex(function (Scene) { return _this._currentScene instanceof Scene; });
|
23
|
+
var NextScene = this.Scenes[currentIndex + 1];
|
24
|
+
return !!NextScene;
|
25
|
+
};
|
26
|
+
SceneManagement.prototype.next = function () {
|
27
|
+
var _this = this;
|
28
|
+
var currentIndex = this.Scenes.findIndex(function (Scene) { return _this._currentScene instanceof Scene; });
|
29
|
+
var NextScene = this.Scenes[currentIndex + 1];
|
30
|
+
if (NextScene) {
|
31
|
+
this.startScene(NextScene);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
SceneManagement.prototype.replay = function () {
|
35
|
+
this.gotoScene(this._currentScene.tag);
|
36
|
+
};
|
20
37
|
SceneManagement.prototype.gotoScene = function (tag) {
|
21
|
-
var _a;
|
22
|
-
|
23
|
-
var Scene_1 = _b[_i];
|
38
|
+
for (var _i = 0, _a = this.Scenes; _i < _a.length; _i++) {
|
39
|
+
var Scene_1 = _a[_i];
|
24
40
|
var _tag = SceneManagement.getTag(Scene_1);
|
25
41
|
if (_tag === tag) {
|
26
42
|
if (this._currentScene) {
|
27
43
|
this._currentScene.destructor();
|
28
44
|
}
|
29
|
-
this.
|
30
|
-
this._currentScene.manager = this;
|
31
|
-
(_a = this.changeSceneListener) === null || _a === void 0 ? void 0 : _a.call(this, this._currentScene);
|
45
|
+
this.startScene(Scene_1);
|
32
46
|
break;
|
33
47
|
}
|
34
48
|
}
|
35
49
|
};
|
50
|
+
SceneManagement.prototype.startScene = function (Scene) {
|
51
|
+
var _a;
|
52
|
+
this._currentScene = new Scene();
|
53
|
+
this._currentScene.manager = this;
|
54
|
+
(_a = this.changeSceneListener) === null || _a === void 0 ? void 0 : _a.call(this, this._currentScene);
|
55
|
+
Renderer.running = true;
|
56
|
+
};
|
36
57
|
return SceneManagement;
|
37
58
|
}());
|
38
59
|
export { SceneManagement };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ScenesProcess.d.ts","sourceRoot":"","sources":["../../src/ui-components/ScenesProcess.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAe,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEpE,aAAK,YAAY,GAAG,qBAAqB,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAErE,aAAK,cAAc,GAAG,sBAAsB,GAAG;IAC7C,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,
|
1
|
+
{"version":3,"file":"ScenesProcess.d.ts","sourceRoot":"","sources":["../../src/ui-components/ScenesProcess.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAe,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEpE,aAAK,YAAY,GAAG,qBAAqB,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAErE,aAAK,cAAc,GAAG,sBAAsB,GAAG;IAC7C,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,eAgC/D"}
|
@@ -33,12 +33,14 @@ export function ScenesProcess(_a) {
|
|
33
33
|
var _c = useState(currentScene.loadedAssets), setLoadedAssets = _c[1];
|
34
34
|
useEffect(function () {
|
35
35
|
sceneManagement.onChangeScene(function (scene) {
|
36
|
+
console.log("change scene");
|
36
37
|
setCurrentScene(scene);
|
37
38
|
setLoadedAssets(scene.loadedAssets);
|
38
39
|
});
|
39
40
|
}, [sceneManagement]);
|
40
41
|
useEffect(function () {
|
41
42
|
currentScene.onLoadAssetNotify(function (isLoaded) {
|
43
|
+
console.log("load asset scene");
|
42
44
|
setLoadedAssets(isLoaded);
|
43
45
|
});
|
44
46
|
}, [currentScene]);
|
@@ -1 +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,
|
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,eAiCb"}
|
@@ -23,7 +23,11 @@ export function Sketch(_a) {
|
|
23
23
|
onDraw();
|
24
24
|
};
|
25
25
|
};
|
26
|
-
new P5(sketch);
|
26
|
+
var p5 = new P5(sketch);
|
27
|
+
return function () {
|
28
|
+
p5.noLoop();
|
29
|
+
p5.remove();
|
30
|
+
};
|
27
31
|
// eslint-disable-next-line
|
28
32
|
}, []);
|
29
33
|
return _jsx("div", { style: { backgroundColor: "#000" }, ref: refContainer });
|