@galacean/effects-core 1.2.0 → 1.2.2

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.
@@ -1,5 +1,4 @@
1
1
  import type * as spec from '@galacean/effects-specification';
2
- import type { JSONValue } from './downloader';
3
2
  import { Downloader } from './downloader';
4
3
  import type { Disposable } from './utils';
5
4
  import type { Scene } from './scene';
@@ -73,6 +72,10 @@ export interface SceneLoadOptions {
73
72
  */
74
73
  speed?: number;
75
74
  }
75
+ /**
76
+ * 被接受用于加载的数据类型
77
+ */
78
+ export type SceneType = string | Scene | Record<string, unknown>;
76
79
  /**
77
80
  * 资源管理器
78
81
  * 用于加载和动效中所有的资源文件,包括图片、插件、图层粒子数据等
@@ -98,6 +101,10 @@ export declare class AssetManager implements Disposable {
98
101
  * @default 10
99
102
  */
100
103
  private timeout;
104
+ /**
105
+ * 场景加载的超时定时器
106
+ */
107
+ private timers;
101
108
  /**
102
109
  * 构造函数
103
110
  * @param options - 场景加载参数
@@ -112,7 +119,7 @@ export declare class AssetManager implements Disposable {
112
119
  * @param options - 扩展参数
113
120
  * @returns
114
121
  */
115
- loadScene(url: string | JSONValue | Scene, renderer?: Renderer, options?: {
122
+ loadScene(url: SceneType, renderer?: Renderer, options?: {
116
123
  env: string;
117
124
  }): Promise<Scene>;
118
125
  private precompile;
@@ -123,6 +130,7 @@ export declare class AssetManager implements Disposable {
123
130
  private processTextures;
124
131
  private loadJSON;
125
132
  private loadBins;
133
+ private removeTimer;
126
134
  /**
127
135
  * 销毁方法
128
136
  */
@@ -1,6 +1,6 @@
1
1
  import * as spec from '@galacean/effects-specification';
2
2
  import type { Ray } from '@galacean/effects-math/es/core/index';
3
- import type { JSONValue } from './downloader';
3
+ import type { SceneType } from './asset-manager';
4
4
  import type { Scene } from './scene';
5
5
  import type { Disposable, LostHandler } from './utils';
6
6
  import { Transform } from './transform';
@@ -138,7 +138,7 @@ export declare class Composition implements Disposable, LostHandler {
138
138
  /**
139
139
  * 合成对应的 url 或者 JSON
140
140
  */
141
- readonly url: string | JSONValue;
141
+ readonly url: SceneType;
142
142
  /**
143
143
  * 合成对象
144
144
  */
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.2.0
6
+ * Version: v1.2.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -19972,9 +19972,10 @@ var TextItem = /** @class */ (function (_super) {
19972
19972
  if (this.textStyle.fontSize === value) {
19973
19973
  return;
19974
19974
  }
19975
+ // 保证字号变化后位置正常
19976
+ var diff = this.textStyle.fontSize - value;
19977
+ this.textLayout.lineHeight += diff;
19975
19978
  this.textStyle.fontSize = value;
19976
- // 1.5175 = 31.43 / 20
19977
- this.textLayout.lineHeight = this.textStyle.fontSize * 1.5175;
19978
19979
  this.isDirty = true;
19979
19980
  };
19980
19981
  /**
@@ -23454,6 +23455,10 @@ var AssetManager = /** @class */ (function () {
23454
23455
  */
23455
23456
  this.assets = {};
23456
23457
  this.id = seed$1++;
23458
+ /**
23459
+ * 场景加载的超时定时器
23460
+ */
23461
+ this.timers = [];
23457
23462
  this.updateOptions(options);
23458
23463
  }
23459
23464
  AssetManager.prototype.updateOptions = function (options) {
@@ -23486,25 +23491,33 @@ var AssetManager = /** @class */ (function () {
23486
23491
  compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
23487
23492
  cancelLoading = false;
23488
23493
  waitPromise = new Promise(function (resolve, reject) {
23489
- return loadTimer = window.setTimeout(function () {
23494
+ loadTimer = window.setTimeout(function () {
23490
23495
  cancelLoading = true;
23496
+ _this.removeTimer(loadTimer);
23491
23497
  var totalTime = performance.now() - startTime;
23492
23498
  reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
23493
23499
  }, _this.timeout * 1000);
23500
+ _this.timers.push(loadTimer);
23494
23501
  });
23495
23502
  hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
23496
- var st, result;
23503
+ var st, result, e_1;
23497
23504
  return __generator(this, function (_a) {
23498
23505
  switch (_a.label) {
23499
23506
  case 0:
23500
- if (!!cancelLoading) return [3 /*break*/, 2];
23507
+ if (!!cancelLoading) return [3 /*break*/, 4];
23501
23508
  st = performance.now();
23502
- return [4 /*yield*/, func()];
23509
+ _a.label = 1;
23503
23510
  case 1:
23511
+ _a.trys.push([1, 3, , 4]);
23512
+ return [4 /*yield*/, func()];
23513
+ case 2:
23504
23514
  result = _a.sent();
23505
23515
  timeInfos.push("[".concat(label, ": ").concat((performance.now() - st).toFixed(2), "]"));
23506
23516
  return [2 /*return*/, result];
23507
- case 2: throw new Error('load canceled.');
23517
+ case 3:
23518
+ e_1 = _a.sent();
23519
+ throw new Error("load error in ".concat(label, ", ").concat(e_1));
23520
+ case 4: throw new Error('load canceled.');
23508
23521
  }
23509
23522
  });
23510
23523
  }); };
@@ -23588,6 +23601,7 @@ var AssetManager = /** @class */ (function () {
23588
23601
  totalTime = performance.now() - startTime;
23589
23602
  logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
23590
23603
  window.clearTimeout(loadTimer);
23604
+ this.removeTimer(loadTimer);
23591
23605
  scene.totalTime = totalTime;
23592
23606
  scene.startTime = startTime;
23593
23607
  return [2 /*return*/, scene];
@@ -23896,16 +23910,26 @@ var AssetManager = /** @class */ (function () {
23896
23910
  });
23897
23911
  });
23898
23912
  };
23913
+ AssetManager.prototype.removeTimer = function (id) {
23914
+ var index = this.timers.indexOf(id);
23915
+ if (index !== -1) {
23916
+ this.timers.splice(index, 1);
23917
+ }
23918
+ };
23899
23919
  /**
23900
23920
  * 销毁方法
23901
23921
  */
23902
23922
  AssetManager.prototype.dispose = function () {
23903
23923
  var _a;
23924
+ if (this.timers.length) {
23925
+ this.timers.map(function (id) { return window.clearTimeout(id); });
23926
+ }
23904
23927
  for (var key in this.assets) {
23905
23928
  var asset = this.assets[key];
23906
23929
  (_a = asset === null || asset === void 0 ? void 0 : asset.dispose) === null || _a === void 0 ? void 0 : _a.call(asset);
23907
23930
  }
23908
23931
  this.assets = {};
23932
+ this.timers = [];
23909
23933
  };
23910
23934
  /**
23911
23935
  * 自定义文本缓存,随页面销毁而销毁