@zhongguo168a/yxeditor-common 0.0.9 → 0.0.10

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/dist/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  import { HorizontalTextAlignment, VerticalTextAlignment, Scheduler, Prefab, Node, Component, ISchedulable, AssetManager, Asset, SpriteAtlas, Vec2, Vec3, Vec4 } from 'cc';
2
- import { Dispatcher as Dispatcher$1 } from 'db://assets/core/libs/event';
3
- import { List as List$1 } from 'db://assets/core/libs/ds';
4
- import { AssetURI as AssetURI$1 } from 'db://assets/core/libs/loader/AssetManager';
5
2
 
6
3
  interface error {
7
4
  isCancel(): boolean;
@@ -1292,20 +1289,35 @@ declare class Dispatcher implements ISchedulable {
1292
1289
  protected typeToList: Dictionary<string, CallbackList<any>>;
1293
1290
  }
1294
1291
 
1292
+ declare class AssetURI {
1293
+ name: string;
1294
+ constructor(name: string);
1295
+ loadType: number;
1296
+ uuid: string;
1297
+ path: string;
1298
+ bundle: string;
1299
+ }
1300
+ declare class XAssetManager {
1301
+ getAsset(uri: string): any;
1302
+ getAssetByUUID(uuid: string): any;
1303
+ getRoot(): AssetManager;
1304
+ }
1305
+ declare let assetx: XAssetManager;
1306
+
1295
1307
  declare class LoaderItem {
1296
1308
  onComplete?: (err: any, asset: any) => void;
1297
1309
  callHandler(err: any, asset: any): void;
1298
1310
  getBundle(): AssetManager.Bundle;
1299
1311
  type: string;
1300
1312
  bundle: AssetManager.Bundle;
1301
- uri: AssetURI$1;
1313
+ uri: AssetURI;
1302
1314
  preload: boolean;
1303
1315
  error: any;
1304
1316
  }
1305
1317
  /**
1306
1318
  * uri格式:path, uuid://uuid, https://url
1307
1319
  */
1308
- declare class AssetLoader extends Dispatcher$1 {
1320
+ declare class AssetLoader extends Dispatcher {
1309
1321
  /**
1310
1322
  *
1311
1323
  * @param bundleName
@@ -1353,32 +1365,17 @@ declare class AssetLoader extends Dispatcher$1 {
1353
1365
  getTotle(): number;
1354
1366
  getSucceed(): number;
1355
1367
  getFail(): number;
1356
- getFailList(): List$1<LoaderItem>;
1368
+ getFailList(): List<LoaderItem>;
1357
1369
  protected _handleFailList(err: any, item: any): void;
1358
1370
  stop(): void;
1359
1371
  protected _stop: boolean;
1360
1372
  protected _onCompleteHandler: Function;
1361
1373
  protected _onProgressHandler: Function;
1362
1374
  protected _loaded: number;
1363
- protected _loaderList: any;
1364
- protected _failList: any;
1375
+ protected _loaderList: List<LoaderItem>;
1376
+ protected _failList: List<LoaderItem>;
1365
1377
  }
1366
1378
 
1367
- declare class AssetURI {
1368
- name: string;
1369
- constructor(name: string);
1370
- loadType: number;
1371
- uuid: string;
1372
- path: string;
1373
- bundle: string;
1374
- }
1375
- declare class XAssetManager {
1376
- getAsset(uri: string): any;
1377
- getAssetByUUID(uuid: string): any;
1378
- getRoot(): AssetManager;
1379
- }
1380
- declare let assetx: XAssetManager;
1381
-
1382
1379
  declare function parseAtlas(name: any, plist: any, texture: any): SpriteAtlas;
1383
1380
 
1384
1381
  type CreatorFunction = (...args: any[]) => {};
package/dist/index.esm.js CHANGED
@@ -1,8 +1,4 @@
1
- import { HorizontalTextAlignment, VerticalTextAlignment, Scheduler, macro, director, instantiate, math, Component, ImageAsset, SpriteFrame, SpriteAtlas, assetManager, JsonAsset, TextAsset, Asset, path, Texture2D, Size, Vec2, Rect, Vec3, UITransform, Vec4, resources } from 'cc';
2
- import { parseAtlas as parseAtlas$1 } from 'db://assets/core/libs/loader/ParseAtlas';
3
- import { Dispatcher as Dispatcher$1, Listener as Listener$1 } from 'db://assets/core/libs/event';
4
- import { List as List$1 } from 'db://assets/core/libs/ds';
5
- import { AssetURI as AssetURI$1, assetx as assetx$1 } from 'db://assets/core/libs/loader/AssetManager';
1
+ import { HorizontalTextAlignment, VerticalTextAlignment, Scheduler, macro, director, instantiate, math, Component, SpriteAtlas, Size, Vec2, Rect, SpriteFrame, path, assetManager, ImageAsset, JsonAsset, TextAsset, Asset, Texture2D, Vec3, UITransform, Vec4, resources } from 'cc';
6
2
 
7
3
  class NetUtil {
8
4
  // 获取URL的参数对象
@@ -4331,6 +4327,111 @@ class Dispatcher {
4331
4327
  }
4332
4328
  }
4333
4329
 
4330
+ function parseAtlas(name, plist, texture) {
4331
+ plist.meta;
4332
+ let frames = plist.frames;
4333
+ let atlas = new SpriteAtlas();
4334
+ atlas.name = name;
4335
+ atlas._nativeAsset = plist;
4336
+ let spriteFrames = atlas.spriteFrames;
4337
+ // 1/1_1_0.png:{
4338
+ // frame: {x: 137, y: 302, w: 18, h: 24}
4339
+ // rotated: false
4340
+ // sourceSize: {w: 32, h: 32}
4341
+ // spriteSourceSize: {x: 7, y: 0, w: 18, h: 24}
4342
+ // trimmed: true
4343
+ // }
4344
+ let maxWidth = 0;
4345
+ let maxHeight = 0;
4346
+ for (let key in frames) {
4347
+ let frame = frames[key];
4348
+ let rotated = false, sourceSize, offset, textureRect;
4349
+ rotated = frame.rotated;
4350
+ {
4351
+ let size = frame.sourceSize;
4352
+ sourceSize = new Size(size.w, size.h);
4353
+ maxWidth = Math.max(maxWidth, size.w);
4354
+ maxHeight = Math.max(maxHeight, size.h);
4355
+ }
4356
+ { // 需要转化成以sourceSize的中心点为原点,cocos坐标系的偏移量
4357
+ let pos = frame.spriteSourceSize;
4358
+ offset = new Vec2(pos.x + pos.w * 0.5, pos.y + pos.h * 0.5);
4359
+ offset.x -= sourceSize.width * 0.5;
4360
+ offset.y -= sourceSize.height * 0.5;
4361
+ offset.y = -offset.y; // y轴相反
4362
+ }
4363
+ {
4364
+ let rect = frame.frame;
4365
+ textureRect = new Rect(rect.x, rect.y, rect.w, rect.h);
4366
+ }
4367
+ var sprite = new SpriteFrame();
4368
+ sprite.name = key;
4369
+ sprite.reset({
4370
+ originalSize: sourceSize,
4371
+ rect: textureRect,
4372
+ offset: offset,
4373
+ isRotate: !!rotated,
4374
+ texture: texture
4375
+ });
4376
+ let name = path.mainFileName(key);
4377
+ spriteFrames[name] = sprite;
4378
+ }
4379
+ //
4380
+ plist.meta.maxSize = { w: maxWidth, h: maxHeight };
4381
+ return atlas;
4382
+ }
4383
+
4384
+ class AssetURI {
4385
+ constructor(name) {
4386
+ this.name = name;
4387
+ // 0-bundle+path 1-uuid 2-remote
4388
+ this.loadType = 0;
4389
+ let arr = name.split("://");
4390
+ if (arr.length == 2) {
4391
+ let head = arr[0];
4392
+ if (head == "uuid") {
4393
+ this.loadType = 1;
4394
+ this.uuid = arr[1];
4395
+ }
4396
+ else if (head == "http" || head == "https") {
4397
+ this.loadType = 2;
4398
+ }
4399
+ else {
4400
+ this.bundle = head;
4401
+ this.path = arr[1];
4402
+ }
4403
+ }
4404
+ else {
4405
+ this.bundle = "resources";
4406
+ this.path = name;
4407
+ }
4408
+ }
4409
+ }
4410
+ class XAssetManager {
4411
+ getAsset(uri) {
4412
+ let obj = new AssetURI(uri);
4413
+ switch (obj.loadType) {
4414
+ case 1:
4415
+ return assetManager.assets.get(obj.uuid);
4416
+ case 2:
4417
+ return assetManager.assets.get(obj.name);
4418
+ default:
4419
+ let bundle = assetManager.getBundle(obj.bundle);
4420
+ if (!bundle) {
4421
+ return null;
4422
+ }
4423
+ return bundle.get(obj.path);
4424
+ }
4425
+ }
4426
+ getAssetByUUID(uuid) {
4427
+ return assetManager.assets.get(uuid);
4428
+ }
4429
+ getRoot() {
4430
+ return assetManager;
4431
+ }
4432
+ }
4433
+ let assetx = new XAssetManager();
4434
+
4334
4435
  class LoaderItem {
4335
4436
  constructor() {
4336
4437
  this.preload = false;
@@ -4352,13 +4453,13 @@ class LoaderItem {
4352
4453
  /**
4353
4454
  * uri格式:path, uuid://uuid, https://url
4354
4455
  */
4355
- class AssetLoader extends Dispatcher$1 {
4456
+ class AssetLoader extends Dispatcher {
4356
4457
  constructor() {
4357
4458
  super(...arguments);
4358
4459
  this._stop = false;
4359
4460
  this._loaded = 0;
4360
- this._loaderList = new List$1();
4361
- this._failList = new List$1();
4461
+ this._loaderList = new List();
4462
+ this._failList = new List();
4362
4463
  }
4363
4464
  /**
4364
4465
  *
@@ -4368,7 +4469,7 @@ class AssetLoader extends Dispatcher$1 {
4368
4469
  loadBundle(bundleName, otherConfig) {
4369
4470
  let item = new LoaderItem();
4370
4471
  item.type = "Bundle";
4371
- item.uri = new AssetURI$1(`${bundleName}://bundle`);
4472
+ item.uri = new AssetURI(`${bundleName}://bundle`);
4372
4473
  if (otherConfig) {
4373
4474
  item.preload = otherConfig.preload;
4374
4475
  item.onComplete = otherConfig.onComplete;
@@ -4384,7 +4485,7 @@ class AssetLoader extends Dispatcher$1 {
4384
4485
  let item = new LoaderItem();
4385
4486
  item.type = "Atlas";
4386
4487
  // 加载json文件
4387
- item.uri = new AssetURI$1(uri);
4488
+ item.uri = new AssetURI(uri);
4388
4489
  if (otherConfig) {
4389
4490
  item.onComplete = otherConfig.onComplete;
4390
4491
  item.preload = otherConfig.preload != undefined ? otherConfig.preload : false;
@@ -4396,7 +4497,7 @@ class AssetLoader extends Dispatcher$1 {
4396
4497
  let item = new LoaderItem();
4397
4498
  item.type = "Prefab";
4398
4499
  // 加载json文件
4399
- item.uri = new AssetURI$1(uri);
4500
+ item.uri = new AssetURI(uri);
4400
4501
  if (otherConfig) {
4401
4502
  item.onComplete = otherConfig.onComplete;
4402
4503
  item.preload = otherConfig.preload != undefined ? otherConfig.preload : false;
@@ -4407,14 +4508,14 @@ class AssetLoader extends Dispatcher$1 {
4407
4508
  loadConfig(uri) {
4408
4509
  let item = new LoaderItem();
4409
4510
  item.type = "Config";
4410
- item.uri = new AssetURI$1(uri);
4511
+ item.uri = new AssetURI(uri);
4411
4512
  this._loaderList.push(item);
4412
4513
  return this;
4413
4514
  }
4414
4515
  loadSpriteFrame(uri, otherConfig) {
4415
4516
  let item = new LoaderItem();
4416
4517
  item.type = "SpriteFrame";
4417
- item.uri = new AssetURI$1(uri);
4518
+ item.uri = new AssetURI(uri);
4418
4519
  if (otherConfig) {
4419
4520
  item.onComplete = otherConfig.onComplete;
4420
4521
  }
@@ -4424,7 +4525,7 @@ class AssetLoader extends Dispatcher$1 {
4424
4525
  loadImageAsset(uri, otherConfig) {
4425
4526
  let item = new LoaderItem();
4426
4527
  item.type = "ImageAsset";
4427
- item.uri = new AssetURI$1(uri);
4528
+ item.uri = new AssetURI(uri);
4428
4529
  if (otherConfig) {
4429
4530
  item.onComplete = otherConfig.onHandler;
4430
4531
  }
@@ -4434,7 +4535,7 @@ class AssetLoader extends Dispatcher$1 {
4434
4535
  _loadSpriteFrameByBundle(uri, bundle) {
4435
4536
  let item = new LoaderItem();
4436
4537
  item.type = "SpriteFrame";
4437
- item.uri = new AssetURI$1(`${bundle.name}://${uri}`);
4538
+ item.uri = new AssetURI(`${bundle.name}://${uri}`);
4438
4539
  item.bundle = bundle;
4439
4540
  this._loaderList.push(item);
4440
4541
  }
@@ -4448,7 +4549,7 @@ class AssetLoader extends Dispatcher$1 {
4448
4549
  resolve(this);
4449
4550
  }
4450
4551
  else {
4451
- let listener = Listener$1.create();
4552
+ let listener = Listener.create();
4452
4553
  let succeed = () => {
4453
4554
  listener.off();
4454
4555
  resolve(this);
@@ -4489,7 +4590,7 @@ class AssetLoader extends Dispatcher$1 {
4489
4590
  break;
4490
4591
  }
4491
4592
  case "Atlas": {
4492
- let asset = assetx$1.getAsset(item.uri.name);
4593
+ let asset = assetx.getAsset(item.uri.name);
4493
4594
  if (asset) {
4494
4595
  if (asset instanceof SpriteAtlas) {
4495
4596
  this._loaded++;
@@ -4515,7 +4616,7 @@ class AssetLoader extends Dispatcher$1 {
4515
4616
  break;
4516
4617
  }
4517
4618
  case "Prefab": {
4518
- let asset = assetx$1.getAsset(item.uri.name);
4619
+ let asset = assetx.getAsset(item.uri.name);
4519
4620
  if (asset) {
4520
4621
  this._loaded++;
4521
4622
  item.callHandler(null, asset);
@@ -4622,14 +4723,14 @@ class AssetLoader extends Dispatcher$1 {
4622
4723
  textureUrl = item.uri.name;
4623
4724
  break;
4624
4725
  }
4625
- textureItem.uri = new AssetURI$1(textureUrl);
4726
+ textureItem.uri = new AssetURI(textureUrl);
4626
4727
  //
4627
4728
  this._loadByItem(textureItem, ImageAsset, (err, asset) => {
4628
4729
  if (!err) {
4629
4730
  let tex = new Texture2D();
4630
4731
  tex.image = asset;
4631
4732
  tex.setFilters(1, 1);
4632
- let atlasSprite = parseAtlas$1(item.uri, content, tex);
4733
+ let atlasSprite = parseAtlas(item.uri, content, tex);
4633
4734
  let uuid = atlasAsset.uuid;
4634
4735
  assetManager.assets.remove(uuid);
4635
4736
  assetManager.assets.add(uuid, atlasSprite);
@@ -4729,111 +4830,6 @@ class AssetLoader extends Dispatcher$1 {
4729
4830
  }
4730
4831
  }
4731
4832
 
4732
- class AssetURI {
4733
- constructor(name) {
4734
- this.name = name;
4735
- // 0-bundle+path 1-uuid 2-remote
4736
- this.loadType = 0;
4737
- let arr = name.split("://");
4738
- if (arr.length == 2) {
4739
- let head = arr[0];
4740
- if (head == "uuid") {
4741
- this.loadType = 1;
4742
- this.uuid = arr[1];
4743
- }
4744
- else if (head == "http" || head == "https") {
4745
- this.loadType = 2;
4746
- }
4747
- else {
4748
- this.bundle = head;
4749
- this.path = arr[1];
4750
- }
4751
- }
4752
- else {
4753
- this.bundle = "resources";
4754
- this.path = name;
4755
- }
4756
- }
4757
- }
4758
- class XAssetManager {
4759
- getAsset(uri) {
4760
- let obj = new AssetURI(uri);
4761
- switch (obj.loadType) {
4762
- case 1:
4763
- return assetManager.assets.get(obj.uuid);
4764
- case 2:
4765
- return assetManager.assets.get(obj.name);
4766
- default:
4767
- let bundle = assetManager.getBundle(obj.bundle);
4768
- if (!bundle) {
4769
- return null;
4770
- }
4771
- return bundle.get(obj.path);
4772
- }
4773
- }
4774
- getAssetByUUID(uuid) {
4775
- return assetManager.assets.get(uuid);
4776
- }
4777
- getRoot() {
4778
- return assetManager;
4779
- }
4780
- }
4781
- let assetx = new XAssetManager();
4782
-
4783
- function parseAtlas(name, plist, texture) {
4784
- plist.meta;
4785
- let frames = plist.frames;
4786
- let atlas = new SpriteAtlas();
4787
- atlas.name = name;
4788
- atlas._nativeAsset = plist;
4789
- let spriteFrames = atlas.spriteFrames;
4790
- // 1/1_1_0.png:{
4791
- // frame: {x: 137, y: 302, w: 18, h: 24}
4792
- // rotated: false
4793
- // sourceSize: {w: 32, h: 32}
4794
- // spriteSourceSize: {x: 7, y: 0, w: 18, h: 24}
4795
- // trimmed: true
4796
- // }
4797
- let maxWidth = 0;
4798
- let maxHeight = 0;
4799
- for (let key in frames) {
4800
- let frame = frames[key];
4801
- let rotated = false, sourceSize, offset, textureRect;
4802
- rotated = frame.rotated;
4803
- {
4804
- let size = frame.sourceSize;
4805
- sourceSize = new Size(size.w, size.h);
4806
- maxWidth = Math.max(maxWidth, size.w);
4807
- maxHeight = Math.max(maxHeight, size.h);
4808
- }
4809
- { // 需要转化成以sourceSize的中心点为原点,cocos坐标系的偏移量
4810
- let pos = frame.spriteSourceSize;
4811
- offset = new Vec2(pos.x + pos.w * 0.5, pos.y + pos.h * 0.5);
4812
- offset.x -= sourceSize.width * 0.5;
4813
- offset.y -= sourceSize.height * 0.5;
4814
- offset.y = -offset.y; // y轴相反
4815
- }
4816
- {
4817
- let rect = frame.frame;
4818
- textureRect = new Rect(rect.x, rect.y, rect.w, rect.h);
4819
- }
4820
- var sprite = new SpriteFrame();
4821
- sprite.name = key;
4822
- sprite.reset({
4823
- originalSize: sourceSize,
4824
- rect: textureRect,
4825
- offset: offset,
4826
- isRotate: !!rotated,
4827
- texture: texture
4828
- });
4829
- let name = path.mainFileName(key);
4830
- spriteFrames[name] = sprite;
4831
- }
4832
- //
4833
- plist.meta.maxSize = { w: maxWidth, h: maxHeight };
4834
- return atlas;
4835
- }
4836
-
4837
4833
  class UIUtil {
4838
4834
  /**
4839
4835
  * 格式化节点的uuid,用于树结构