react-simple-game-engine 0.1.46 → 0.1.47
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/sound.d.ts +2 -1
- package/lib/classes/sound.d.ts.map +1 -1
- package/lib/classes/sound.js +7 -23
- package/lib/utils.js +3 -3
- package/package.json +1 -1
package/lib/classes/sound.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import { SoundType } from "../export-enums";
|
2
2
|
import { SoundManagement } from "../export-types";
|
3
|
-
export declare class Sound
|
3
|
+
export declare class Sound {
|
4
4
|
private readonly type;
|
5
5
|
static Management: SoundManagement;
|
6
|
+
readonly native: HTMLAudioElement;
|
6
7
|
constructor(type?: SoundType);
|
7
8
|
playNow(): Promise<void>;
|
8
9
|
play(): Promise<void>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sound.d.ts","sourceRoot":"","sources":["../../src/classes/sound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"sound.d.ts","sourceRoot":"","sources":["../../src/classes/sound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,qBAAa,KAAK;IAWJ,OAAO,CAAC,QAAQ,CAAC,IAAI;IAVjC,MAAM,CAAC,UAAU,EAAE,eAAe,CAOhC;IACF,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAe;gBAEnB,IAAI,GAAE,SAA0B;IAEvD,OAAO;IAKP,IAAI;CAMX"}
|
package/lib/classes/sound.js
CHANGED
@@ -1,18 +1,3 @@
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
2
|
-
var extendStatics = function (d, b) {
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
-
return extendStatics(d, b);
|
7
|
-
};
|
8
|
-
return function (d, b) {
|
9
|
-
if (typeof b !== "function" && b !== null)
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
-
extendStatics(d, b);
|
12
|
-
function __() { this.constructor = d; }
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
-
};
|
15
|
-
})();
|
16
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
17
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
18
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -51,20 +36,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
51
36
|
};
|
52
37
|
var _a;
|
53
38
|
import { SoundType } from "../export-enums";
|
54
|
-
|
55
|
-
|
39
|
+
// cant not Sound extends Audio, because TS complite, make call new Audio like a function
|
40
|
+
var Sound = /** @class */ (function () {
|
56
41
|
function Sound(type) {
|
57
42
|
if (type === void 0) { type = SoundType.ONCE; }
|
58
|
-
|
59
|
-
|
60
|
-
return _this;
|
43
|
+
this.type = type;
|
44
|
+
this.native = new Audio();
|
61
45
|
}
|
62
46
|
Sound.prototype.playNow = function () {
|
63
47
|
return __awaiter(this, void 0, void 0, function () {
|
64
48
|
return __generator(this, function (_a) {
|
65
49
|
switch (_a.label) {
|
66
50
|
case 0:
|
67
|
-
this.currentTime = 0;
|
51
|
+
this.native.currentTime = 0;
|
68
52
|
return [4 /*yield*/, this.play()];
|
69
53
|
case 1:
|
70
54
|
_a.sent();
|
@@ -79,7 +63,7 @@ var Sound = /** @class */ (function (_super) {
|
|
79
63
|
return __generator(this, function (_a) {
|
80
64
|
canPlay = Sound.Management[this.type].canPlay;
|
81
65
|
if (canPlay) {
|
82
|
-
|
66
|
+
this.native.play();
|
83
67
|
}
|
84
68
|
return [2 /*return*/];
|
85
69
|
});
|
@@ -94,5 +78,5 @@ var Sound = /** @class */ (function (_super) {
|
|
94
78
|
},
|
95
79
|
_a);
|
96
80
|
return Sound;
|
97
|
-
}(
|
81
|
+
}());
|
98
82
|
export { Sound };
|
package/lib/utils.js
CHANGED
@@ -63,13 +63,13 @@ export function createAssetSound(src, type) {
|
|
63
63
|
return __generator(this, function (_a) {
|
64
64
|
media = new Sound(type);
|
65
65
|
return [2 /*return*/, new Promise(function (res, rej) {
|
66
|
-
media.onloadedmetadata = function () {
|
66
|
+
media.native.onloadedmetadata = function () {
|
67
67
|
res(media);
|
68
68
|
};
|
69
|
-
media.onerror = function (error) {
|
69
|
+
media.native.onerror = function (error) {
|
70
70
|
rej(error);
|
71
71
|
};
|
72
|
-
media.src = src;
|
72
|
+
media.native.src = src;
|
73
73
|
})];
|
74
74
|
});
|
75
75
|
});
|