react-simple-game-engine 0.2.46 → 0.2.48
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/animations/animation.js +1 -1
- package/lib/classes/animations/animator.d.ts +18 -0
- package/lib/classes/animations/animator.d.ts.map +1 -0
- package/lib/classes/animations/animator.js +40 -0
- package/lib/classes/sprites/sprite.d.ts +4 -3
- package/lib/classes/sprites/sprite.d.ts.map +1 -1
- package/lib/classes/sprites/sprite.js +8 -2
- package/package.json +1 -1
@@ -29,7 +29,7 @@ var AnimationSprite = /** @class */ (function () {
|
|
29
29
|
this.currentFrame = 0;
|
30
30
|
}
|
31
31
|
this.onDraw();
|
32
|
-
if (this.timeCounter
|
32
|
+
if (this.timeCounter >= this.timePerFrame) {
|
33
33
|
this.timeCounter = 0;
|
34
34
|
if (this._isRunning) {
|
35
35
|
this.currentFrame++;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Initialler } from "../../export-interfaces";
|
2
|
+
import { Sprite } from "../sprites/sprite";
|
3
|
+
import { AnimationSprite } from "./animation";
|
4
|
+
declare type AnimatorState = Sprite<any> | AnimationSprite<any>;
|
5
|
+
export declare class Animator<K extends string = string> implements Initialler {
|
6
|
+
private states;
|
7
|
+
private activeKey;
|
8
|
+
initial(params: {
|
9
|
+
activeKey: K;
|
10
|
+
states: Record<K, AnimatorState>;
|
11
|
+
}): void;
|
12
|
+
linkSprite(sprite: Sprite<any>): void;
|
13
|
+
draw(): void;
|
14
|
+
getActiveAnimation(): Record<K, AnimatorState>[K];
|
15
|
+
set state(k: K);
|
16
|
+
}
|
17
|
+
export {};
|
18
|
+
//# sourceMappingURL=animator.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"animator.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/animator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,aAAK,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;AAExD,qBAAa,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,YAAW,UAAU;IACpE,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,SAAS,CAAI;IAErB,OAAO,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAA;KAAE;IAIlE,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC;IAY9B,IAAI;IASJ,kBAAkB;IAIlB,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,EAEb;CACF"}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { copyProperties } from "../../utils";
|
2
|
+
import { AnimationSprite } from "./animation";
|
3
|
+
var Animator = /** @class */ (function () {
|
4
|
+
function Animator() {
|
5
|
+
}
|
6
|
+
Animator.prototype.initial = function (params) {
|
7
|
+
copyProperties(this, params);
|
8
|
+
};
|
9
|
+
Animator.prototype.linkSprite = function (sprite) {
|
10
|
+
for (var key in this.states) {
|
11
|
+
if (this.states.hasOwnProperty(key)) {
|
12
|
+
var state = this.states[key];
|
13
|
+
if (state instanceof AnimationSprite) {
|
14
|
+
//@ts-ignore,pass check modifier for first initial
|
15
|
+
this._animation._sprite = sprite;
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
};
|
20
|
+
Animator.prototype.draw = function () {
|
21
|
+
for (var key in this.states) {
|
22
|
+
if (this.states.hasOwnProperty(key)) {
|
23
|
+
var state = this.states[key];
|
24
|
+
state.draw();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
};
|
28
|
+
Animator.prototype.getActiveAnimation = function () {
|
29
|
+
return this.states[this.activeKey];
|
30
|
+
};
|
31
|
+
Object.defineProperty(Animator.prototype, "state", {
|
32
|
+
set: function (k) {
|
33
|
+
this.activeKey = k;
|
34
|
+
},
|
35
|
+
enumerable: false,
|
36
|
+
configurable: true
|
37
|
+
});
|
38
|
+
return Animator;
|
39
|
+
}());
|
40
|
+
export { Animator };
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Avatar, Color } from "../../export-types";
|
2
2
|
import { AnimationSprite } from "../animations/animation";
|
3
|
+
import { Animator } from "../animations/animator";
|
3
4
|
import { Entity } from "../entities/entity";
|
4
5
|
import { LogicComponent } from "../logic-component";
|
5
6
|
export declare type SourceType = Avatar | Color | undefined | null;
|
@@ -12,9 +13,9 @@ export declare abstract class Sprite<SpriteType extends SourceType> {
|
|
12
13
|
private _entity;
|
13
14
|
private _width;
|
14
15
|
private _height;
|
15
|
-
private _animation
|
16
|
-
set animation(ani: AnimationSprite<this>);
|
17
|
-
get animation(): AnimationSprite<this
|
16
|
+
private _animation?;
|
17
|
+
set animation(ani: AnimationSprite<this> | Animator);
|
18
|
+
get animation(): AnimationSprite<this> | Animator;
|
18
19
|
set entity(entity: Entity);
|
19
20
|
get entity(): Entity;
|
20
21
|
get width(): number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,oBAAY,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC;AAE3D,oBAAY,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG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eAAe,CAAC,IAAI,CAAC,GAAG,QAAQ,EAQlD;IAED,IAAI,SAAS,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,QAAQ,CAEhD;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAKxB;IAED,IAAI,MAAM,IAPS,MAAM,CASxB;IAED,IAAI,KAAK,WAER;IAED,IAAI,MAAM,WAET;IAED,IAAI;IAiBJ,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,OAAO,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC;CAexC"}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Animator } from "../animations/animator";
|
1
2
|
import { LogicComponent } from "../logic-component";
|
2
3
|
var Sprite = /** @class */ (function () {
|
3
4
|
function Sprite() {
|
@@ -8,8 +9,13 @@ var Sprite = /** @class */ (function () {
|
|
8
9
|
},
|
9
10
|
set: function (ani) {
|
10
11
|
this._animation = ani;
|
11
|
-
|
12
|
-
|
12
|
+
if (ani instanceof Animator) {
|
13
|
+
ani.linkSprite(this);
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
//@ts-ignore,pass check modifier for first initial
|
17
|
+
this._animation._sprite = this;
|
18
|
+
}
|
13
19
|
},
|
14
20
|
enumerable: false,
|
15
21
|
configurable: true
|