react-simple-game-engine 0.0.21 → 0.0.24
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/avatar.animation.d.ts +9 -7
- package/lib/classes/animations/avatar.animation.d.ts.map +1 -1
- package/lib/classes/animations/avatar.animation.js +11 -28
- package/lib/classes/sprites/avatar.sprite.d.ts +2 -1
- package/lib/classes/sprites/avatar.sprite.d.ts.map +1 -1
- package/lib/classes/sprites/avatar.sprite.js +23 -14
- package/lib/utils.d.ts +1 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +7 -0
- package/package.json +1 -1
@@ -1,14 +1,16 @@
|
|
1
1
|
import { AvatarSprite } from "../sprites/avatar.sprite";
|
2
2
|
import { AnimationSprite } from "./animation";
|
3
|
+
declare type Offset = {
|
4
|
+
x: number;
|
5
|
+
y: number;
|
6
|
+
width: number;
|
7
|
+
height: number;
|
8
|
+
};
|
3
9
|
export declare class AvatarAnimationSprite extends AnimationSprite<AvatarSprite> {
|
4
|
-
private
|
5
|
-
initial({
|
6
|
-
offsetX?: number;
|
7
|
-
offsetY?: number;
|
8
|
-
offsetWidth: number;
|
9
|
-
offsetHeight: number;
|
10
|
-
}): void;
|
10
|
+
private offset;
|
11
|
+
initial({ x, y, width, height }: Partial<Offset>): void;
|
11
12
|
protected checkFrameMax(): boolean;
|
12
13
|
onDraw(): void;
|
13
14
|
}
|
15
|
+
export {};
|
14
16
|
//# sourceMappingURL=avatar.animation.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"avatar.animation.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/avatar.animation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,
|
1
|
+
{"version":3,"file":"avatar.animation.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/avatar.animation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,aAAK,MAAM,GAAG;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,qBAAsB,SAAQ,eAAe,CAAC,YAAY,CAAC;IACtE,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,EAAE,CAAK,EAAE,CAAK,EAAE,KAAS,EAAE,MAAU,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC;IAShE,SAAS,CAAC,aAAa,IAAI,OAAO;IAKlC,MAAM;CAiBP"}
|
@@ -13,28 +13,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
14
|
};
|
15
15
|
})();
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
17
|
-
__assign = Object.assign || function(t) {
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
19
|
-
s = arguments[i];
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
21
|
-
t[p] = s[p];
|
22
|
-
}
|
23
|
-
return t;
|
24
|
-
};
|
25
|
-
return __assign.apply(this, arguments);
|
26
|
-
};
|
27
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
28
|
-
var t = {};
|
29
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
30
|
-
t[p] = s[p];
|
31
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
32
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
33
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
34
|
-
t[p[i]] = s[p[i]];
|
35
|
-
}
|
36
|
-
return t;
|
37
|
-
};
|
38
16
|
import { AnimationSprite } from "./animation";
|
39
17
|
var AvatarAnimationSprite = /** @class */ (function (_super) {
|
40
18
|
__extends(AvatarAnimationSprite, _super);
|
@@ -42,21 +20,26 @@ var AvatarAnimationSprite = /** @class */ (function (_super) {
|
|
42
20
|
return _super !== null && _super.apply(this, arguments) || this;
|
43
21
|
}
|
44
22
|
AvatarAnimationSprite.prototype.initial = function (_a) {
|
45
|
-
var _b = _a.
|
46
|
-
this.
|
23
|
+
var _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c, _d = _a.width, width = _d === void 0 ? 0 : _d, _e = _a.height, height = _e === void 0 ? 0 : _e;
|
24
|
+
this.offset = {
|
25
|
+
x: x,
|
26
|
+
y: y,
|
27
|
+
width: width,
|
28
|
+
height: height,
|
29
|
+
};
|
47
30
|
};
|
48
31
|
AvatarAnimationSprite.prototype.checkFrameMax = function () {
|
49
|
-
var _a = this.
|
50
|
-
return
|
32
|
+
var _a = this.offset, width = _a.width, x = _a.x;
|
33
|
+
return this.currentFrame * width + x >= this.source.sprite.width;
|
51
34
|
};
|
52
35
|
AvatarAnimationSprite.prototype.onDraw = function () {
|
53
36
|
var source = this.source;
|
54
|
-
var _a = this.
|
37
|
+
var _a = this.offset, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
55
38
|
Renderer.image(source.sprite,
|
56
39
|
// position on canvas
|
57
40
|
0, 0, source.width, source.height,
|
58
41
|
//crop on source image
|
59
|
-
this.currentFrame *
|
42
|
+
this.currentFrame * width + x, y, width, height);
|
60
43
|
};
|
61
44
|
return AvatarAnimationSprite;
|
62
45
|
}(AnimationSprite));
|
@@ -11,7 +11,8 @@ declare type AvatarGetInitialParams<S extends AvatarSprite> = GetInitialParams<S
|
|
11
11
|
offset?: Partial<SpriteOffet>;
|
12
12
|
};
|
13
13
|
export declare class AvatarSprite extends Sprite<Avatar | undefined | null> {
|
14
|
-
private
|
14
|
+
private _offset;
|
15
|
+
get offset(): SpriteOffet;
|
15
16
|
onDraw(): void;
|
16
17
|
initial(params?: AvatarGetInitialParams<this>): void;
|
17
18
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"avatar.sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/avatar.sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;
|
1
|
+
{"version":3,"file":"avatar.sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/avatar.sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEpD,aAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,aAAK,sBAAsB,CAAC,CAAC,SAAS,YAAY,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG;IAE1E,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/B,CAAC;AAEF,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,OAAO,CAAC,OAAO,CAMb;IAEF,IAAI,MAAM,gBAET;IAED,MAAM;IAuBN,OAAO,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAC,IAAI,CAAC;CAc9C"}
|
@@ -35,19 +35,35 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
35
35
|
}
|
36
36
|
return t;
|
37
37
|
};
|
38
|
+
import { copyProperties } from "../../utils";
|
38
39
|
import { Sprite } from "./sprite";
|
39
40
|
var AvatarSprite = /** @class */ (function (_super) {
|
40
41
|
__extends(AvatarSprite, _super);
|
41
42
|
function AvatarSprite() {
|
42
|
-
|
43
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
44
|
+
_this._offset = {
|
45
|
+
x: 0,
|
46
|
+
y: 0,
|
47
|
+
index: 0,
|
48
|
+
width: 0,
|
49
|
+
height: 0,
|
50
|
+
};
|
51
|
+
return _this;
|
43
52
|
}
|
53
|
+
Object.defineProperty(AvatarSprite.prototype, "offset", {
|
54
|
+
get: function () {
|
55
|
+
return this._offset;
|
56
|
+
},
|
57
|
+
enumerable: false,
|
58
|
+
configurable: true
|
59
|
+
});
|
44
60
|
AvatarSprite.prototype.onDraw = function () {
|
45
61
|
if (this.sprite) {
|
46
62
|
if (this.animation) {
|
47
63
|
this.animation.draw();
|
48
64
|
}
|
49
65
|
else {
|
50
|
-
var _a = this.
|
66
|
+
var _a = this._offset, x = _a.x, y = _a.y, width = _a.width, height = _a.height, index = _a.index;
|
51
67
|
Renderer.image(this.sprite,
|
52
68
|
// position on canvas
|
53
69
|
0, 0, this.width, this.height,
|
@@ -59,19 +75,12 @@ var AvatarSprite = /** @class */ (function (_super) {
|
|
59
75
|
AvatarSprite.prototype.initial = function (params) {
|
60
76
|
var _a = (params ||
|
61
77
|
{}), offset = _a.offset, sprite = _a.sprite, _params = __rest(_a, ["offset", "sprite"]);
|
62
|
-
if (
|
63
|
-
this.
|
64
|
-
this.
|
65
|
-
this.offset.index = offset.index || 0;
|
66
|
-
this.offset.width = offset.width || (sprite === null || sprite === void 0 ? void 0 : sprite.width) || 0;
|
67
|
-
this.offset.height = offset.height || (sprite === null || sprite === void 0 ? void 0 : sprite.height) || 0;
|
78
|
+
if (sprite) {
|
79
|
+
this._offset.width = sprite.width;
|
80
|
+
this._offset.height = sprite.height;
|
68
81
|
}
|
69
|
-
|
70
|
-
this.offset
|
71
|
-
this.offset.y = 0;
|
72
|
-
this.offset.index = 0;
|
73
|
-
this.offset.width = (sprite === null || sprite === void 0 ? void 0 : sprite.width) || 0;
|
74
|
-
this.offset.height = (sprite === null || sprite === void 0 ? void 0 : sprite.height) || 0;
|
82
|
+
if (offset) {
|
83
|
+
copyProperties(this._offset, offset);
|
75
84
|
}
|
76
85
|
_super.prototype.initial.call(this, __assign(__assign({}, _params), { sprite: sprite }));
|
77
86
|
};
|
package/lib/utils.d.ts
CHANGED
@@ -2,4 +2,5 @@ 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
4
|
export declare function tick(delay?: number): Promise<unknown>;
|
5
|
+
export declare function copyProperties(source: Record<string, any>, target: Record<string, any>): void;
|
5
6
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
@@ -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;AAED,wBAAsB,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,oBAQxC"}
|
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;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
CHANGED