@zhongguo168a/yxeditor-common 0.0.8 → 0.0.9
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 +94 -2
- package/dist/index.esm.js +509 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { HorizontalTextAlignment, VerticalTextAlignment, Scheduler, Prefab, Node, Component, ISchedulable,
|
|
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';
|
|
2
5
|
|
|
3
6
|
interface error {
|
|
4
7
|
isCancel(): boolean;
|
|
@@ -1289,6 +1292,95 @@ declare class Dispatcher implements ISchedulable {
|
|
|
1289
1292
|
protected typeToList: Dictionary<string, CallbackList<any>>;
|
|
1290
1293
|
}
|
|
1291
1294
|
|
|
1295
|
+
declare class LoaderItem {
|
|
1296
|
+
onComplete?: (err: any, asset: any) => void;
|
|
1297
|
+
callHandler(err: any, asset: any): void;
|
|
1298
|
+
getBundle(): AssetManager.Bundle;
|
|
1299
|
+
type: string;
|
|
1300
|
+
bundle: AssetManager.Bundle;
|
|
1301
|
+
uri: AssetURI$1;
|
|
1302
|
+
preload: boolean;
|
|
1303
|
+
error: any;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* uri格式:path, uuid://uuid, https://url
|
|
1307
|
+
*/
|
|
1308
|
+
declare class AssetLoader extends Dispatcher$1 {
|
|
1309
|
+
/**
|
|
1310
|
+
*
|
|
1311
|
+
* @param bundleName
|
|
1312
|
+
* @param otherConfig preload:是预加载-否-加载, 包中的资源
|
|
1313
|
+
*/
|
|
1314
|
+
loadBundle(bundleName: string, otherConfig?: {
|
|
1315
|
+
onComplete?: (err: any, asset: any) => void;
|
|
1316
|
+
preload?: boolean;
|
|
1317
|
+
}): this;
|
|
1318
|
+
/**
|
|
1319
|
+
* @param uri
|
|
1320
|
+
* @param otherConfig
|
|
1321
|
+
*/
|
|
1322
|
+
loadAtlas(uri: string, otherConfig?: {
|
|
1323
|
+
onComplete?: (err: any, asset: any) => void;
|
|
1324
|
+
preload?: boolean;
|
|
1325
|
+
}): this;
|
|
1326
|
+
loadPrefab(uri: string, otherConfig?: {
|
|
1327
|
+
onComplete?: (err: any, asset: any) => void;
|
|
1328
|
+
preload?: boolean;
|
|
1329
|
+
}): this;
|
|
1330
|
+
loadConfig(uri: string): this;
|
|
1331
|
+
loadSpriteFrame(uri: string, otherConfig?: {
|
|
1332
|
+
onComplete?: (err: any, asset: any) => void;
|
|
1333
|
+
uuid?: string;
|
|
1334
|
+
}): this;
|
|
1335
|
+
loadImageAsset(uri: string, otherConfig?: {
|
|
1336
|
+
onHandler?: (err: any, asset: any) => void;
|
|
1337
|
+
}): this;
|
|
1338
|
+
protected _loadSpriteFrameByBundle(uri: string, bundle: AssetManager.Bundle): void;
|
|
1339
|
+
/**
|
|
1340
|
+
* 等待发送的结果
|
|
1341
|
+
* 如果返回 null,表示主动取消 [cancel]
|
|
1342
|
+
*/
|
|
1343
|
+
wait(): Promise<this>;
|
|
1344
|
+
start(): this;
|
|
1345
|
+
onComplete(val: (loader: AssetLoader) => void): this;
|
|
1346
|
+
onProgress(val: (loader: AssetLoader) => void): this;
|
|
1347
|
+
isComplete(): boolean;
|
|
1348
|
+
protected validComplete(): void;
|
|
1349
|
+
protected parseBundleToAssetsLoader(bundle: AssetManager.Bundle, loaderItem: LoaderItem): AssetLoader;
|
|
1350
|
+
protected handleAtlas(item: LoaderItem, atlasAsset: Asset): void;
|
|
1351
|
+
protected _loadByItem(item: LoaderItem, type: any, onComplate: (err: any, asset: any) => void): void;
|
|
1352
|
+
getLoaded(): number;
|
|
1353
|
+
getTotle(): number;
|
|
1354
|
+
getSucceed(): number;
|
|
1355
|
+
getFail(): number;
|
|
1356
|
+
getFailList(): List$1<LoaderItem>;
|
|
1357
|
+
protected _handleFailList(err: any, item: any): void;
|
|
1358
|
+
stop(): void;
|
|
1359
|
+
protected _stop: boolean;
|
|
1360
|
+
protected _onCompleteHandler: Function;
|
|
1361
|
+
protected _onProgressHandler: Function;
|
|
1362
|
+
protected _loaded: number;
|
|
1363
|
+
protected _loaderList: any;
|
|
1364
|
+
protected _failList: any;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
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
|
+
declare function parseAtlas(name: any, plist: any, texture: any): SpriteAtlas;
|
|
1383
|
+
|
|
1292
1384
|
type CreatorFunction = (...args: any[]) => {};
|
|
1293
1385
|
/**
|
|
1294
1386
|
* 回收的方法
|
|
@@ -1760,5 +1852,5 @@ declare const pathutil: PathUtil;
|
|
|
1760
1852
|
declare function parsePlist(plist: any, texture: any): SpriteAtlas;
|
|
1761
1853
|
declare function loadAtlas(url: any, callback: any): void;
|
|
1762
1854
|
|
|
1763
|
-
export { ArrayUtil, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XEvent, arrayutil, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timeutil, uidict, uimgr, uiutil };
|
|
1855
|
+
export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XAssetManager, XEvent, arrayutil, assetx, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timeutil, uidict, uimgr, uiutil };
|
|
1764
1856
|
export type { CreatorFunction, DisposeFunction, IController, IEventManager, IExtend, IListItem, IModel, IModule, IModuleSample, ITreeListItem, RecycleFunction, error };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { HorizontalTextAlignment, VerticalTextAlignment, Scheduler, macro, director, instantiate, math, Component,
|
|
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';
|
|
2
6
|
|
|
3
7
|
class NetUtil {
|
|
4
8
|
// 获取URL的参数对象
|
|
@@ -4327,6 +4331,509 @@ class Dispatcher {
|
|
|
4327
4331
|
}
|
|
4328
4332
|
}
|
|
4329
4333
|
|
|
4334
|
+
class LoaderItem {
|
|
4335
|
+
constructor() {
|
|
4336
|
+
this.preload = false;
|
|
4337
|
+
}
|
|
4338
|
+
callHandler(err, asset) {
|
|
4339
|
+
if (this.onComplete) {
|
|
4340
|
+
this.onComplete(err, asset);
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
getBundle() {
|
|
4344
|
+
let bundle = this.bundle;
|
|
4345
|
+
if (!bundle) {
|
|
4346
|
+
bundle = assetManager.getBundle(this.uri.bundle);
|
|
4347
|
+
this.bundle = bundle;
|
|
4348
|
+
}
|
|
4349
|
+
return bundle;
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
/**
|
|
4353
|
+
* uri格式:path, uuid://uuid, https://url
|
|
4354
|
+
*/
|
|
4355
|
+
class AssetLoader extends Dispatcher$1 {
|
|
4356
|
+
constructor() {
|
|
4357
|
+
super(...arguments);
|
|
4358
|
+
this._stop = false;
|
|
4359
|
+
this._loaded = 0;
|
|
4360
|
+
this._loaderList = new List$1();
|
|
4361
|
+
this._failList = new List$1();
|
|
4362
|
+
}
|
|
4363
|
+
/**
|
|
4364
|
+
*
|
|
4365
|
+
* @param bundleName
|
|
4366
|
+
* @param otherConfig preload:是预加载-否-加载, 包中的资源
|
|
4367
|
+
*/
|
|
4368
|
+
loadBundle(bundleName, otherConfig) {
|
|
4369
|
+
let item = new LoaderItem();
|
|
4370
|
+
item.type = "Bundle";
|
|
4371
|
+
item.uri = new AssetURI$1(`${bundleName}://bundle`);
|
|
4372
|
+
if (otherConfig) {
|
|
4373
|
+
item.preload = otherConfig.preload;
|
|
4374
|
+
item.onComplete = otherConfig.onComplete;
|
|
4375
|
+
}
|
|
4376
|
+
this._loaderList.push(item);
|
|
4377
|
+
return this;
|
|
4378
|
+
}
|
|
4379
|
+
/**
|
|
4380
|
+
* @param uri
|
|
4381
|
+
* @param otherConfig
|
|
4382
|
+
*/
|
|
4383
|
+
loadAtlas(uri, otherConfig) {
|
|
4384
|
+
let item = new LoaderItem();
|
|
4385
|
+
item.type = "Atlas";
|
|
4386
|
+
// 加载json文件
|
|
4387
|
+
item.uri = new AssetURI$1(uri);
|
|
4388
|
+
if (otherConfig) {
|
|
4389
|
+
item.onComplete = otherConfig.onComplete;
|
|
4390
|
+
item.preload = otherConfig.preload != undefined ? otherConfig.preload : false;
|
|
4391
|
+
}
|
|
4392
|
+
this._loaderList.push(item);
|
|
4393
|
+
return this;
|
|
4394
|
+
}
|
|
4395
|
+
loadPrefab(uri, otherConfig) {
|
|
4396
|
+
let item = new LoaderItem();
|
|
4397
|
+
item.type = "Prefab";
|
|
4398
|
+
// 加载json文件
|
|
4399
|
+
item.uri = new AssetURI$1(uri);
|
|
4400
|
+
if (otherConfig) {
|
|
4401
|
+
item.onComplete = otherConfig.onComplete;
|
|
4402
|
+
item.preload = otherConfig.preload != undefined ? otherConfig.preload : false;
|
|
4403
|
+
}
|
|
4404
|
+
this._loaderList.push(item);
|
|
4405
|
+
return this;
|
|
4406
|
+
}
|
|
4407
|
+
loadConfig(uri) {
|
|
4408
|
+
let item = new LoaderItem();
|
|
4409
|
+
item.type = "Config";
|
|
4410
|
+
item.uri = new AssetURI$1(uri);
|
|
4411
|
+
this._loaderList.push(item);
|
|
4412
|
+
return this;
|
|
4413
|
+
}
|
|
4414
|
+
loadSpriteFrame(uri, otherConfig) {
|
|
4415
|
+
let item = new LoaderItem();
|
|
4416
|
+
item.type = "SpriteFrame";
|
|
4417
|
+
item.uri = new AssetURI$1(uri);
|
|
4418
|
+
if (otherConfig) {
|
|
4419
|
+
item.onComplete = otherConfig.onComplete;
|
|
4420
|
+
}
|
|
4421
|
+
this._loaderList.push(item);
|
|
4422
|
+
return this;
|
|
4423
|
+
}
|
|
4424
|
+
loadImageAsset(uri, otherConfig) {
|
|
4425
|
+
let item = new LoaderItem();
|
|
4426
|
+
item.type = "ImageAsset";
|
|
4427
|
+
item.uri = new AssetURI$1(uri);
|
|
4428
|
+
if (otherConfig) {
|
|
4429
|
+
item.onComplete = otherConfig.onHandler;
|
|
4430
|
+
}
|
|
4431
|
+
this._loaderList.push(item);
|
|
4432
|
+
return this;
|
|
4433
|
+
}
|
|
4434
|
+
_loadSpriteFrameByBundle(uri, bundle) {
|
|
4435
|
+
let item = new LoaderItem();
|
|
4436
|
+
item.type = "SpriteFrame";
|
|
4437
|
+
item.uri = new AssetURI$1(`${bundle.name}://${uri}`);
|
|
4438
|
+
item.bundle = bundle;
|
|
4439
|
+
this._loaderList.push(item);
|
|
4440
|
+
}
|
|
4441
|
+
/**
|
|
4442
|
+
* 等待发送的结果
|
|
4443
|
+
* 如果返回 null,表示主动取消 [cancel]
|
|
4444
|
+
*/
|
|
4445
|
+
wait() {
|
|
4446
|
+
return new Promise((resolve, reject) => {
|
|
4447
|
+
if (this.isComplete()) {
|
|
4448
|
+
resolve(this);
|
|
4449
|
+
}
|
|
4450
|
+
else {
|
|
4451
|
+
let listener = Listener$1.create();
|
|
4452
|
+
let succeed = () => {
|
|
4453
|
+
listener.off();
|
|
4454
|
+
resolve(this);
|
|
4455
|
+
};
|
|
4456
|
+
listener.setCaller(this).setHandler(succeed).on();
|
|
4457
|
+
this.create("complete", listener);
|
|
4458
|
+
}
|
|
4459
|
+
});
|
|
4460
|
+
}
|
|
4461
|
+
start() {
|
|
4462
|
+
this._loaderList.forEach((index, item) => {
|
|
4463
|
+
switch (item.type) {
|
|
4464
|
+
case "Bundle": {
|
|
4465
|
+
assetManager.loadBundle(item.uri.bundle, (err, bundle) => {
|
|
4466
|
+
if (err) {
|
|
4467
|
+
return;
|
|
4468
|
+
}
|
|
4469
|
+
let loader = this.parseBundleToAssetsLoader(bundle, item);
|
|
4470
|
+
loader.onComplete(() => {
|
|
4471
|
+
this._loaded++;
|
|
4472
|
+
this.validComplete();
|
|
4473
|
+
});
|
|
4474
|
+
loader.start();
|
|
4475
|
+
});
|
|
4476
|
+
break;
|
|
4477
|
+
}
|
|
4478
|
+
case "Config": {
|
|
4479
|
+
assetManager.loadBundle(item.uri.bundle, (err, bundle) => {
|
|
4480
|
+
if (this._stop) {
|
|
4481
|
+
return;
|
|
4482
|
+
}
|
|
4483
|
+
if (err) {
|
|
4484
|
+
return;
|
|
4485
|
+
}
|
|
4486
|
+
this._loaded++;
|
|
4487
|
+
this.validComplete();
|
|
4488
|
+
});
|
|
4489
|
+
break;
|
|
4490
|
+
}
|
|
4491
|
+
case "Atlas": {
|
|
4492
|
+
let asset = assetx$1.getAsset(item.uri.name);
|
|
4493
|
+
if (asset) {
|
|
4494
|
+
if (asset instanceof SpriteAtlas) {
|
|
4495
|
+
this._loaded++;
|
|
4496
|
+
item.callHandler(null, asset);
|
|
4497
|
+
this.validComplete();
|
|
4498
|
+
}
|
|
4499
|
+
else {
|
|
4500
|
+
this.handleAtlas(item, asset);
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
else {
|
|
4504
|
+
// json文件
|
|
4505
|
+
this._loadByItem(item, null, (err, asset) => {
|
|
4506
|
+
if (!err) {
|
|
4507
|
+
this.handleAtlas(item, asset);
|
|
4508
|
+
}
|
|
4509
|
+
else {
|
|
4510
|
+
this._loaded++;
|
|
4511
|
+
this.validComplete();
|
|
4512
|
+
}
|
|
4513
|
+
});
|
|
4514
|
+
}
|
|
4515
|
+
break;
|
|
4516
|
+
}
|
|
4517
|
+
case "Prefab": {
|
|
4518
|
+
let asset = assetx$1.getAsset(item.uri.name);
|
|
4519
|
+
if (asset) {
|
|
4520
|
+
this._loaded++;
|
|
4521
|
+
item.callHandler(null, asset);
|
|
4522
|
+
this.validComplete();
|
|
4523
|
+
}
|
|
4524
|
+
else {
|
|
4525
|
+
this._loadByItem(item, null, (err, asset) => {
|
|
4526
|
+
this._loaded++;
|
|
4527
|
+
item.callHandler(err, asset);
|
|
4528
|
+
this.validComplete();
|
|
4529
|
+
});
|
|
4530
|
+
}
|
|
4531
|
+
break;
|
|
4532
|
+
}
|
|
4533
|
+
case "SpriteFrame": {
|
|
4534
|
+
this._loadByItem(item, SpriteFrame, (err, asset) => {
|
|
4535
|
+
this._loaded++;
|
|
4536
|
+
this.validComplete();
|
|
4537
|
+
});
|
|
4538
|
+
break;
|
|
4539
|
+
}
|
|
4540
|
+
case "ImageAsset": {
|
|
4541
|
+
this._loadByItem(item, ImageAsset, (err, asset) => {
|
|
4542
|
+
this._loaded++;
|
|
4543
|
+
this.validComplete();
|
|
4544
|
+
});
|
|
4545
|
+
break;
|
|
4546
|
+
}
|
|
4547
|
+
}
|
|
4548
|
+
});
|
|
4549
|
+
return this;
|
|
4550
|
+
}
|
|
4551
|
+
onComplete(val) {
|
|
4552
|
+
this._onCompleteHandler = val;
|
|
4553
|
+
return this;
|
|
4554
|
+
}
|
|
4555
|
+
onProgress(val) {
|
|
4556
|
+
this._onProgressHandler = val;
|
|
4557
|
+
return this;
|
|
4558
|
+
}
|
|
4559
|
+
isComplete() {
|
|
4560
|
+
return this._loaded == this._loaderList.length;
|
|
4561
|
+
}
|
|
4562
|
+
validComplete() {
|
|
4563
|
+
if (this._stop) {
|
|
4564
|
+
return;
|
|
4565
|
+
}
|
|
4566
|
+
if (this._onProgressHandler) {
|
|
4567
|
+
this._onProgressHandler(this);
|
|
4568
|
+
}
|
|
4569
|
+
if (this._loaded == this._loaderList.length) {
|
|
4570
|
+
if (this._onCompleteHandler) {
|
|
4571
|
+
this._onCompleteHandler(this);
|
|
4572
|
+
}
|
|
4573
|
+
this.dispatch("complete");
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
parseBundleToAssetsLoader(bundle, loaderItem) {
|
|
4577
|
+
let loader = new AssetLoader();
|
|
4578
|
+
// @ts-ignore
|
|
4579
|
+
let map = bundle._config.assetInfos._map;
|
|
4580
|
+
for (const mapKey in map) {
|
|
4581
|
+
let assetInfo = map[mapKey];
|
|
4582
|
+
if (!assetInfo.ctor) {
|
|
4583
|
+
continue;
|
|
4584
|
+
}
|
|
4585
|
+
switch (assetInfo.ctor.name) {
|
|
4586
|
+
case "ImageAsset":
|
|
4587
|
+
break;
|
|
4588
|
+
case "Prefab":
|
|
4589
|
+
break;
|
|
4590
|
+
case "SpriteFrame":
|
|
4591
|
+
loader._loadSpriteFrameByBundle(assetInfo.path, bundle);
|
|
4592
|
+
break;
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
return loader;
|
|
4596
|
+
}
|
|
4597
|
+
handleAtlas(item, atlasAsset) {
|
|
4598
|
+
let content = (() => {
|
|
4599
|
+
if (atlasAsset instanceof JsonAsset) {
|
|
4600
|
+
return atlasAsset.json;
|
|
4601
|
+
}
|
|
4602
|
+
else if (atlasAsset instanceof TextAsset) {
|
|
4603
|
+
return JSON.parse(atlasAsset.text);
|
|
4604
|
+
}
|
|
4605
|
+
else if (atlasAsset instanceof Asset) {
|
|
4606
|
+
return JSON.parse(atlasAsset.nativeAsset);
|
|
4607
|
+
}
|
|
4608
|
+
})();
|
|
4609
|
+
let textureUrl = "";
|
|
4610
|
+
let textureItem = new LoaderItem();
|
|
4611
|
+
switch (item.uri.loadType) {
|
|
4612
|
+
case 2:
|
|
4613
|
+
textureItem.type = "ImageAsset";
|
|
4614
|
+
textureUrl = path.join(path.dirname(item.uri.name), content.meta.image);
|
|
4615
|
+
break;
|
|
4616
|
+
case 1:
|
|
4617
|
+
textureItem.type = "ImageAsset";
|
|
4618
|
+
textureUrl = atlasAsset._nativeUrl;
|
|
4619
|
+
break;
|
|
4620
|
+
case 0:
|
|
4621
|
+
textureItem.type = "ImageAsset";
|
|
4622
|
+
textureUrl = item.uri.name;
|
|
4623
|
+
break;
|
|
4624
|
+
}
|
|
4625
|
+
textureItem.uri = new AssetURI$1(textureUrl);
|
|
4626
|
+
//
|
|
4627
|
+
this._loadByItem(textureItem, ImageAsset, (err, asset) => {
|
|
4628
|
+
if (!err) {
|
|
4629
|
+
let tex = new Texture2D();
|
|
4630
|
+
tex.image = asset;
|
|
4631
|
+
tex.setFilters(1, 1);
|
|
4632
|
+
let atlasSprite = parseAtlas$1(item.uri, content, tex);
|
|
4633
|
+
let uuid = atlasAsset.uuid;
|
|
4634
|
+
assetManager.assets.remove(uuid);
|
|
4635
|
+
assetManager.assets.add(uuid, atlasSprite);
|
|
4636
|
+
//
|
|
4637
|
+
item.callHandler(null, atlasSprite);
|
|
4638
|
+
}
|
|
4639
|
+
this._loaded++;
|
|
4640
|
+
this.validComplete();
|
|
4641
|
+
});
|
|
4642
|
+
}
|
|
4643
|
+
_loadByItem(item, type, onComplate) {
|
|
4644
|
+
switch (item.uri.loadType) {
|
|
4645
|
+
case 0: {
|
|
4646
|
+
let bundle = item.getBundle();
|
|
4647
|
+
if (!bundle) ;
|
|
4648
|
+
else {
|
|
4649
|
+
if (item.preload) {
|
|
4650
|
+
bundle.preload(item.uri.path, type, (err, asset) => {
|
|
4651
|
+
if (this._stop) {
|
|
4652
|
+
return;
|
|
4653
|
+
}
|
|
4654
|
+
this._handleFailList(err, item);
|
|
4655
|
+
onComplate(err, asset);
|
|
4656
|
+
});
|
|
4657
|
+
}
|
|
4658
|
+
else {
|
|
4659
|
+
bundle.load(item.uri.path, type, (err, asset) => {
|
|
4660
|
+
if (this._stop) {
|
|
4661
|
+
return;
|
|
4662
|
+
}
|
|
4663
|
+
this._handleFailList(err, item);
|
|
4664
|
+
onComplate(err, asset);
|
|
4665
|
+
});
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
break;
|
|
4669
|
+
}
|
|
4670
|
+
case 1: {
|
|
4671
|
+
if (item.preload) {
|
|
4672
|
+
assetManager.preloadAny({ uuid: item.uri.uuid }, { type: type }, (err, asset) => {
|
|
4673
|
+
if (this._stop) {
|
|
4674
|
+
return;
|
|
4675
|
+
}
|
|
4676
|
+
this._handleFailList(err, item);
|
|
4677
|
+
onComplate(err, asset);
|
|
4678
|
+
});
|
|
4679
|
+
}
|
|
4680
|
+
else {
|
|
4681
|
+
assetManager.loadAny({ uuid: item.uri.uuid }, { type: type }, (err, asset) => {
|
|
4682
|
+
if (this._stop) {
|
|
4683
|
+
return;
|
|
4684
|
+
}
|
|
4685
|
+
this._handleFailList(err, item);
|
|
4686
|
+
onComplate(err, asset);
|
|
4687
|
+
});
|
|
4688
|
+
}
|
|
4689
|
+
break;
|
|
4690
|
+
}
|
|
4691
|
+
case 2: {
|
|
4692
|
+
assetManager.loadRemote(item.uri.name, (err, asset) => {
|
|
4693
|
+
this._handleFailList(err, item);
|
|
4694
|
+
if (this._stop) {
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4697
|
+
onComplate(err, asset);
|
|
4698
|
+
});
|
|
4699
|
+
}
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
// 获取已经加载的数量,报错加载失败的
|
|
4703
|
+
getLoaded() {
|
|
4704
|
+
return this._loaded;
|
|
4705
|
+
}
|
|
4706
|
+
getTotle() {
|
|
4707
|
+
return this._loaderList.length;
|
|
4708
|
+
}
|
|
4709
|
+
// 获取成功的数量
|
|
4710
|
+
getSucceed() {
|
|
4711
|
+
return this._loaded - this.getFail();
|
|
4712
|
+
}
|
|
4713
|
+
// 获取失败的数量
|
|
4714
|
+
getFail() {
|
|
4715
|
+
return this._failList.length;
|
|
4716
|
+
}
|
|
4717
|
+
getFailList() {
|
|
4718
|
+
return this._failList;
|
|
4719
|
+
}
|
|
4720
|
+
_handleFailList(err, item) {
|
|
4721
|
+
if (err) {
|
|
4722
|
+
console.error(err.toString());
|
|
4723
|
+
item.error = err;
|
|
4724
|
+
this._failList.push(item);
|
|
4725
|
+
}
|
|
4726
|
+
}
|
|
4727
|
+
stop() {
|
|
4728
|
+
this._stop = true;
|
|
4729
|
+
}
|
|
4730
|
+
}
|
|
4731
|
+
|
|
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
|
+
|
|
4330
4837
|
class UIUtil {
|
|
4331
4838
|
/**
|
|
4332
4839
|
* 格式化节点的uuid,用于树结构
|
|
@@ -5491,5 +5998,5 @@ class PathUtil {
|
|
|
5491
5998
|
}
|
|
5492
5999
|
const pathutil = new PathUtil();
|
|
5493
6000
|
|
|
5494
|
-
export { ArrayUtil, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XEvent, arrayutil, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timeutil, uidict, uimgr, uiutil };
|
|
6001
|
+
export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, Controller, ControllerDict, ControllerSet, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, ErrorUtil, EventItem, EventManager, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LinkError, List, ListIterator, ListNode, ListSource, Listener, MapUtil, MathUtil, Model, Module, NetUtil, Page, PageController, PageEvent, PageLayer, PageList, PageRepo, PageState, PathUtil, Pool, RandUtil, Route, SamplePool, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, UIManager, UIObjectDict, UIPoolConfig, UISingleConfig, UIUtil, ViewController, XAssetManager, XEvent, arrayutil, assetx, bitutil, convertutil, ctrlrepo, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, maputil, mathutil, netutil, pagerepo, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timeutil, uidict, uimgr, uiutil };
|
|
5495
6002
|
//# sourceMappingURL=index.esm.js.map
|