olympus-r-17plugins
Version:
A plugin of Olympus for 17zuoye.
1,255 lines (1,254 loc) • 150 kB
JavaScript
var __reflect = (this && this.__reflect) || function (p, c, t) {
p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* @classic
* @private
*/
var AnalyzerBase = (function (_super) {
__extends(AnalyzerBase, _super);
function AnalyzerBase() {
var _this = _super.call(this) || this;
_this.resourceConfig = null;
_this.resourceConfig = (RES["configInstance"]);
return _this;
}
/**
* 添加一个二级键名到配置列表。
* @method RES.ResourceConfig#addSubkey
* @param subkey {string} 要添加的二级键名
* @param name {string} 二级键名所属的资源name属性
*/
AnalyzerBase.prototype.addSubkey = function (subkey, name) {
this.resourceConfig.addSubkey(subkey, name);
};
/**
* 加载一个资源文件
* @param resItem 加载项信息
* @param compFunc 加载完成回调函数,示例:compFunc(resItem:ResourceItem):void;
* @param thisObject 加载完成回调函数的this引用
*/
AnalyzerBase.prototype.loadFile = function (resItem, compFunc, thisObject) {
};
/**
* 同步方式获取解析完成的数据
* @param name 对应配置文件里的name属性。
*/
AnalyzerBase.prototype.getRes = function (name) {
};
/**
* 销毁某个资源文件的二进制数据,返回是否删除成功。
* @param name 配置文件中加载项的name属性
*/
AnalyzerBase.prototype.destroyRes = function (name) {
return false;
};
/**
* 读取一个字符串里第一个点之前的内容。
* @param name {string} 要读取的字符串
*/
AnalyzerBase.getStringPrefix = function (name) {
if (!name) {
return "";
}
var index = name.indexOf(".");
if (index != -1) {
return name.substring(0, index);
}
return "";
};
/**
* 读取一个字符串里第一个点之后的内容。
* @param name {string} 要读取的字符串
*/
AnalyzerBase.getStringTail = function (name) {
if (!name) {
return "";
}
var index = name.indexOf(".");
if (index != -1) {
return name.substring(index + 1);
}
return "";
};
return AnalyzerBase;
}(egret.HashObject));
RES.AnalyzerBase = AnalyzerBase;
__reflect(AnalyzerBase.prototype, "RES.AnalyzerBase");
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* @private
*/
var BinAnalyzer = (function (_super) {
__extends(BinAnalyzer, _super);
/**
* 构造函数
*/
function BinAnalyzer() {
var _this = _super.call(this) || this;
/**
* 字节流数据缓存字典
*/
_this.fileDic = {};
/**
* 加载项字典
*/
_this.resItemDic = [];
_this._dataFormat = egret.HttpResponseType.ARRAY_BUFFER;
/**
* Loader对象池
*/
_this.recycler = [];
return _this;
}
/**
* @inheritDoc
*/
BinAnalyzer.prototype.loadFile = function (resItem, compFunc, thisObject) {
if (this.fileDic[resItem.name]) {
compFunc.call(thisObject, resItem);
return;
}
var request = this.getRequest();
this.resItemDic[request.hashCode] = { item: resItem, func: compFunc, thisObject: thisObject };
request.open(RES.$getVirtualUrl(resItem.url));
request.send();
};
/**
* 获取一个URLLoader对象
*/
BinAnalyzer.prototype.getRequest = function () {
var request = this.recycler.pop();
if (!request) {
request = new egret.HttpRequest();
request.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
request.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
}
request.responseType = this._dataFormat;
return request;
};
/**
* 一项加载结束
*/
BinAnalyzer.prototype.onLoadFinish = function (event) {
var request = (event.target);
var data = this.resItemDic[request.hashCode];
delete this.resItemDic[request.hashCode];
var resItem = data.item;
var compFunc = data.func;
resItem.loaded = (event.type == egret.Event.COMPLETE);
if (resItem.loaded) {
this.analyzeData(resItem, request.response);
}
this.recycler.push(request);
compFunc.call(data.thisObject, resItem);
};
/**
* 解析并缓存加载成功的数据
*/
BinAnalyzer.prototype.analyzeData = function (resItem, data) {
var name = resItem.name;
if (this.fileDic[name] || (data != "" && !data)) {
return;
}
this.fileDic[name] = data;
};
/**
* @inheritDoc
*/
BinAnalyzer.prototype.getRes = function (name) {
return this.fileDic[name];
};
/**
* @inheritDoc
*/
BinAnalyzer.prototype.hasRes = function (name) {
var res = this.getRes(name);
return res != null;
};
/**
* @inheritDoc
*/
BinAnalyzer.prototype.destroyRes = function (name) {
if (this.fileDic[name]) {
this.onResourceDestroy(this.fileDic[name]);
delete this.fileDic[name];
return true;
}
return false;
};
BinAnalyzer.prototype.onResourceDestroy = function (resource) {
};
return BinAnalyzer;
}(RES.AnalyzerBase));
RES.BinAnalyzer = BinAnalyzer;
__reflect(BinAnalyzer.prototype, "RES.BinAnalyzer");
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* Resource term. One of the resources arrays in resource.json.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 资源项。对应 resource.json 中 resources 数组中的一项。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
var ResourceItem = (function () {
/**
* Constructor.
* @param name Name of resource term.
* @param url URL of resource term.
* @param type Type of resource term.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 构造函数。
* @param name 加载项名称。
* @param url 要加载的文件地址。
* @param type 加载项文件类型。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
function ResourceItem(name, url, type) {
/**
* Name of the resource term group.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 资源所属的组名。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
this.groupName = "";
/**
* The raw data object to be referenced.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 被引用的原始数据对象。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
this.data = null;
this._loaded = false;
this.name = name;
this.url = url;
this.type = type;
}
Object.defineProperty(ResourceItem.prototype, "loaded", {
/**
* Load complete flag.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 加载完成的标志。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
get: function () {
return this.data ? this.data.loaded : this._loaded;
},
set: function (value) {
if (this.data)
this.data.loaded = value;
this._loaded = value;
},
enumerable: true,
configurable: true
});
/**
* Turn into a string.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 转成字符串。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.prototype.toString = function () {
return "[ResourceItem name=\"" + this.name + "\" url=\"" + this.url + "\" type=\"" + this.type + "\"]";
};
/**
* XML file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* XML 文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_XML = "xml";
/**
* Picture file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 图片文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_IMAGE = "image";
/**
* Binary file.
* @version Egret 2.4
* @platform Web
* @language en_US
*/
/**
* 二进制文件。
* @version Egret 2.4
* @platform Web
* @language zh_CN
*/
ResourceItem.TYPE_BIN = "bin";
/**
* Text file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 文本文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_TEXT = "text";
/**
* JSON file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* JSON 文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_JSON = "json";
/**
* SpriteSheet file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* SpriteSheet 文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_SHEET = "sheet";
/**
* BitmapTextSpriteSheet file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* BitmapTextSpriteSheet 文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_FONT = "font";
/**
* Sound file.
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 声音文件。
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
ResourceItem.TYPE_SOUND = "sound";
return ResourceItem;
}());
RES.ResourceItem = ResourceItem;
__reflect(ResourceItem.prototype, "RES.ResourceItem");
})(RES || (RES = {}));
////////////////////////////////////////////////////////////////////////////////////////
////
//// Copyright (c) 2014-present, Egret Technology.
//// All rights reserved.
//// Redistribution and use in source and binary forms, with or without
//// modification, are permitted provided that the following conditions are met:
////
//// * Redistributions of source code must retain the above copyright
//// notice, this list of conditions and the following disclaimer.
//// * Redistributions in binary form must reproduce the above copyright
//// notice, this list of conditions and the following disclaimer in the
//// documentation and/or other materials provided with the distribution.
//// * Neither the name of the Egret nor the
//// names of its contributors may be used to endorse or promote products
//// derived from this software without specific prior written permission.
////
//// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////
////////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* SpriteSheet解析器
* @private
*/
var SheetAnalyzer = (function (_super) {
__extends(SheetAnalyzer, _super);
function SheetAnalyzer() {
var _this = _super.call(this) || this;
_this.sheetMap = {};
_this.textureMap = {};
/**
* ImageLoader对象池
*/
_this.recyclerIamge = [];
_this._dataFormat = egret.HttpResponseType.TEXT;
return _this;
}
SheetAnalyzer.prototype.getRes = function (name) {
var res = this.fileDic[name];
if (!res) {
res = this.textureMap[name];
}
if (!res) {
var prefix = RES.AnalyzerBase.getStringPrefix(name);
res = this.fileDic[prefix];
if (res) {
var tail = RES.AnalyzerBase.getStringTail(name);
res = res.getTexture(tail);
}
}
return res;
};
/**
* 一项加载结束
*/
SheetAnalyzer.prototype.onLoadFinish = function (event) {
var request = event.target;
var data = this.resItemDic[request.$hashCode];
delete this.resItemDic[request.hashCode];
var resItem = data.item;
var compFunc = data.func;
resItem.loaded = (event.type == egret.Event.COMPLETE);
if (resItem.loaded) {
if (request instanceof egret.HttpRequest) {
resItem.loaded = false;
var imageUrl = this.analyzeConfig(resItem, request.response);
if (imageUrl) {
this.loadImage(imageUrl, data);
this.recycler.push(request);
return;
}
}
else {
var texture = new egret.Texture();
texture._setBitmapData(request.data);
this.analyzeBitmap(resItem, texture);
}
}
if (request instanceof egret.HttpRequest) {
this.recycler.push(request);
}
else {
this.recyclerIamge.push(request);
}
compFunc.call(data.thisObject, resItem);
};
/**
* 解析并缓存加载成功的配置文件
*/
SheetAnalyzer.prototype.analyzeConfig = function (resItem, data) {
var name = resItem.name;
var config;
var imageUrl = "";
try {
var str = data;
config = JSON.parse(str);
}
catch (e) {
egret.$warn(1017, resItem.url, data);
}
if (config) {
this.sheetMap[name] = config;
imageUrl = this.getRelativePath(resItem.url, config["file"]);
}
return imageUrl;
};
/**
* 解析并缓存加载成功的位图数据
*/
SheetAnalyzer.prototype.analyzeBitmap = function (resItem, texture) {
var name = resItem.name;
if (this.fileDic[name] || !texture) {
return;
}
var config = this.sheetMap[name];
delete this.sheetMap[name];
var targetName = resItem.data && resItem.data.subkeys ? "" : name;
var spriteSheet = this.parseSpriteSheet(texture, config, targetName);
this.fileDic[name] = spriteSheet;
};
/**
* 获取相对位置
*/
SheetAnalyzer.prototype.getRelativePath = function (url, file) {
url = url.split("\\").join("/");
var params = url.match(/#.*|\?.*/);
var paramUrl = "";
if (params) {
paramUrl = params[0];
}
var index = url.lastIndexOf("/");
if (index != -1) {
url = url.substring(0, index + 1) + file;
}
else {
url = file;
}
return url + paramUrl;
};
SheetAnalyzer.prototype.parseSpriteSheet = function (texture, data, name) {
var frames = data.frames;
if (!frames) {
return null;
}
var spriteSheet = new egret.SpriteSheet(texture);
var textureMap = this.textureMap;
for (var subkey in frames) {
var config = frames[subkey];
var texture_1 = spriteSheet.createTexture(subkey, config.x, config.y, config.w, config.h, config.offX, config.offY, config.sourceW, config.sourceH);
if (config["scale9grid"]) {
var str = config["scale9grid"];
var list = str.split(",");
texture_1["scale9Grid"] = new egret.Rectangle(parseInt(list[0]), parseInt(list[1]), parseInt(list[2]), parseInt(list[3]));
}
if (textureMap[subkey] == null) {
textureMap[subkey] = texture_1;
if (name) {
this.addSubkey(subkey, name);
}
}
}
return spriteSheet;
};
SheetAnalyzer.prototype.destroyRes = function (name) {
var sheet = this.fileDic[name];
if (sheet) {
delete this.fileDic[name];
var texture = void 0;
for (var subkey in sheet._textureMap) {
if (texture == null) {
texture = sheet._textureMap[subkey];
this.onResourceDestroy(texture);
texture = null;
}
delete this.textureMap[subkey];
}
if (sheet.dispose) {
sheet.dispose();
}
return true;
}
return false;
};
SheetAnalyzer.prototype.loadImage = function (url, data) {
var loader = this.getImageLoader();
this.resItemDic[loader.hashCode] = data;
loader.load(RES.$getVirtualUrl(url));
};
SheetAnalyzer.prototype.getImageLoader = function () {
var loader = this.recyclerIamge.pop();
if (!loader) {
loader = new egret.ImageLoader();
loader.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
loader.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
}
return loader;
};
SheetAnalyzer.prototype.onResourceDestroy = function (texture) {
if (texture) {
texture.dispose();
}
};
return SheetAnalyzer;
}(RES.BinAnalyzer));
RES.SheetAnalyzer = SheetAnalyzer;
__reflect(SheetAnalyzer.prototype, "RES.SheetAnalyzer");
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* @private
*/
var ImageAnalyzer = (function (_super) {
__extends(ImageAnalyzer, _super);
/**
* 构造函数
*/
function ImageAnalyzer() {
var _this = _super.call(this) || this;
/**
* 字节流数据缓存字典
*/
_this.fileDic = {};
/**
* 加载项字典
*/
_this.resItemDic = [];
/**
* Loader对象池
*/
_this.recycler = [];
return _this;
}
/**
* @inheritDoc
*/
ImageAnalyzer.prototype.loadFile = function (resItem, compFunc, thisObject) {
if (this.fileDic[resItem.name]) {
compFunc.call(thisObject, resItem);
return;
}
var loader = this.getLoader();
this.resItemDic[loader.$hashCode] = { item: resItem, func: compFunc, thisObject: thisObject };
loader.load(RES.$getVirtualUrl(resItem.url));
};
/**
* 获取一个Loader对象
*/
ImageAnalyzer.prototype.getLoader = function () {
var loader = this.recycler.pop();
if (!loader) {
loader = new egret.ImageLoader();
loader.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
loader.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
}
return loader;
};
/**
* 一项加载结束
*/
ImageAnalyzer.prototype.onLoadFinish = function (event) {
var request = (event.$target);
var data = this.resItemDic[request.$hashCode];
delete this.resItemDic[request.$hashCode];
var resItem = data.item;
var compFunc = data.func;
resItem.loaded = (event.$type == egret.Event.COMPLETE);
if (resItem.loaded) {
var texture = new egret.Texture();
texture._setBitmapData(request.data);
this.analyzeData(resItem, texture);
}
this.recycler.push(request);
compFunc.call(data.thisObject, resItem);
};
/**
* 解析并缓存加载成功的数据
*/
ImageAnalyzer.prototype.analyzeData = function (resItem, texture) {
var name = resItem.name;
if (this.fileDic[name] || !texture) {
return;
}
this.fileDic[name] = texture;
var config = resItem.data;
if (config && config["scale9grid"]) {
var str = config["scale9grid"];
var list = str.split(",");
texture["scale9Grid"] = new egret.Rectangle(parseInt(list[0]), parseInt(list[1]), parseInt(list[2]), parseInt(list[3]));
}
};
/**
* @inheritDoc
*/
ImageAnalyzer.prototype.getRes = function (name) {
return this.fileDic[name];
};
/**
* @inheritDoc
*/
ImageAnalyzer.prototype.hasRes = function (name) {
var res = this.getRes(name);
return res != null;
};
/**
* @inheritDoc
*/
ImageAnalyzer.prototype.destroyRes = function (name) {
if (this.fileDic[name]) {
this.onResourceDestroy(this.fileDic[name]);
delete this.fileDic[name];
return true;
}
return false;
};
ImageAnalyzer.prototype.onResourceDestroy = function (texture) {
texture.dispose();
};
return ImageAnalyzer;
}(RES.AnalyzerBase));
RES.ImageAnalyzer = ImageAnalyzer;
__reflect(ImageAnalyzer.prototype, "RES.ImageAnalyzer");
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* @private
*/
var TextAnalyzer = (function (_super) {
__extends(TextAnalyzer, _super);
function TextAnalyzer() {
var _this = _super.call(this) || this;
_this._dataFormat = egret.HttpResponseType.TEXT;
return _this;
}
return TextAnalyzer;
}(RES.BinAnalyzer));
RES.TextAnalyzer = TextAnalyzer;
__reflect(TextAnalyzer.prototype, "RES.TextAnalyzer");
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* @private
*/
var JsonAnalyzer = (function (_super) {
__extends(JsonAnalyzer, _super);
function JsonAnalyzer() {
var _this = _super.call(this) || this;
_this._dataFormat = egret.HttpResponseType.TEXT;
return _this;
}
/**
* 解析并缓存加载成功的数据
*/
JsonAnalyzer.prototype.analyzeData = function (resItem, data) {
var name = resItem.name;
if (this.fileDic[name] || !data) {
return;
}
try {
var str = data;
this.fileDic[name] = JSON.parse(str);
}
catch (e) {
egret.$warn(1017, resItem.url, data);
}
};
return JsonAnalyzer;
}(RES.BinAnalyzer));
RES.JsonAnalyzer = JsonAnalyzer;
__reflect(JsonAnalyzer.prototype, "RES.JsonAnalyzer");
})(RES || (RES = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var RES;
(function (RES) {
/**
* @class RES.ResourceLoader
* @classdesc
* @extends egret.EventDispatcher
* @private
*/
var ResourceLoader = (function (_super) {
__extends(ResourceLoader, _super);
/**
* 构造函数
* @method RES.ResourceLoader#constructor
*/
function ResourceLoader() {
var _this = _super.call(this) || this;
/**
* 最大并发加载数
*/
_this.thread = 2;
/**
* 正在加载的线程计数
*/
_this.loadingCount = 0;
/**
* 一项加载结束回调函数。无论加载成功或者出错都将执行回调函数。示例:callBack(resItem:ResourceItem):void;
* @member {Function} RES.ResourceLoader#callBack
*/
_this.callBack = null;
/**
* RES单例的引用
* @member {any} RES.ResourceLoader#resInstance
*/
_this.resInstance = null;
/**
* 当前组加载的项总个数,key为groupName
*/
_this.groupTotalDic = {};
/**
* 已经加载的项个数,key为groupName
*/
_this.numLoadedDic = {};
/**
* 正在加载的组列表,key为groupName
*/
_this.itemListDic = {};
/**
* 加载失败的组,key为groupName
*/
_this.groupErrorDic = {};
_this.retryTimesDic = {};
_this.maxRetryTimes = 3;
_this.failedList = new Array();
/**
* 优先级队列,key为priority,value为groupName列表
*/
_this.priorityQueue = {};
/**
* 延迟加载队列
*/
_this.lazyLoadList = new Array();
/**
* 资源解析库字典类
*/
_this.analyzerDic = {};
/**
* 当前应该加载同优先级队列的第几列
*/
_this.queueIndex = 0;
return _this;
}
/**
* 检查指定的组是否正在加载中
* @method RES.ResourceLoader#isGroupInLoading
* @param groupName {string}
* @returns {boolean}
*/
ResourceLoader.prototype.isGroupInLoading = function (groupName) {
return this.itemListDic[groupName] !== undefined;
};
/**
* 开始加载一组文件
* @method RES.ResourceLoader#loadGroup
* @param list {egret.Array<ResourceItem>} 加载项列表
* @param groupName {string} 组名
* @param priority {number} 加载优先级
*/
ResourceLoader.prototype.loadGroup = function (list, groupName, priority) {
if (priority === void 0) { priority = 0; }
if (this.itemListDic[groupName] || !groupName)
return;
if (!list || list.length == 0) {
egret.$warn(3201, groupName);
var event_1 = new RES.ResourceEvent(RES.ResourceEvent.GROUP_LOAD_ERROR);
event_1.groupName = groupName;
this.dispatchEvent(event_1);
return;
}
if (this.priorityQueue[priority])
this.priorityQueue[priority].push(groupName);
else
this.priorityQueue[priority] = [groupName];
this.itemListDic[groupName] = list;
var length = list.length;
for (var i = 0; i < length; i++) {
var resItem = list[i];
resItem.groupName = groupName;
}
this.groupTotalDic[groupName] = list.length;
this.numLoadedDic[groupName] = 0;
this.next();
};
/**
* 加载一个文件
* @method RES.ResourceLoader#loadItem
* @param resItem {egret.ResourceItem} 要加载的项
*/
ResourceLoader.prototype.loadItem = function (resItem) {
this.lazyLoadList.push(resItem);
resItem.groupName = "";
this.next();
};
/**
* 加载下一项
*/
ResourceLoader.prototype.next = function () {
while (this.loadingCount < this.thread) {
var resItem = this.getOneResourceItem();
if (!resItem)
break;
this.loadingCount++;
if (resItem.loaded) {
this.onItemComplete(resItem);
}
else {
var analyzer = this.resInstance.$getAnalyzerByType(resItem.type);
analyzer.loadFile(resItem, this.onItemComplete, this);
}
}
};
/**
* 获取下一个待加载项
*/
ResourceLoader.prototype.getOneResourceItem = function () {
if (this.failedList.length > 0)
return this.failedList.shift();
var maxPriority = Number.NEGATIVE_INFINITY;
for (var p in this.priorityQueue) {
maxPriority = Math.max(maxPriority, p);
}
var queue = this.priorityQueue[maxPriority];
if (!queue || queue.length == 0) {
if (this.lazyLoadList.length == 0)
return null;
//后请求的先加载,以便更快获取当前需要的资源
return this.lazyLoadList.pop();
}
var length = queue.length;
var list;
for (var i = 0; i < length; i++) {
if (this.queueIndex >= length)
this.queueIndex = 0;
list = this.itemListDic[queue[this.queueIndex]];
if (list.length > 0)
break;
this.queueIndex++;
}
if (list.length == 0)
return null;
return list.shift();
};
/**
* 加载结束
*/
ResourceLoader.prototype.onItemComplete = function (resItem) {
this.loadingCount--;
var groupName = resItem.groupName;
if (!resItem.loaded) {
var times = this.retryTimesDic[resItem.name] || 1;
if (times > this.maxRetryTimes) {
delete this.retryTimesDic[resItem.name];
RES.ResourceEvent.dispatchResourceEvent(this.resInstance, RES.ResourceEvent.ITEM_LOAD_ERROR, groupName, resItem);
}
else {
this.retryTimesDic[resItem.name] = times + 1;
this.failedList.push(resItem);
this.next();
return;
}
}
if (groupName) {
this.numLoadedDic[groupName]++;
var itemsLoaded = this.numLoadedDic[groupName];
var itemsTotal = this.groupTotalDic[groupName];
if (!resItem.loaded) {
this.groupErrorDic[groupName] = true;
}
RES.ResourceEvent.dispatchResourceEvent(this.resInstance, RES.ResourceEvent.GROUP_PROGRESS, groupName, resItem, itemsLoaded, itemsTotal);
if (itemsLoaded == itemsTotal) {
var groupError = this.groupErrorDic[groupName];
this.removeGroupName(groupName);
delete this.groupTotalDic[groupName];
delete this.numLoadedDic[groupName];
delete this.itemListDic[groupName];
delete this.groupErrorDic[groupName];
if (groupError) {
RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.GROUP_LOAD_ERROR, groupName);
}
else {
RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.GROUP_COMPLETE, groupName);
}
}
}
else {
this.callBack.call(this.resInstance, resItem);
}
this.next();
};
/**
* 从优先级队列中移除指定的组名
*/
ResourceLoader.prototype.removeGroupName = function (groupName) {
for (var p in this.priorityQueue) {
var queue = this.priorityQueue[p];
var index = 0;
var found = false;
var length_1 = queue.length;
for (var i = 0; i < length_1; i++) {
var name_1 = queue[i];
if (name_1 == groupName) {
queue.splice(index, 1);