react-simple-game-engine 0.2.8 → 0.2.12
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/scene.d.ts +23 -3
- package/lib/classes/scene.d.ts.map +1 -1
- package/lib/classes/scene.js +78 -27
- package/lib/ui-components/game-bootstrap.d.ts.map +1 -1
- package/lib/ui-components/game-bootstrap.js +5 -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/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,14 +8,29 @@ 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
|
-
declare type LoadAssetsListener = (loadedAssets: boolean
|
23
|
+
declare type LoadAssetsListener = (loadedAssets: boolean, errors?: {
|
24
|
+
type: AssetErrorType;
|
25
|
+
detail: any;
|
26
|
+
}[]) => void;
|
13
27
|
declare type EntityPropsChangeListener<V = any> = (value: V) => void;
|
14
28
|
declare type ProcessStateChangeListener = (isForeground: boolean) => void;
|
15
29
|
export declare abstract class Scene<UIP = any> {
|
16
30
|
private ui;
|
17
31
|
private worldManagement;
|
18
32
|
private _loadedAssets;
|
33
|
+
private _renderAssetsFail;
|
19
34
|
private loadAssetsListener;
|
20
35
|
private nativeEventsUnsubscribes;
|
21
36
|
private readonly entityPropsChangeListeners;
|
@@ -33,6 +48,10 @@ export declare abstract class Scene<UIP = any> {
|
|
33
48
|
manager: SceneManagement;
|
34
49
|
abstract getComponents(camera: Camera): LogicComponent<EntitySult>[];
|
35
50
|
constructor();
|
51
|
+
get renderAssetsFail(): () => ReactElement<any, string | import("react").JSXElementConstructor<any>> | {
|
52
|
+
type: AssetErrorType;
|
53
|
+
detail: any;
|
54
|
+
}[];
|
36
55
|
get UI(): ComponentType<UIP> | (() => any);
|
37
56
|
get UIProps(): UIP;
|
38
57
|
get soundBackgroundOptions(): SoundManagement[SoundType.BACKGROUND];
|
@@ -45,6 +64,7 @@ export declare abstract class Scene<UIP = any> {
|
|
45
64
|
protected getUIProps(): UIP;
|
46
65
|
get loadedAssets(): boolean;
|
47
66
|
private set loadedAssets(value);
|
67
|
+
private set loadedAssetsError(value);
|
48
68
|
onProcessStateChangeListener(func: ProcessStateChangeListener): () => void;
|
49
69
|
onSoundOnceOptionsChange(func: SoundOptionsChangeListener<SoundType.ONCE>): () => void;
|
50
70
|
onSoundBackgroundOptionsChange(func: SoundOptionsChangeListener<SoundType.BACKGROUND>): () => void;
|
@@ -66,7 +86,7 @@ export declare abstract class Scene<UIP = any> {
|
|
66
86
|
})[]): Promise<Sound[]>;
|
67
87
|
mapSprites(...srcs: string[]): Promise<void>;
|
68
88
|
mapSounds(...srcs: string[]): Promise<void>;
|
69
|
-
loadAssets(delay?:
|
89
|
+
loadAssets(delay: number | undefined | null, { skip, render }?: AssetsFailBehavior): Promise<void>;
|
70
90
|
onLoadAssets(): Promise<void>;
|
71
91
|
getPrefab<C extends EntitySult>(Class: {
|
72
92
|
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,k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,QAAQ,EAAE,CAAC,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAC,EAAE;IAsBxE,UAAU,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;IAgB5B,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;IA+C7C,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; });
|
@@ -125,6 +132,14 @@ var Scene = /** @class */ (function () {
|
|
125
132
|
enumerable: false,
|
126
133
|
configurable: true
|
127
134
|
});
|
135
|
+
Object.defineProperty(Scene.prototype, "loadedAssetsError", {
|
136
|
+
set: function (errors) {
|
137
|
+
var _a;
|
138
|
+
(_a = this.loadAssetsListener) === null || _a === void 0 ? void 0 : _a.call(this, this._loadedAssets, errors);
|
139
|
+
},
|
140
|
+
enumerable: false,
|
141
|
+
configurable: true
|
142
|
+
});
|
128
143
|
Scene.prototype.onProcessStateChangeListener = function (func) {
|
129
144
|
var listeners = this.processStateChangeListeners;
|
130
145
|
listeners.push(func);
|
@@ -195,23 +210,32 @@ var Scene = /** @class */ (function () {
|
|
195
210
|
this.manager.gotoScene(tag);
|
196
211
|
};
|
197
212
|
Scene.prototype.loadSprites = function () {
|
198
|
-
|
199
|
-
|
200
|
-
var sprite;
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
214
|
+
var _this_1 = this;
|
201
215
|
return __generator(this, function (_a) {
|
202
216
|
switch (_a.label) {
|
203
|
-
case 0:
|
204
|
-
|
205
|
-
|
217
|
+
case 0: return [4 /*yield*/, parallel(this.spritesDecor, function (decor) { return __awaiter(_this_1, void 0, void 0, function () {
|
218
|
+
var sprite;
|
219
|
+
return __generator(this, function (_a) {
|
220
|
+
switch (_a.label) {
|
221
|
+
case 0:
|
222
|
+
if (!decor.src) return [3 /*break*/, 2];
|
223
|
+
return [4 /*yield*/, createAssetImage(decor.src)];
|
224
|
+
case 1:
|
225
|
+
sprite = _a.sent();
|
226
|
+
this[decor.propertyKey] = sprite;
|
227
|
+
this.sprites.push(sprite);
|
228
|
+
_a.label = 2;
|
229
|
+
case 2: return [2 /*return*/];
|
230
|
+
}
|
231
|
+
});
|
232
|
+
}); }, MAX_ASSET_PARALLEL_LOAD)];
|
206
233
|
case 1:
|
207
|
-
|
208
|
-
|
209
|
-
this.sprites.push(sprite);
|
210
|
-
_a.label = 2;
|
211
|
-
case 2: return [2 /*return*/];
|
234
|
+
_a.sent();
|
235
|
+
return [2 /*return*/];
|
212
236
|
}
|
213
237
|
});
|
214
|
-
});
|
238
|
+
});
|
215
239
|
};
|
216
240
|
Scene.prototype.loadSounds = function () {
|
217
241
|
return __awaiter(this, void 0, void 0, function () {
|
@@ -373,10 +397,12 @@ var Scene = /** @class */ (function () {
|
|
373
397
|
});
|
374
398
|
});
|
375
399
|
};
|
376
|
-
Scene.prototype.loadAssets = function (delay) {
|
400
|
+
Scene.prototype.loadAssets = function (delay, _a) {
|
401
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.skip, skip = _c === void 0 ? false : _c, render = _b.render;
|
377
402
|
return __awaiter(this, void 0, void 0, function () {
|
378
|
-
|
379
|
-
|
403
|
+
var result, hasErrors, errors_1;
|
404
|
+
return __generator(this, function (_d) {
|
405
|
+
switch (_d.label) {
|
380
406
|
case 0:
|
381
407
|
if (delay != null) {
|
382
408
|
this.assetsDelay = delay;
|
@@ -385,22 +411,46 @@ var Scene = /** @class */ (function () {
|
|
385
411
|
return [4 /*yield*/, tick(this.assetsDelay < 0 ? undefined : this.assetsDelay)];
|
386
412
|
case 1:
|
387
413
|
// if delay less than 0, it will wait forever
|
388
|
-
|
414
|
+
_d.sent();
|
389
415
|
this.loadedAssets = false;
|
390
416
|
return [4 /*yield*/, Promise.all([
|
391
417
|
this.loadSounds().catch(function (err) {
|
392
|
-
|
418
|
+
return {
|
419
|
+
error: true,
|
420
|
+
type: "load-sound",
|
421
|
+
detail: err,
|
422
|
+
};
|
393
423
|
}),
|
394
424
|
this.loadSprites().catch(function (err) {
|
395
|
-
|
425
|
+
return {
|
426
|
+
error: true,
|
427
|
+
type: "load-sprite",
|
428
|
+
detail: err,
|
429
|
+
};
|
396
430
|
}),
|
397
431
|
this.onLoadAssets().catch(function (err) {
|
398
|
-
|
432
|
+
return {
|
433
|
+
error: true,
|
434
|
+
type: "load-extends",
|
435
|
+
detail: err,
|
436
|
+
};
|
399
437
|
}),
|
400
438
|
])];
|
401
439
|
case 2:
|
402
|
-
|
403
|
-
|
440
|
+
result = _d.sent();
|
441
|
+
hasErrors = result.some(function (rs) { return rs === null || rs === void 0 ? void 0 : rs.error; });
|
442
|
+
if (hasErrors && !skip) {
|
443
|
+
errors_1 = result.filter(function (rs) { return !!(rs === null || rs === void 0 ? void 0 : rs.error); });
|
444
|
+
// this.loadedAssets = false;
|
445
|
+
this._renderAssetsFail = function () {
|
446
|
+
return render ? render(errors_1) : errors_1;
|
447
|
+
};
|
448
|
+
this.loadedAssetsError = errors_1;
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
// when dont have error or skip error
|
452
|
+
this.loadedAssets = true;
|
453
|
+
}
|
404
454
|
return [2 /*return*/];
|
405
455
|
}
|
406
456
|
});
|
@@ -430,12 +480,13 @@ var Scene = /** @class */ (function () {
|
|
430
480
|
this.bootSoundOptions();
|
431
481
|
this.onProcessStateChangeListener(function (isForeground) {
|
432
482
|
if (isForeground) {
|
433
|
-
|
434
|
-
var
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
483
|
+
if (window.Renderer.running) {
|
484
|
+
for (var _i = 0, _a = _this_1.sounds; _i < _a.length; _i++) {
|
485
|
+
var sound = _a[_i];
|
486
|
+
// only resume background sounds
|
487
|
+
if (sound.type === SoundType.BACKGROUND) {
|
488
|
+
sound.resume();
|
489
|
+
}
|
439
490
|
}
|
440
491
|
}
|
441
492
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"game-bootstrap.d.ts","sourceRoot":"","sources":["../../src/ui-components/game-bootstrap.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAmB,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAe,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAErE,aAAK,cAAc,GAAG,sBAAsB,GAAG;IAC7C,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,
|
1
|
+
{"version":3,"file":"game-bootstrap.d.ts","sourceRoot":"","sources":["../../src/ui-components/game-bootstrap.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAmB,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAe,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAErE,aAAK,cAAc,GAAG,sBAAsB,GAAG;IAC7C,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,eAkCjE"}
|
@@ -31,6 +31,7 @@ export function GameBootstrap(_a) {
|
|
31
31
|
}, [scenes]);
|
32
32
|
var _b = useState(sceneManagement.currentScene), currentScene = _b[0], setCurrentScene = _b[1];
|
33
33
|
var _c = useState(currentScene.loadedAssets), setLoadedAssets = _c[1];
|
34
|
+
var _d = useState([]), setLoadAssetsError = _d[1];
|
34
35
|
useEffect(function () {
|
35
36
|
sceneManagement.onChangeScene(function (scene) {
|
36
37
|
setCurrentScene(scene);
|
@@ -38,8 +39,11 @@ export function GameBootstrap(_a) {
|
|
38
39
|
});
|
39
40
|
}, [sceneManagement]);
|
40
41
|
useEffect(function () {
|
41
|
-
currentScene.onLoadAssetNotify(function (isLoaded) {
|
42
|
+
currentScene.onLoadAssetNotify(function (isLoaded, errors) {
|
42
43
|
setLoadedAssets(isLoaded);
|
44
|
+
if (errors) {
|
45
|
+
setLoadAssetsError(errors);
|
46
|
+
}
|
43
47
|
});
|
44
48
|
}, [currentScene]);
|
45
49
|
return (_jsx(SceneRunner, __assign({ current: currentScene }, props), currentScene.sessionId));
|
@@ -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");
|