react-simple-game-engine 0.2.7 → 0.2.11
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/scaler.js +2 -2
- package/lib/classes/scene.d.ts +18 -2
- package/lib/classes/scene.d.ts.map +1 -1
- package/lib/classes/scene.js +71 -24
- package/lib/classes/sound.d.ts +1 -1
- package/lib/classes/sound.d.ts.map +1 -1
- package/lib/ui-components/scene-runner.d.ts +3 -2
- package/lib/ui-components/scene-runner.d.ts.map +1 -1
- package/lib/ui-components/scene-runner.js +18 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +8 -22
- package/package.json +1 -1
package/lib/classes/scaler.js
CHANGED
@@ -92,10 +92,10 @@ var Scaler = /** @class */ (function () {
|
|
92
92
|
Scaler.prototype.update = function () {
|
93
93
|
if (this._layoutMode === LayoutMode.LANDSCAPE) {
|
94
94
|
if (this._canvasSize.width >= this._canvasSize.height) {
|
95
|
-
this._value = this._canvasSize.
|
95
|
+
this._value = this._canvasSize.width / this._gameSize.width;
|
96
96
|
}
|
97
97
|
else {
|
98
|
-
this._value = this._canvasSize.
|
98
|
+
this._value = this._canvasSize.height / this._gameSize.height;
|
99
99
|
}
|
100
100
|
}
|
101
101
|
else {
|
package/lib/classes/scene.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="p5" />
|
2
|
-
import { ComponentType } from "react";
|
2
|
+
import { ComponentType, ReactElement } from "react";
|
3
3
|
import { Camera } from "./camera";
|
4
4
|
import { LogicComponent } from "./logic-component";
|
5
5
|
import { SceneManagement } from "./scene-management";
|
@@ -8,6 +8,17 @@ import { Prefab } from "./prefab";
|
|
8
8
|
import { Sound } from "./sound";
|
9
9
|
import { Avatar, GetSoundOptions, SoundManagement } from "../export-types";
|
10
10
|
import { SoundType } from "../export-enums";
|
11
|
+
declare type AssetErrorType = "load-sound" | "load-sprite" | "load-extends";
|
12
|
+
export declare type AssetsFailBehavior = {
|
13
|
+
skip: true;
|
14
|
+
render?: never;
|
15
|
+
} | {
|
16
|
+
skip?: false;
|
17
|
+
render?: (errors: {
|
18
|
+
type: AssetErrorType;
|
19
|
+
detail: any;
|
20
|
+
}[]) => ReactElement;
|
21
|
+
};
|
11
22
|
declare type SoundOptionsChangeListener<O extends SoundType> = (options: SoundManagement[O]) => void;
|
12
23
|
declare type LoadAssetsListener = (loadedAssets: boolean) => void;
|
13
24
|
declare type EntityPropsChangeListener<V = any> = (value: V) => void;
|
@@ -16,6 +27,7 @@ export declare abstract class Scene<UIP = any> {
|
|
16
27
|
private ui;
|
17
28
|
private worldManagement;
|
18
29
|
private _loadedAssets;
|
30
|
+
private _renderAssetsFail;
|
19
31
|
private loadAssetsListener;
|
20
32
|
private nativeEventsUnsubscribes;
|
21
33
|
private readonly entityPropsChangeListeners;
|
@@ -33,6 +45,10 @@ export declare abstract class Scene<UIP = any> {
|
|
33
45
|
manager: SceneManagement;
|
34
46
|
abstract getComponents(camera: Camera): LogicComponent<EntitySult>[];
|
35
47
|
constructor();
|
48
|
+
get renderAssetsFail(): () => ReactElement<any, string | import("react").JSXElementConstructor<any>> | {
|
49
|
+
type: AssetErrorType;
|
50
|
+
detail: any;
|
51
|
+
}[];
|
36
52
|
get UI(): ComponentType<UIP> | (() => any);
|
37
53
|
get UIProps(): UIP;
|
38
54
|
get soundBackgroundOptions(): SoundManagement[SoundType.BACKGROUND];
|
@@ -66,7 +82,7 @@ export declare abstract class Scene<UIP = any> {
|
|
66
82
|
})[]): Promise<Sound[]>;
|
67
83
|
mapSprites(...srcs: string[]): Promise<void>;
|
68
84
|
mapSounds(...srcs: string[]): Promise<void>;
|
69
|
-
loadAssets(delay?:
|
85
|
+
loadAssets(delay: number | undefined | null, { skip, render }?: AssetsFailBehavior): Promise<void>;
|
70
86
|
onLoadAssets(): Promise<void>;
|
71
87
|
getPrefab<C extends EntitySult>(Class: {
|
72
88
|
new (...args: any[]): Prefab<C>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAa,MAAM,OAAO,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AASlC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EACL,MAAM,EACN,eAAe,EAEf,eAAe,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,aAAK,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,cAAc,CAAC;AACpE,oBAAY,kBAAkB,GAC1B;IACE,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,CACP,MAAM,EAAE;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,EAAE,KAC5C,YAAY,CAAC;CACnB,CAAC;AACN,aAAK,0BAA0B,CAAC,CAAC,SAAS,SAAS,IAAI,CACrD,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KACxB,IAAI,CAAC;AACV,aAAK,kBAAkB,GAAG,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;AAC1D,aAAK,yBAAyB,CAAC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B,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAc3B,UAAU,CACd,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAChC,EAAE,IAAY,EAAE,MAAM,EAAE,GAAE,kBAAuB;IA8C7C,YAAY;IAElB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,KAAK,EAAE;QACrC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;KACjC,GAAG,MAAM,CAAC,CAAC,CAAC;IAIb,kBAAkB;IAelB,SAAS,CAAC,MAAM,EAAE,MAAM;IAsCxB,SAAS,CAAC,MAAM;IAChB,SAAS,CAAC,QAAQ;IAElB,MAAM;CAUP"}
|
package/lib/classes/scene.js
CHANGED
@@ -58,6 +58,13 @@ var Scene = /** @class */ (function () {
|
|
58
58
|
this._loadedAssets = false;
|
59
59
|
this.onBorn();
|
60
60
|
}
|
61
|
+
Object.defineProperty(Scene.prototype, "renderAssetsFail", {
|
62
|
+
get: function () {
|
63
|
+
return this._renderAssetsFail;
|
64
|
+
},
|
65
|
+
enumerable: false,
|
66
|
+
configurable: true
|
67
|
+
});
|
61
68
|
Object.defineProperty(Scene.prototype, "UI", {
|
62
69
|
get: function () {
|
63
70
|
var Ui = this.ui || (function () { return null; });
|
@@ -195,23 +202,32 @@ var Scene = /** @class */ (function () {
|
|
195
202
|
this.manager.gotoScene(tag);
|
196
203
|
};
|
197
204
|
Scene.prototype.loadSprites = function () {
|
198
|
-
|
199
|
-
|
200
|
-
var sprite;
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
206
|
+
var _this_1 = this;
|
201
207
|
return __generator(this, function (_a) {
|
202
208
|
switch (_a.label) {
|
203
|
-
case 0:
|
204
|
-
|
205
|
-
|
209
|
+
case 0: return [4 /*yield*/, parallel(this.spritesDecor, function (decor) { return __awaiter(_this_1, void 0, void 0, function () {
|
210
|
+
var sprite;
|
211
|
+
return __generator(this, function (_a) {
|
212
|
+
switch (_a.label) {
|
213
|
+
case 0:
|
214
|
+
if (!decor.src) return [3 /*break*/, 2];
|
215
|
+
return [4 /*yield*/, createAssetImage(decor.src)];
|
216
|
+
case 1:
|
217
|
+
sprite = _a.sent();
|
218
|
+
this[decor.propertyKey] = sprite;
|
219
|
+
this.sprites.push(sprite);
|
220
|
+
_a.label = 2;
|
221
|
+
case 2: return [2 /*return*/];
|
222
|
+
}
|
223
|
+
});
|
224
|
+
}); }, MAX_ASSET_PARALLEL_LOAD)];
|
206
225
|
case 1:
|
207
|
-
|
208
|
-
|
209
|
-
this.sprites.push(sprite);
|
210
|
-
_a.label = 2;
|
211
|
-
case 2: return [2 /*return*/];
|
226
|
+
_a.sent();
|
227
|
+
return [2 /*return*/];
|
212
228
|
}
|
213
229
|
});
|
214
|
-
});
|
230
|
+
});
|
215
231
|
};
|
216
232
|
Scene.prototype.loadSounds = function () {
|
217
233
|
return __awaiter(this, void 0, void 0, function () {
|
@@ -373,10 +389,12 @@ var Scene = /** @class */ (function () {
|
|
373
389
|
});
|
374
390
|
});
|
375
391
|
};
|
376
|
-
Scene.prototype.loadAssets = function (delay) {
|
392
|
+
Scene.prototype.loadAssets = function (delay, _a) {
|
393
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.skip, skip = _c === void 0 ? false : _c, render = _b.render;
|
377
394
|
return __awaiter(this, void 0, void 0, function () {
|
378
|
-
|
379
|
-
|
395
|
+
var result, hasErrors;
|
396
|
+
return __generator(this, function (_d) {
|
397
|
+
switch (_d.label) {
|
380
398
|
case 0:
|
381
399
|
if (delay != null) {
|
382
400
|
this.assetsDelay = delay;
|
@@ -385,22 +403,45 @@ var Scene = /** @class */ (function () {
|
|
385
403
|
return [4 /*yield*/, tick(this.assetsDelay < 0 ? undefined : this.assetsDelay)];
|
386
404
|
case 1:
|
387
405
|
// if delay less than 0, it will wait forever
|
388
|
-
|
406
|
+
_d.sent();
|
389
407
|
this.loadedAssets = false;
|
390
408
|
return [4 /*yield*/, Promise.all([
|
391
409
|
this.loadSounds().catch(function (err) {
|
392
|
-
|
410
|
+
return {
|
411
|
+
error: true,
|
412
|
+
type: "load-sound",
|
413
|
+
detail: err,
|
414
|
+
};
|
393
415
|
}),
|
394
416
|
this.loadSprites().catch(function (err) {
|
395
|
-
|
417
|
+
return {
|
418
|
+
error: true,
|
419
|
+
type: "load-sprite",
|
420
|
+
detail: err,
|
421
|
+
};
|
396
422
|
}),
|
397
423
|
this.onLoadAssets().catch(function (err) {
|
398
|
-
|
424
|
+
return {
|
425
|
+
error: true,
|
426
|
+
type: "load-extends",
|
427
|
+
detail: err,
|
428
|
+
};
|
399
429
|
}),
|
400
430
|
])];
|
401
431
|
case 2:
|
402
|
-
|
403
|
-
|
432
|
+
result = _d.sent();
|
433
|
+
hasErrors = result.some(function (rs) { return rs === null || rs === void 0 ? void 0 : rs.error; });
|
434
|
+
if (hasErrors && !skip) {
|
435
|
+
// this.loadedAssets = false;
|
436
|
+
this._renderAssetsFail = function () {
|
437
|
+
var errors = result.filter(function (rs) { return !!(rs === null || rs === void 0 ? void 0 : rs.error); });
|
438
|
+
return render ? render(errors) : errors;
|
439
|
+
};
|
440
|
+
}
|
441
|
+
else {
|
442
|
+
// when dont have error or skip error
|
443
|
+
this.loadedAssets = true;
|
444
|
+
}
|
404
445
|
return [2 /*return*/];
|
405
446
|
}
|
406
447
|
});
|
@@ -430,12 +471,18 @@ var Scene = /** @class */ (function () {
|
|
430
471
|
this.bootSoundOptions();
|
431
472
|
this.onProcessStateChangeListener(function (isForeground) {
|
432
473
|
if (isForeground) {
|
433
|
-
|
434
|
-
var
|
435
|
-
|
474
|
+
if (window.Renderer.running) {
|
475
|
+
for (var _i = 0, _a = _this_1.sounds; _i < _a.length; _i++) {
|
476
|
+
var sound = _a[_i];
|
477
|
+
// only resume background sounds
|
478
|
+
if (sound.type === SoundType.BACKGROUND) {
|
479
|
+
sound.resume();
|
480
|
+
}
|
481
|
+
}
|
436
482
|
}
|
437
483
|
}
|
438
484
|
else {
|
485
|
+
// pause all sounds
|
439
486
|
for (var _b = 0, _c = _this_1.sounds; _b < _c.length; _b++) {
|
440
487
|
var sound = _c[_b];
|
441
488
|
sound.pause();
|
package/lib/classes/sound.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { SoundType } from "../export-enums";
|
2
2
|
import { SoundManagement } from "../export-types";
|
3
3
|
export declare class Sound {
|
4
|
-
|
4
|
+
readonly type: SoundType;
|
5
5
|
static Management: SoundManagement;
|
6
6
|
readonly native: HTMLAudioElement;
|
7
7
|
constructor(type?: SoundType);
|
@@ -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;AAGlD,qBAAa,KAAK;
|
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;aAWY,IAAI,EAAE,SAAS;IAV3C,MAAM,CAAC,UAAU,EAAE,eAAe,CAOhC;IACF,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAe;gBAEpB,IAAI,GAAE,SAA0B;IAE5D,IAAI,MAAM,IAIM,MAAM,CAFrB;IAED,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,EAErB;IAED,IAAI,SAAS,YAEZ;IAEK,OAAO;IAQP,KAAK;IAIL,MAAM;IAQN,IAAI;IAQJ,IAAI;CAYX"}
|
@@ -1,16 +1,17 @@
|
|
1
1
|
import { ComponentType, ReactNode } from "react";
|
2
|
-
import { Scene } from "../classes/scene";
|
2
|
+
import { AssetsFailBehavior, Scene } from "../classes/scene";
|
3
3
|
import { LayoutMode } from "../export-enums";
|
4
4
|
export declare type SceneRunnerPublicProps = {
|
5
5
|
width: number;
|
6
6
|
height: number;
|
7
7
|
assetsLoader?: ReactNode | ComponentType;
|
8
8
|
assetsDelay?: number;
|
9
|
+
assetsFailBehavior?: AssetsFailBehavior;
|
9
10
|
layoutMode?: LayoutMode;
|
10
11
|
};
|
11
12
|
declare type SceneRunnerProps = SceneRunnerPublicProps & {
|
12
13
|
current: Scene;
|
13
14
|
};
|
14
|
-
export declare function SceneRunner({
|
15
|
+
export declare function SceneRunner({ width, height, current, layoutMode, assetsDelay, assetsFailBehavior, assetsLoader: AssetsLoader, }: SceneRunnerProps): JSX.Element;
|
15
16
|
export {};
|
16
17
|
//# sourceMappingURL=scene-runner.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"scene-runner.d.ts","sourceRoot":"","sources":["../../src/ui-components/scene-runner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAKV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;
|
1
|
+
{"version":3,"file":"scene-runner.d.ts","sourceRoot":"","sources":["../../src/ui-components/scene-runner.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,SAAS,EAKV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,oBAAY,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF,aAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAC/C,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAiC,EAEjC,WAAW,EACX,kBAAkB,EAClB,YAAY,EAAE,YAAY,GAC3B,EAAE,gBAAgB,eAyIlB"}
|
@@ -9,14 +9,16 @@ var __assign = (this && this.__assign) || function () {
|
|
9
9
|
};
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
|
-
import { jsx as _jsx,
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
13
13
|
import { useEffect, useMemo, useRef, useState, } from "react";
|
14
14
|
import { Sketch } from "./sketch";
|
15
15
|
import { useWindowSize } from "../utils";
|
16
16
|
import { LayoutMode } from "../export-enums";
|
17
17
|
import { Scaler } from "../classes/scaler";
|
18
18
|
export function SceneRunner(_a) {
|
19
|
-
var
|
19
|
+
var width = _a.width, height = _a.height, current = _a.current, _b = _a.layoutMode, layoutMode = _b === void 0 ? LayoutMode.LANDSCAPE : _b,
|
20
|
+
//
|
21
|
+
assetsDelay = _a.assetsDelay, assetsFailBehavior = _a.assetsFailBehavior, AssetsLoader = _a.assetsLoader;
|
20
22
|
var windowSize = useWindowSize();
|
21
23
|
var refScaler = useRef(new Scaler(windowSize, { width: width, height: height }, layoutMode));
|
22
24
|
var _c = useState(false), isBootDone = _c[0], setBootDone = _c[1];
|
@@ -39,7 +41,8 @@ export function SceneRunner(_a) {
|
|
39
41
|
refScaler.current.layoutMode = layoutMode;
|
40
42
|
}, [layoutMode]);
|
41
43
|
useEffect(function () {
|
42
|
-
current.loadAssets(assetsDelay);
|
44
|
+
current.loadAssets(assetsDelay, assetsFailBehavior);
|
45
|
+
// Don't Dependency on assetsFailBehavior
|
43
46
|
}, [current, assetsDelay]);
|
44
47
|
var setup = function (camera) {
|
45
48
|
current.bootstrap(camera);
|
@@ -77,7 +80,18 @@ export function SceneRunner(_a) {
|
|
77
80
|
} }, { children: _jsx("div", __assign({ style: __assign({ width: width, height: height, transform: "scale(".concat(refScaler.current.value, ")"), transformOrigin: "left top", position: "relative" }, (function () {
|
78
81
|
var deltaOfScaleForUI = refScaler.current.deltaOfScaleForUI;
|
79
82
|
return { left: deltaOfScaleForUI.x, top: deltaOfScaleForUI.y };
|
80
|
-
})()) }, { children: !current.loadedAssets ? (
|
83
|
+
})()) }, { children: !current.loadedAssets ? (_jsx(_Fragment, { children: current.renderAssetsFail
|
84
|
+
? (function () {
|
85
|
+
var rendered = current.renderAssetsFail();
|
86
|
+
if (Array.isArray(rendered)) {
|
87
|
+
return (_jsx("div", __assign({ style: {
|
88
|
+
backgroundColor: "#f28181a1",
|
89
|
+
color: "#000",
|
90
|
+
} }, { children: rendered.map(function (item) { return (_jsxs("p", { children: [item.type, ": ", item.detail] })); }) })));
|
91
|
+
}
|
92
|
+
return rendered;
|
93
|
+
})()
|
94
|
+
: assetsLoader })) : (_jsx(_Fragment, { children: isBootDone ? (_jsx("div", __assign({ style: {
|
81
95
|
width: "100%",
|
82
96
|
height: "100%",
|
83
97
|
} }, { children: _jsx(current.UI, __assign({ scene: current }, current.UIProps)) }))) : (_jsx("div", {})) })) })) }))] })));
|
package/lib/utils.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAiBxC,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAInE;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,KAAK,CAAC,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAiBxC,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAInE;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,KAAK,CAAC,CAiChB;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;AAED,wBAAsB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAC3C,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EACtE,KAAK,SAAI,GACR,OAAO,CAAC,CAAC,EAAE,CAAC,CAkBd;AAED,wBAAgB,aAAa;;;EAiB5B"}
|
package/lib/utils.js
CHANGED
@@ -83,29 +83,15 @@ export function createAssetSound(src, type) {
|
|
83
83
|
media.native.onerror = function (e) {
|
84
84
|
if (e instanceof Event) {
|
85
85
|
var targetError = e.currentTarget.error;
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
case targetError.MEDIA_ERR_NETWORK:
|
95
|
-
console.warn("A network error caused the audio download to fail.");
|
96
|
-
break;
|
97
|
-
case targetError.MEDIA_ERR_DECODE:
|
98
|
-
console.warn("The audio playback was aborted due to a corruption problem or because the video used features your browser did not support.");
|
99
|
-
break;
|
100
|
-
case targetError.MEDIA_ERR_SRC_NOT_SUPPORTED:
|
101
|
-
console.warn("The video audio not be loaded, either because the server or network failed or because the format is not supported.");
|
102
|
-
break;
|
103
|
-
default:
|
104
|
-
console.warn("An unknown error occurred.");
|
105
|
-
break;
|
106
|
-
}
|
86
|
+
rej({
|
87
|
+
fullSrc: e.currentTarget.src,
|
88
|
+
src: src,
|
89
|
+
code: targetError.code,
|
90
|
+
});
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
rej(e);
|
107
94
|
}
|
108
|
-
rej(e);
|
109
95
|
};
|
110
96
|
media.native.setAttribute("preload", "metadata");
|
111
97
|
media.native.setAttribute("type", "audio/wav");
|