react-simple-game-engine 0.1.16 → 0.1.17

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.
@@ -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
- tag?: string;
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;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE;gBAIjB,MAAM,EAAE;QAAE,QAAQ,KAAK,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;IAK7D,IAAI,YAAY,eAEf;IAED,aAAa,CAAC,IAAI,EAAE,mBAAmB;IAIvC,SAAS,CAAC,GAAG,EAAE,MAAM;CActB"}
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;CAKnB"}
@@ -17,22 +17,42 @@ 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
- for (var _i = 0, _b = this.Scenes; _i < _b.length; _i++) {
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._currentScene = new Scene_1();
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
+ };
36
56
  return SceneManagement;
37
57
  }());
38
58
  export { SceneManagement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simple-game-engine",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib",