|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515 |
- 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 (d, b) {
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
- 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) {
- /**
- * @language en_US
- * Resource term. One of the resources arrays in resource.json.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 资源项。对应 resource.json 中 resources 数组中的一项。
- * @version Egret 2.4
- * @platform Web,Native
- */
- var ResourceItem = (function () {
- /**
- * @language en_US
- * 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 zh_CN
- * 构造函数。
- * @param name 加载项名称。
- * @param url 要加载的文件地址。
- * @param type 加载项文件类型。
- * @version Egret 2.4
- * @platform Web,Native
- */
- function ResourceItem(name, url, type) {
- /**
- * @language en_US
- * Name of the resource term group.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 资源所属的组名。
- * @version Egret 2.4
- * @platform Web,Native
- */
- this.groupName = "";
- /**
- * @language en_US
- * The raw data object to be referenced.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 被引用的原始数据对象。
- * @version Egret 2.4
- * @platform Web,Native
- */
- this.data = null;
- this._loaded = false;
- this.name = name;
- this.url = url;
- this.type = type;
- }
- Object.defineProperty(ResourceItem.prototype, "loaded", {
- /**
- * @language en_US
- * Load complete flag.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 加载完成的标志。
- * @version Egret 2.4
- * @platform Web,Native
- */
- 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
- });
- /**
- * @language en_US
- * Turn into a string.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 转成字符串。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.prototype.toString = function () {
- return "[ResourceItem name=\"" + this.name + "\" url=\"" + this.url + "\" type=\"" + this.type + "\"]";
- };
- return ResourceItem;
- }());
- /**
- * @language en_US
- * XML file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * XML 文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_XML = "xml";
- /**
- * @language en_US
- * Picture file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 图片文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_IMAGE = "image";
- /**
- * @language en_US
- * Binary file.
- * @version Egret 2.4
- * @platform Web
- */
- /**
- * @language zh_CN
- * 二进制文件。
- * @version Egret 2.4
- * @platform Web
- */
- ResourceItem.TYPE_BIN = "bin";
- /**
- * @language en_US
- * Text file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 文本文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_TEXT = "text";
- /**
- * @language en_US
- * JSON file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * JSON 文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_JSON = "json";
- /**
- * @language en_US
- * SpriteSheet file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * SpriteSheet 文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_SHEET = "sheet";
- /**
- * @language en_US
- * BitmapTextSpriteSheet file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * BitmapTextSpriteSheet 文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_FONT = "font";
- /**
- * @language en_US
- * Sound file.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 声音文件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceItem.TYPE_SOUND = "sound";
- 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) {
- /**
- * @language en_US
- * The events of resource loading.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 资源加载事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- var ResourceEvent = (function (_super) {
- __extends(ResourceEvent, _super);
- /**
- * @language en_US
- * Creates an Event object to pass as a parameter to event listeners.
- * @param type The type of the event, accessible as Event.type.
- * @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
- * @param cancelable Determines whether the Event object can be canceled. The default values is false.
- * @version Egret 2.4
- * @platform Web,Native
- * @private
- */
- /**
- * @language zh_CN
- * 创建一个作为参数传递给事件侦听器的 Event 对象。
- * @param type 事件的类型,可以作为 Event.type 访问。
- * @param bubbles 确定 Event 对象是否参与事件流的冒泡阶段。默认值为 false。
- * @param cancelable 确定是否可以取消 Event 对象。默认值为 false。
- * @version Egret 2.4
- * @platform Web,Native
- * @private
- */
- function ResourceEvent(type, bubbles, cancelable) {
- if (bubbles === void 0) { bubbles = false; }
- if (cancelable === void 0) { cancelable = false; }
- var _this = _super.call(this, type, bubbles, cancelable) || this;
- /**
- * @language en_US
- * File number that has been loaded.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 已经加载的文件数。
- * @version Egret 2.4
- * @platform Web,Native
- */
- _this.itemsLoaded = 0;
- /**
- * @language en_US
- * Total file number to load.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 要加载的总文件数。
- * @version Egret 2.4
- * @platform Web,Native
- */
- _this.itemsTotal = 0;
- /**
- * @language en_US
- * Resource group name.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 资源组名。
- * @version Egret 2.4
- * @platform Web,Native
- */
- _this.groupName = "";
- /**
- * @language en_US
- * An item of information that is finished by the end of a load.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 一次加载项加载结束的项信息对象。
- * @version Egret 2.4
- * @platform Web,Native
- */
- _this.resItem = null;
- return _this;
- }
- /**
- * 使用指定的EventDispatcher对象来抛出事件对象。抛出的对象将会缓存在对象池上,供下次循环复用。
- * @method RES.ResourceEvent.dispatchResourceEvent
- * @param target {egret.IEventDispatcher}
- * @param type {string}
- * @param groupName {string}
- * @param resItem {egret.ResourceItem}
- * @param itemsLoaded {number}
- * @param itemsTotal {number}
- * @private
- */
- ResourceEvent.dispatchResourceEvent = function (target, type, groupName, resItem, itemsLoaded, itemsTotal) {
- if (groupName === void 0) { groupName = ""; }
- if (resItem === void 0) { resItem = null; }
- if (itemsLoaded === void 0) { itemsLoaded = 0; }
- if (itemsTotal === void 0) { itemsTotal = 0; }
- var event = egret.Event.create(ResourceEvent, type);
- event.groupName = groupName;
- event.resItem = resItem;
- event.itemsLoaded = itemsLoaded;
- event.itemsTotal = itemsTotal;
- var result = target.dispatchEvent(event);
- egret.Event.release(event);
- return result;
- };
- return ResourceEvent;
- }(egret.Event));
- /**
- * @language en_US
- * Failure event for a load item.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 一个加载项加载失败事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceEvent.ITEM_LOAD_ERROR = "itemLoadError";
- /**
- * @language en_US
- * Configure file to load and parse the completion event. Note: if a configuration file is loaded, it will not be thrown out, and if you want to handle the configuration loading failure, monitor the CONFIG_LOAD_ERROR event.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 配置文件加载并解析完成事件。注意:若有配置文件加载失败,将不会抛出此事件,若要处理配置加载失败,请同时监听 CONFIG_LOAD_ERROR 事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceEvent.CONFIG_COMPLETE = "configComplete";
- /**
- * @language en_US
- * Configuration file failed to load.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 配置文件加载失败事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceEvent.CONFIG_LOAD_ERROR = "configLoadError";
- /**
- * @language en_US
- * Delay load group resource loading progress event.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 延迟加载组资源加载进度事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceEvent.GROUP_PROGRESS = "groupProgress";
- /**
- * @language en_US
- * Delay load group resource to complete event. Note: if you have a resource item loading failure, the event will not be thrown, if you want to handle the group load failure, please listen to the GROUP_LOAD_ERROR event.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 延迟加载组资源加载完成事件。注意:若组内有资源项加载失败,将不会抛出此事件,若要处理组加载失败,请同时监听 GROUP_LOAD_ERROR 事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceEvent.GROUP_COMPLETE = "groupComplete";
- /**
- * @language en_US
- * Delayed load group resource failed event.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 延迟加载组资源加载失败事件。
- * @version Egret 2.4
- * @platform Web,Native
- */
- ResourceEvent.GROUP_LOAD_ERROR = "groupLoadError";
- RES.ResourceEvent = ResourceEvent;
- __reflect(ResourceEvent.prototype, "RES.ResourceEvent");
- })(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);
- found = true;
- break;
- }
- index++;
- }
- if (found) {
- if (queue.length == 0) {
- delete this.priorityQueue[p];
- }
- break;
- }
- }
- };
- return ResourceLoader;
- }(egret.EventDispatcher));
- RES.ResourceLoader = ResourceLoader;
- __reflect(ResourceLoader.prototype, "RES.ResourceLoader");
- })(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 FontAnalyzer = (function (_super) {
- __extends(FontAnalyzer, _super);
- function FontAnalyzer() {
- return _super.call(this) || this;
- }
- FontAnalyzer.prototype.analyzeConfig = function (resItem, data) {
- var name = resItem.name;
- var config;
- var imageUrl = "";
- try {
- var str = data;
- config = JSON.parse(str);
- }
- catch (e) {
- }
- if (config) {
- imageUrl = this.getRelativePath(resItem.url, config["file"]);
- }
- else {
- config = data;
- imageUrl = this.getTexturePath(resItem.url, config);
- }
- this.sheetMap[name] = config;
- return imageUrl;
- };
- FontAnalyzer.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 bitmapFont = new egret.BitmapFont(texture, config);
- this.fileDic[name] = bitmapFont;
- };
- FontAnalyzer.prototype.getTexturePath = function (url, fntText) {
- var file = "";
- var lines = fntText.split("\n");
- var pngLine = lines[2];
- var index = pngLine.indexOf("file=\"");
- if (index != -1) {
- pngLine = pngLine.substring(index + 6);
- index = pngLine.indexOf("\"");
- file = pngLine.substring(0, index);
- }
- url = url.split("\\").join("/");
- index = url.lastIndexOf("/");
- if (index != -1) {
- url = url.substring(0, index + 1) + file;
- }
- else {
- url = file;
- }
- return url;
- };
- FontAnalyzer.prototype.onResourceDestroy = function (font) {
- if (font) {
- font.dispose();
- }
- };
- return FontAnalyzer;
- }(RES.SheetAnalyzer));
- RES.FontAnalyzer = FontAnalyzer;
- __reflect(FontAnalyzer.prototype, "RES.FontAnalyzer");
- })(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 SoundAnalyzer = (function (_super) {
- __extends(SoundAnalyzer, _super);
- /**
- * 构造函数
- */
- function SoundAnalyzer() {
- var _this = _super.call(this) || this;
- /**
- * 字节流数据缓存字典
- */
- _this.soundDic = {};
- /**
- * 加载项字典
- */
- _this.resItemDic = [];
- return _this;
- }
- /**
- * @inheritDoc
- */
- SoundAnalyzer.prototype.loadFile = function (resItem, callBack, thisObject) {
- if (this.soundDic[resItem.name]) {
- callBack.call(thisObject, resItem);
- return;
- }
- var sound = new egret.Sound();
- sound.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
- sound.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
- this.resItemDic[sound.$hashCode] = { item: resItem, func: callBack, thisObject: thisObject };
- sound.load(RES.$getVirtualUrl(resItem.url));
- if (resItem.data) {
- sound.type = resItem.data.soundType;
- }
- };
- /**
- * 一项加载结束
- */
- SoundAnalyzer.prototype.onLoadFinish = function (event) {
- var sound = (event.$target);
- sound.removeEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
- sound.removeEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
- var data = this.resItemDic[sound.$hashCode];
- delete this.resItemDic[sound.$hashCode];
- var resItem = data.item;
- var compFunc = data.func;
- resItem.loaded = (event.$type == egret.Event.COMPLETE);
- if (resItem.loaded) {
- this.analyzeData(resItem, sound);
- }
- compFunc.call(data.thisObject, resItem);
- };
- /**
- * 解析并缓存加载成功的数据
- */
- SoundAnalyzer.prototype.analyzeData = function (resItem, data) {
- var name = resItem.name;
- if (this.soundDic[name] || !data) {
- return;
- }
- this.soundDic[name] = data;
- };
- /**
- * @inheritDoc
- */
- SoundAnalyzer.prototype.getRes = function (name) {
- return this.soundDic[name];
- };
- /**
- * @inheritDoc
- */
- SoundAnalyzer.prototype.hasRes = function (name) {
- return !!this.getRes(name);
- };
- /**
- * @inheritDoc
- */
- SoundAnalyzer.prototype.destroyRes = function (name) {
- if (this.soundDic[name]) {
- delete this.soundDic[name];
- return true;
- }
- return false;
- };
- return SoundAnalyzer;
- }(RES.AnalyzerBase));
- RES.SoundAnalyzer = SoundAnalyzer;
- __reflect(SoundAnalyzer.prototype, "RES.SoundAnalyzer");
- })(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 XMLAnalyzer = (function (_super) {
- __extends(XMLAnalyzer, _super);
- function XMLAnalyzer() {
- var _this = _super.call(this) || this;
- _this._dataFormat = egret.HttpResponseType.TEXT;
- return _this;
- }
- /**
- * 解析并缓存加载成功的数据
- */
- XMLAnalyzer.prototype.analyzeData = function (resItem, data) {
- var name = resItem.name;
- if (this.fileDic[name] || !data) {
- return;
- }
- try {
- var xmlStr = data;
- var xml = egret.XML.parse(xmlStr);
- this.fileDic[name] = xml;
- }
- catch (e) {
- }
- };
- return XMLAnalyzer;
- }(RES.BinAnalyzer));
- RES.XMLAnalyzer = XMLAnalyzer;
- __reflect(XMLAnalyzer.prototype, "RES.XMLAnalyzer");
- })(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) {
- /**
- * @class RES.ResourceConfig
- * @classdesc
- * @private
- */
- var ResourceConfig = (function () {
- function ResourceConfig() {
- /**
- * 一级键名字典
- */
- this.keyMap = {};
- /**
- * 加载组字典
- */
- this.groupDic = {};
- RES["configInstance"] = this;
- }
- /**
- * 根据组名获取组加载项列表
- * @method RES.ResourceConfig#getGroupByName
- * @param name {string} 组名
- * @returns {Array<egret.ResourceItem>}
- */
- ResourceConfig.prototype.getGroupByName = function (name) {
- var group = new Array();
- if (!this.groupDic[name])
- return group;
- var list = this.groupDic[name];
- var length = list.length;
- for (var i = 0; i < length; i++) {
- var obj = list[i];
- group.push(this.parseResourceItem(obj));
- }
- return group;
- };
- /**
- * 根据组名获取原始的组加载项列表
- * @method RES.ResourceConfig#getRawGroupByName
- * @param name {string} 组名
- * @returns {any[]}
- */
- ResourceConfig.prototype.getRawGroupByName = function (name) {
- if (this.groupDic[name])
- return this.groupDic[name];
- return [];
- };
- /**
- * 创建自定义的加载资源组,注意:此方法仅在资源配置文件加载完成后执行才有效。
- * 可以监听ResourceEvent.CONFIG_COMPLETE事件来确认配置加载完成。
- * @method RES.ResourceConfig#createGroup
- * @param name {string} 要创建的加载资源组的组名
- * @param keys {egret.string[]} 要包含的键名列表,key对应配置文件里的name属性或sbuKeys属性的一项或一个资源组名。
- * @param override {boolean} 是否覆盖已经存在的同名资源组,默认false。
- * @returns {boolean}
- */
- ResourceConfig.prototype.createGroup = function (name, keys, override) {
- if (override === void 0) { override = false; }
- if ((!override && this.groupDic[name]) || !keys || keys.length == 0)
- return false;
- var groupDic = this.groupDic;
- var group = [];
- var length = keys.length;
- for (var i = 0; i < length; i++) {
- var key = keys[i];
- var g = groupDic[key];
- if (g) {
- var len = g.length;
- for (var j = 0; j < len; j++) {
- var item = g[j];
- if (group.indexOf(item) == -1)
- group.push(item);
- }
- }
- else {
- var item = this.keyMap[key];
- if (item) {
- if (group.indexOf(item) == -1)
- group.push(item);
- }
- else {
- egret.$warn(3200, key);
- }
- }
- }
- if (group.length == 0)
- return false;
- this.groupDic[name] = group;
- return true;
- };
- /**
- * 解析一个配置文件
- * @method RES.ResourceConfig#parseConfig
- * @param data {any} 配置文件数据
- * @param folder {string} 加载项的路径前缀。
- */
- ResourceConfig.prototype.parseConfig = function (data, folder) {
- if (!data)
- return;
- var resources = data["resources"];
- if (resources) {
- var length_2 = resources.length;
- for (var i = 0; i < length_2; i++) {
- var item = resources[i];
- var url = item.url;
- if (url && url.indexOf("://") == -1)
- item.url = folder + url;
- this.addItemToKeyMap(item);
- }
- }
- var groups = data["groups"];
- if (groups) {
- var length_3 = groups.length;
- for (var i = 0; i < length_3; i++) {
- var group = groups[i];
- var list = [];
- var keys = group.keys.split(",");
- var l = keys.length;
- for (var j = 0; j < l; j++) {
- var name_2 = keys[j].trim();
- var item = this.keyMap[name_2];
- if (item && list.indexOf(item) == -1) {
- list.push(item);
- }
- }
- this.groupDic[group.name] = list;
- }
- }
- };
- /**
- * 添加一个二级键名到配置列表。
- * @method RES.ResourceConfig#addSubkey
- * @param subkey {string} 要添加的二级键名
- * @param name {string} 二级键名所属的资源name属性
- */
- ResourceConfig.prototype.addSubkey = function (subkey, name) {
- var item = this.keyMap[name];
- if (item && !this.keyMap[subkey]) {
- this.keyMap[subkey] = item;
- }
- };
- /**
- * 添加一个加载项数据到列表
- */
- ResourceConfig.prototype.addItemToKeyMap = function (item) {
- if (!this.keyMap[item.name])
- this.keyMap[item.name] = item;
- if (item.hasOwnProperty("subkeys")) {
- var subkeys = (item.subkeys).split(",");
- item.subkeys = subkeys;
- var length_4 = subkeys.length;
- for (var i = 0; i < length_4; i++) {
- var key = subkeys[i];
- if (this.keyMap[key] != null)
- continue;
- this.keyMap[key] = item;
- }
- }
- };
- /**
- * 获取加载项的name属性
- * @method RES.ResourceConfig#getType
- * @param key {string} 对应配置文件里的name属性或sbuKeys属性的一项。
- * @returns {string}
- */
- ResourceConfig.prototype.getName = function (key) {
- var data = this.keyMap[key];
- return data ? data.name : "";
- };
- /**
- * 获取加载项类型。
- * @method RES.ResourceConfig#getType
- * @param key {string} 对应配置文件里的name属性或sbuKeys属性的一项。
- * @returns {string}
- */
- ResourceConfig.prototype.getType = function (key) {
- var data = this.keyMap[key];
- return data ? data.type : "";
- };
- ResourceConfig.prototype.getRawResourceItem = function (key) {
- return this.keyMap[key];
- };
- /**
- * 获取加载项信息对象
- * @method RES.ResourceConfig#getResourceItem
- * @param key {string} 对应配置文件里的key属性或sbuKeys属性的一项。
- * @returns {egret.ResourceItem}
- */
- ResourceConfig.prototype.getResourceItem = function (key) {
- var data = this.keyMap[key];
- if (data)
- return this.parseResourceItem(data);
- return null;
- };
- /**
- * 转换Object数据为ResourceItem对象
- */
- ResourceConfig.prototype.parseResourceItem = function (data) {
- var resItem = new RES.ResourceItem(data.name, data.url, data.type);
- resItem.data = data;
- return resItem;
- };
- return ResourceConfig;
- }());
- RES.ResourceConfig = ResourceConfig;
- __reflect(ResourceConfig.prototype, "RES.ResourceConfig");
- })(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) {
- var native;
- (function (native) {
- /**
- * @private
- */
- var NativeVersionController = (function () {
- function NativeVersionController() {
- this._versionInfo = {};
- this._versionPath = "";
- this._localFileArr = [];
- }
- NativeVersionController.prototype.fetchVersion = function (callback) {
- if (true) {
- callback.onSuccess(null);
- return;
- }
- var self = this;
- self._versionPath = "all.manifest";
- self._versionInfo = self.getLocalData(self._versionPath);
- if (self._versionInfo == null) {
- egret.callLater(function () {
- callback.onFail(1, null);
- }, self);
- return;
- }
- var count = 0;
- var loadOver = function (paths) {
- if (paths) {
- for (var i = 0; i < paths.length; i++) {
- if (paths[i] && paths[i] != "") {
- self._localFileArr.push("resource/" + paths[i]);
- }
- }
- }
- count++;
- if (count == 2) {
- callback.onSuccess(null);
- }
- };
- self.getList(loadOver, "assets", "resource");
- self.getList(loadOver, "update", "resource");
- };
- NativeVersionController.prototype.getList = function (callback, type, root) {
- if (root === void 0) { root = ""; }
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = function (paths) {
- callback(paths);
- };
- promise.onErrorFunc = function () {
- console.error("list files error");
- };
- if (type == "assets") {
- egret_native.Game.listResource(root, promise);
- }
- else {
- egret_native.Game.listUpdate(root, promise);
- }
- };
- /**
- * 获取所有有变化的文件
- * @returns {any[]}
- */
- NativeVersionController.prototype.getChangeList = function () {
- var temp = [];
- var localFileArr = this._localFileArr;
- for (var key in this._versionInfo) {
- if (localFileArr.indexOf(this.getVirtualUrl(key)) < 0) {
- temp.push({ "url": this.getVirtualUrl(key), "size": this._versionInfo[key]["s"] });
- }
- }
- return temp;
- };
- NativeVersionController.prototype.getVirtualUrl = function (url) {
- if (true) {
- return url;
- }
- if (this._versionInfo && this._versionInfo[url]) {
- return "resource/" + this._versionInfo[url]["v"].substring(0, 2) + "/" + this._versionInfo[url]["v"] + "_" + this._versionInfo[url]["s"] + "." + url.substring(url.lastIndexOf(".") + 1);
- }
- else {
- return url;
- }
- };
- NativeVersionController.prototype.getLocalData = function (filePath) {
- if (egret_native.readUpdateFileSync && egret_native.readResourceFileSync) {
- //先取更新目录
- var content = egret_native.readUpdateFileSync(filePath);
- if (content != null) {
- return JSON.parse(content);
- }
- //再取资源目录
- content = egret_native.readResourceFileSync(filePath);
- if (content != null) {
- return JSON.parse(content);
- }
- }
- return null;
- };
- return NativeVersionController;
- }());
- native.NativeVersionController = NativeVersionController;
- __reflect(NativeVersionController.prototype, "RES.native.NativeVersionController", ["RES.VersionController", "RES.IVersionController"]);
- if (egret.Capabilities.runtimeType == egret.RuntimeType.NATIVE) {
- RES.VersionController = NativeVersionController;
- }
- })(native = RES.native || (RES.native = {}));
- })(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) {
- var web;
- (function (web) {
- /**
- * @private
- */
- var Html5VersionController = (function (_super) {
- __extends(Html5VersionController, _super);
- function Html5VersionController() {
- var _this = _super.call(this) || this;
- _this._versionInfo = {};
- return _this;
- }
- Html5VersionController.prototype.fetchVersion = function (callback) {
- callback.onSuccess(null);
- return;
- /*
-
- todo
-
- let self = this;
-
- let virtualUrl:string = "all.manifest";
-
- let httpLoader:egret.HttpRequest = new egret.HttpRequest();
- httpLoader.addEventListener(egret.Event.COMPLETE, onLoadComplete, this);
- httpLoader.addEventListener(egret.IOErrorEvent.IO_ERROR, onError, this);
-
- httpLoader.open(virtualUrl + "?r=" + Date.now(), "get");
- httpLoader.send();
-
- function onError(event:egret.IOErrorEvent) {
- removeListeners();
- self.dispatchEvent(event);
- }
-
- function onLoadComplete() {
- removeListeners();
-
- self._versionInfo = JSON.parse(httpLoader.response);
-
- window.setTimeout(function () {
- self.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
- }, 0);
- }
-
- function removeListeners():void {
- httpLoader.removeEventListener(egret.Event.COMPLETE, onLoadComplete, self);
- httpLoader.removeEventListener(egret.IOErrorEvent.IO_ERROR, onError, self);
- }
-
- */
- };
- /**
- * 获取所有有变化的文件
- * @returns {any[]}
- */
- Html5VersionController.prototype.getChangeList = function () {
- return [];
- };
- Html5VersionController.prototype.getVirtualUrl = function (url) {
- return url;
- /*
-
- todo
-
- if (DEBUG) {
- return url;
- }
- if (this._versionInfo && this._versionInfo[url]) {
- return "resource/" + this._versionInfo[url]["v"].substring(0, 2) + "/" + this._versionInfo[url]["v"] + "_" + this._versionInfo[url]["s"] + "." + url.substring(url.lastIndexOf(".") + 1);
- }
- else {
- return url;
- }
-
- */
- };
- return Html5VersionController;
- }(egret.EventDispatcher));
- web.Html5VersionController = Html5VersionController;
- __reflect(Html5VersionController.prototype, "RES.web.Html5VersionController", ["RES.VersionController", "RES.IVersionController"]);
- if (egret.Capabilities.runtimeType == egret.RuntimeType.WEB) {
- RES.VersionController = Html5VersionController;
- }
- })(web = RES.web || (RES.web = {}));
- })(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.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- /// <reference path="core/ResourceItem.ts" />
- /// <reference path="core/ResourceConfig.ts" />
- /// <reference path="core/ResourceLoader.ts" />
- /// <reference path="events/ResourceEvent.ts" />
- /// <reference path="analyzer/BinAnalyzer.ts" />
- /// <reference path="analyzer/ImageAnalyzer.ts" />
- /// <reference path="analyzer/TextAnalyzer.ts" />
- /// <reference path="analyzer/JsonAnalyzer.ts" />
- /// <reference path="analyzer/SheetAnalyzer.ts" />
- /// <reference path="analyzer/FontAnalyzer.ts" />
- /// <reference path="analyzer/SoundAnalyzer.ts" />
- /// <reference path="analyzer/XMLAnalyzer.ts" />
- /// <reference path="version/IVersionController.ts" />
- /// <reference path="version/HTML5VersionController.ts" />
- /// <reference path="version/NativeVersionController.ts" />
- var RES;
- (function (RES) {
- /**
- * @language en_US
- * Conduct mapping injection with class definition as the value.
- * @param type Injection type.
- * @param analyzerClass Injection type classes need to be resolved.
- * @version Egret 2.4
- * @platform Web,Native
- * @includeExample extension/resource/Resource.ts
- */
- /**
- * @language zh_CN
- * 以类定义为值进行映射注入。
- * @param type 注入的类型。
- * @param analyzerClass 注入类型需要解析的类。
- * @version Egret 2.4
- * @platform Web,Native
- * @includeExample extension/resource/Resource.ts
- */
- function registerAnalyzer(type, analyzerClass) {
- instance.registerAnalyzer(type, analyzerClass);
- }
- RES.registerAnalyzer = registerAnalyzer;
- /**
- * @language en_US
- * Get mapping injection.
- * @param type Injection type.
- * @version Egret 3.2.6
- * @platform Web,Native
- * @includeExample extension/resource/Resource.ts
- */
- /**
- * @language zh_CN
- * 获取映射注入。
- * @param type 注入的类型。
- * @version Egret 3.2.6
- * @platform Web,Native
- * @includeExample extension/resource/Resource.ts
- */
- function getAnalyzer(type) {
- return instance.$getAnalyzerByType(type);
- }
- RES.getAnalyzer = getAnalyzer;
- /**
- * @language en_US
- * Register the VersionController
- * @param vcs The VersionController to register.
- * @version Egret 2.5
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 注册版本控制器,通过RES模块加载资源时会从版本控制器获取真实url
- * @param vcs 注入的版本控制器。
- * @version Egret 2.5
- * @platform Web,Native
- */
- function registerVersionController(vcs) {
- instance.$registerVersionController(vcs);
- }
- RES.registerVersionController = registerVersionController;
- /**
- * @language en_US
- * Returns the VersionController
- * @version Egret 2.5
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 获得版本控制器.
- * @version Egret 2.5
- * @platform Web,Native
- */
- function getVersionController() {
- return instance.vcs;
- }
- RES.getVersionController = getVersionController;
- /**
- * @language en_US
- * Load configuration file and parse.
- * @param url Configuration file path (path resource.json).
- * @param resourceRoot Resource path. All URL in the configuration is the relative value of the path. The ultimate URL is the value of the sum of the URL of the string and the resource in the configuration.
- * @param type Configuration file format. Determine what parser to parse the configuration file. Default "json".
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 加载配置文件并解析。
- * @param url 配置文件路径(resource.json的路径)。
- * @param resourceRoot 资源根路径。配置中的所有url都是这个路径的相对值。最终url是这个字符串与配置里资源项的url相加的值。
- * @param type 配置文件的格式。确定要用什么解析器来解析配置文件。默认"json"
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function loadConfig(url, resourceRoot, type) {
- if (resourceRoot === void 0) { resourceRoot = ""; }
- if (type === void 0) { type = "json"; }
- instance.loadConfig(url, resourceRoot, type);
- }
- RES.loadConfig = loadConfig;
- /**
- * @language en_US
- * Load a set of resources according to the group name.
- * @param name Group name to load the resource group.
- * @param priority Load priority can be negative, the default value is 0.
- * <br>A low priority group must wait for the high priority group to complete the end of the load to start, and the same priority group will be loaded at the same time.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 根据组名加载一组资源。
- * @param name 要加载资源组的组名。
- * @param priority 加载优先级,可以为负数,默认值为 0。
- * <br>低优先级的组必须等待高优先级组完全加载结束才能开始,同一优先级的组会同时加载。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function loadGroup(name, priority) {
- if (priority === void 0) { priority = 0; }
- instance.loadGroup(name, priority);
- }
- RES.loadGroup = loadGroup;
- /**
- * @language en_US
- * Check whether a resource group has been loaded.
- * @param name Group name。
- * @returns Is loading or not.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 检查某个资源组是否已经加载完成。
- * @param name 组名。
- * @returns 是否正在加载。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function isGroupLoaded(name) {
- return instance.isGroupLoaded(name);
- }
- RES.isGroupLoaded = isGroupLoaded;
- /**
- * @language en_US
- * A list of groups of loading is obtained according to the group name.
- * @param name Group name.
- * @returns The resource item array of group.
- * @see RES.ResourceItem
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 根据组名获取组加载项列表。
- * @param name 组名。
- * @returns 加载项列表。
- * @see RES.ResourceItem
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function getGroupByName(name) {
- return instance.getGroupByName(name);
- }
- RES.getGroupByName = getGroupByName;
- /**
- * @language en_US
- * Create a custom load resource group, note that this method is valid only after the resource configuration file is loaded.
- * <br>You can monitor the ResourceEvent.CONFIG_COMPLETE event to verify that the configuration is complete.
- * @param name Group name to create the load resource group.
- * @param keys To be included in the list of key keys, the corresponding configuration file in the name or sbuKeys property one or a resource group name.
- * @param override Is the default false for the same name resource group already exists.
- * @returns Create success or fail.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 创建自定义的加载资源组,注意:此方法仅在资源配置文件加载完成后执行才有效。
- * <br>可以监听 ResourceEvent.CONFIG_COMPLETE 事件来确认配置加载完成。
- * @param name 要创建的加载资源组的组名。
- * @param keys 要包含的键名列表,key 对应配置文件里的 name 属性或 sbuKeys 属性的一项或一个资源组名。
- * @param override 是否覆盖已经存在的同名资源组,默认 false。
- * @returns 是否创建成功。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function createGroup(name, keys, override) {
- if (override === void 0) { override = false; }
- return instance.createGroup(name, keys, override);
- }
- RES.createGroup = createGroup;
- /**
- * @language en_US
- * Check whether the configuration file contains the specified resources.
- * @param key A sbuKeys attribute or name property in a configuration file.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 检查配置文件里是否含有指定的资源。
- * @param key 对应配置文件里的 name 属性或 sbuKeys 属性的一项。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function hasRes(key) {
- return instance.hasRes(key);
- }
- RES.hasRes = hasRes;
- /**
- * @language en_US
- * parse a configuration file at run time,it will not clean the exist data.
- * @param data Configuration file data, please refer to the resource.json configuration file format. JSON object can be introduced into the corresponding.
- * @param folder Path prefix for load.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 运行时动态解析一个配置文件,此操作不会清空之前已存在的配置。
- * @param data 配置文件数据,请参考 resource.json 的配置文件格式。传入对应的 json 对象即可。
- * @param folder 加载项的路径前缀。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function parseConfig(data, folder) {
- if (folder === void 0) { folder = ""; }
- instance.parseConfig(data, folder);
- }
- RES.parseConfig = parseConfig;
- /**
- * @language en_US
- * The synchronization method for obtaining the cache has been loaded with the success of the resource.
- * <br>The type of resource and the corresponding return value types are as follows:
- * <br>RES.ResourceItem.TYPE_BIN : ArrayBuffer JavaScript primary object
- * <br>RES.ResourceItem.TYPE_IMAGE : img Html Object,or egret.BitmapData interface。
- * <br>RES.ResourceItem.TYPE_JSON : Object
- * <br>RES.ResourceItem.TYPE_SHEET : Object
- * <br> 1. If the incoming parameter is the name of the entire SpriteSheet is returned is {image1: Texture, "image2": Texture}.
- * <br> 2. If the incoming is "sheet.image1", the return is a single resource.
- * <br> 3. If the incoming is the name of the "image1" single resource, the return is a single resource.
- * But if there are two SpriteSheet in a single picture of the same name, the return of the image after the load.
- * <br>RES.ResourceItem.TYPE_SOUND : HtmlSound Html Object
- * <br>RES.ResourceItem.TYPE_TEXT : string
- * @param key A subKeys attribute or name property in a configuration file.
- * @see RES.ResourceItem
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 同步方式获取缓存的已经加载成功的资源。
- * <br>资源类型和对应的返回值类型关系如下:
- * <br>RES.ResourceItem.TYPE_BIN : ArrayBuffer JavaScript 原生对象
- * <br>RES.ResourceItem.TYPE_IMAGE : img Html 对象,或者 egret.BitmapData 接口。
- * <br>RES.ResourceItem.TYPE_JSON : Object
- * <br>RES.ResourceItem.TYPE_SHEET : Object
- * <br> 1. 如果传入的参数是整个 SpriteSheet 的名称返回的是 {"image1":Texture,"image2":Texture} 这样的格式。
- * <br> 2. 如果传入的是 "sheet.image1",返回的是单个资源。
- * <br> 3. 如果传入的是 "image1" 单个资源的名称,返回的是单个资源。但是如果有两张 SpriteSheet 中有单个图片资源名称相同,返回的是后加载的那个图片资源。
- * <br>RES.ResourceItem.TYPE_SOUND : HtmlSound Html 对象
- * <br>RES.ResourceItem.TYPE_TEXT : string
- * @param key 对应配置文件里的 name 属性或 subKeys 属性的一项。
- * @see RES.ResourceItem
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function getRes(key) {
- return instance.getRes(key);
- }
- RES.getRes = getRes;
- /**
- * @language en_US
- * Asynchronous mode to get the resources in the configuration. As long as the resources exist in the configuration file, you can get it in an asynchronous way.
- * @param key A sbuKeys attribute or name property in a configuration file.
- * @param compFunc Call back function. Example:compFunc(data,key):void.
- * @param thisObject This pointer of call back function.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 异步方式获取配置里的资源。只要是配置文件里存在的资源,都可以通过异步方式获取。
- * @param key 对应配置文件里的 name 属性或 sbuKeys 属性的一项。
- * @param compFunc 回调函数。示例:compFunc(data,key):void。
- * @param thisObject 回调函数的 this 引用。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function getResAsync(key, compFunc, thisObject) {
- instance.getResAsync(key, compFunc, thisObject);
- }
- RES.getResAsync = getResAsync;
- /**
- * @language en_US
- * Access to external resources through the full URL.
- * @param url The external path to load the file.
- * @param compFunc Call back function. Example:compFunc(data,url):void。
- * @param thisObject This pointer of call back function.
- * @param type File type (optional). Use the static constants defined in the ResourceItem class. If you do not set the file name extension.
- * @version Egret 2.4
- * @platform Web,Native
- * @includeExample extension/resource/GetResByUrl.ts
- */
- /**
- * @language zh_CN
- * 通过完整URL方式获取外部资源。
- * @param url 要加载文件的外部路径。
- * @param compFunc 回调函数。示例:compFunc(data,url):void。
- * @param thisObject 回调函数的 this 引用。
- * @param type 文件类型(可选)。请使用 ResourceItem 类中定义的静态常量。若不设置将根据文件扩展名生成。
- * @version Egret 2.4
- * @platform Web,Native
- * @includeExample extension/resource/GetResByUrl.ts
- */
- function getResByUrl(url, compFunc, thisObject, type) {
- if (type === void 0) { type = ""; }
- instance.getResByUrl(url, compFunc, thisObject, type);
- }
- RES.getResByUrl = getResByUrl;
- /**
- * @language en_US
- * Destroy a single resource file or a set of resources to the cache data, to return whether to delete success.
- * @param name Name attribute or resource group name of the load item in the configuration file.
- * @param force Destruction of a resource group when the other resources groups have the same resource situation whether the resources will be deleted, the default value true.
- * @returns Are successful destruction.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 销毁单个资源文件或一组资源的缓存数据,返回是否删除成功。
- * @param name 配置文件中加载项的name属性或资源组名。
- * @param force 销毁一个资源组时其他资源组有同样资源情况资源是否会被删除,默认值 true。
- * @see #setMaxRetryTimes
- * @returns 是否销毁成功。
- * @version Egret 2.4
- * @platform Web,Native
- */
- function destroyRes(name, force) {
- return instance.destroyRes(name, force);
- }
- RES.destroyRes = destroyRes;
- /**
- * @language en_US
- * Sets the maximum number of concurrent load threads, the default value is 2.
- * @param thread The number of concurrent loads to be set.
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 设置最大并发加载线程数量,默认值是 2。
- * @param thread 要设置的并发加载数。
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function setMaxLoadingThread(thread) {
- instance.setMaxLoadingThread(thread);
- }
- RES.setMaxLoadingThread = setMaxLoadingThread;
- /**
- * @language en_US
- * Sets the number of retry times when the resource failed to load, and the default value is 3.
- * @param retry To set the retry count.
- * @includeExample extension/resource/Resource.ts
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 设置资源加载失败时的重试次数,默认值是 3。
- * @param retry 要设置的重试次数。
- * @includeExample extension/resource/Resource.ts
- * @version Egret 2.4
- * @platform Web,Native
- */
- function setMaxRetryTimes(retry) {
- instance.setMaxRetryTimes(retry);
- }
- RES.setMaxRetryTimes = setMaxRetryTimes;
- /**
- * @language en_US
- * Add event listeners, reference ResourceEvent defined constants.
- * @param type Event name。
- * @param listener Listener functions for handling events. This function must accept the Event object as its only parameter, and can't return any results,
- * As shown in the following example: function (evt:Event):void can have any name.
- * @param thisObject The this object that is bound to a function.
- * @param useCapture Determine the listener is running on the capture or running on the target and the bubbling phase. Set useCapture to true,
- * then the listener in the capture phase processing events, but not in the target or the bubbling phase processing events.
- * If useCapture is false, then the listener only in the target or the bubbling phase processing events.
- * To listen for events in all three stages, please call addEventListener two times: once the useCapture is set to true, once the useCapture is set to false.
- * @param priority Event listener priority. Priority is specified by a 32 - bit integer with a symbol. The higher the number, the higher the priority.
- * All listeners with a priority for n will be processed before the -1 n listener.
- * If two or more listeners share the same priority, they are processed in accordance with the order of their added. The default priority is 0.
- * @see RES.ResourceEvent
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 添加事件侦听器,参考 ResourceEvent 定义的常量。
- * @param type 事件的类型。
- * @param listener 处理事件的侦听器函数。此函数必须接受 Event 对象作为其唯一的参数,并且不能返回任何结果,
- * 如下面的示例所示: function(evt:Event):void 函数可以有任何名称。
- * @param thisObject 侦听函数绑定的 this 对象。
- * @param useCapture 确定侦听器是运行于捕获阶段还是运行于目标和冒泡阶段。如果将 useCapture 设置为 true,
- * 则侦听器只在捕获阶段处理事件,而不在目标或冒泡阶段处理事件。如果 useCapture 为 false,则侦听器只在目标或冒泡阶段处理事件。
- * 要在所有三个阶段都侦听事件,请调用 addEventListener 两次:一次将 useCapture 设置为 true,一次将 useCapture 设置为 false。
- * @param priority 事件侦听器的优先级。优先级由一个带符号的 32 位整数指定。数字越大,优先级越高。优先级为 n 的所有侦听器会在
- * 优先级为 n -1 的侦听器之前得到处理。如果两个或更多个侦听器共享相同的优先级,则按照它们的添加顺序进行处理。默认优先级为 0。
- * @see RES.ResourceEvent
- * @see #setMaxRetryTimes
- * @version Egret 2.4
- * @platform Web,Native
- */
- function addEventListener(type, listener, thisObject, useCapture, priority) {
- if (useCapture === void 0) { useCapture = false; }
- if (priority === void 0) { priority = 0; }
- instance.addEventListener(type, listener, thisObject, useCapture, priority);
- }
- RES.addEventListener = addEventListener;
- /**
- * @language en_US
- * Remove event listeners, reference ResourceEvent defined constants.
- * @param type Event name。
- * @param listener Listening function。
- * @param thisObject The this object that is bound to a function.
- * @param useCapture Is used to capture, and this property is only valid in the display list.
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 移除事件侦听器,参考ResourceEvent定义的常量。
- * @param type 事件名。
- * @param listener 侦听函数。
- * @param thisObject 侦听函数绑定的this对象。
- * @param useCapture 是否使用捕获,这个属性只在显示列表中生效。
- * @version Egret 2.4
- * @platform Web,Native
- */
- function removeEventListener(type, listener, thisObject, useCapture) {
- if (useCapture === void 0) { useCapture = false; }
- instance.removeEventListener(type, listener, thisObject, useCapture);
- }
- RES.removeEventListener = removeEventListener;
- function $getVirtualUrl(url) {
- if (instance.vcs) {
- return instance.vcs.getVirtualUrl(url);
- }
- else {
- return url;
- }
- }
- RES.$getVirtualUrl = $getVirtualUrl;
- /**
- * @private
- */
- var Resource = (function (_super) {
- __extends(Resource, _super);
- /**
- * 构造函数
- * @method RES.constructor
- * @private
- */
- function Resource() {
- var _this = _super.call(this) || this;
- /**
- * 解析器字典
- */
- _this.analyzerDic = {};
- _this.analyzerClassMap = {};
- _this.configItemList = [];
- _this.callLaterFlag = false;
- /**
- * 配置文件加载解析完成标志
- */
- _this.configComplete = false;
- /**
- * 已经加载过组名列表
- */
- _this.loadedGroups = [];
- _this.groupNameList = [];
- /**
- * 异步获取资源参数缓存字典
- */
- _this.asyncDic = {};
- _this._loadedUrlTypes = {};
- _this.init();
- return _this;
- }
- /**
- * 根据type获取对应的文件解析库
- */
- Resource.prototype.$getAnalyzerByType = function (type) {
- var analyzer = this.analyzerDic[type];
- if (!analyzer) {
- var clazz = this.analyzerClassMap[type];
- if (!clazz) {
- if (true) {
- egret.$error(3203, type);
- }
- return null;
- }
- analyzer = this.analyzerDic[type] = new clazz();
- }
- return analyzer;
- };
- /**
- * 注册一个自定义文件类型解析器
- * @param type 文件类型字符串,例如:bin,text,image,json等。
- * @param analyzerClass 自定义解析器的类定义
- */
- Resource.prototype.registerAnalyzer = function (type, analyzerClass) {
- this.analyzerClassMap[type] = analyzerClass;
- };
- Resource.prototype.$registerVersionController = function (vcs) {
- this.vcs = vcs;
- };
- /**
- * 初始化
- */
- Resource.prototype.init = function () {
- this.vcs = new RES.VersionController();
- var analyzerClassMap = this.analyzerClassMap;
- analyzerClassMap[RES.ResourceItem.TYPE_BIN] = RES.BinAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_IMAGE] = RES.ImageAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_TEXT] = RES.TextAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_JSON] = RES.JsonAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_SHEET] = RES.SheetAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_FONT] = RES.FontAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_SOUND] = RES.SoundAnalyzer;
- analyzerClassMap[RES.ResourceItem.TYPE_XML] = RES.XMLAnalyzer;
- this.resConfig = new RES.ResourceConfig();
- this.resLoader = new RES.ResourceLoader();
- this.resLoader.callBack = this.onResourceItemComp;
- this.resLoader.resInstance = this;
- this.resLoader.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onGroupComp, this);
- this.resLoader.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onGroupError, this);
- };
- /**
- * 开始加载配置
- * @method RES.loadConfig
- * @param url {string}
- * @param resourceRoot {string}
- * @param type {string}
- */
- Resource.prototype.loadConfig = function (url, resourceRoot, type) {
- if (type === void 0) { type = "json"; }
- var configItem = { url: url, resourceRoot: resourceRoot, type: type };
- this.configItemList.push(configItem);
- if (!this.callLaterFlag) {
- egret.callLater(this.startLoadConfig, this);
- this.callLaterFlag = true;
- }
- };
- Resource.prototype.startLoadConfig = function () {
- var _this = this;
- this.callLaterFlag = false;
- var configList = this.configItemList;
- this.configItemList = [];
- this.loadingConfigList = configList;
- var length = configList.length;
- var itemList = [];
- for (var i = 0; i < length; i++) {
- var item = configList[i];
- var resItem = new RES.ResourceItem(item.url, item.url, item.type);
- itemList.push(resItem);
- }
- var callback = {
- onSuccess: function (data) {
- _this.resLoader.loadGroup(itemList, Resource.GROUP_CONFIG, Number.MAX_VALUE);
- },
- onFail: function (err, data) {
- RES.ResourceEvent.dispatchResourceEvent(_this, RES.ResourceEvent.CONFIG_LOAD_ERROR);
- }
- };
- if (this.vcs) {
- this.vcs.fetchVersion(callback);
- }
- else {
- this.resLoader.loadGroup(itemList, Resource.GROUP_CONFIG, Number.MAX_VALUE);
- }
- };
- /**
- * 检查某个资源组是否已经加载完成
- * @method RES.isGroupLoaded
- * @param name {string}
- * @returns {boolean}
- */
- Resource.prototype.isGroupLoaded = function (name) {
- return this.loadedGroups.indexOf(name) != -1;
- };
- /**
- * 根据组名获取组加载项列表
- * @method RES.getGroupByName
- * @param name {string}
- * @returns {Array<egret.ResourceItem>}
- */
- Resource.prototype.getGroupByName = function (name) {
- return this.resConfig.getGroupByName(name);
- };
- /**
- * 根据组名加载一组资源
- * @method RES.loadGroup
- * @param name {string}
- * @param priority {number}
- */
- Resource.prototype.loadGroup = function (name, priority) {
- if (priority === void 0) { priority = 0; }
- if (this.loadedGroups.indexOf(name) != -1) {
- RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.GROUP_COMPLETE, name);
- return;
- }
- if (this.resLoader.isGroupInLoading(name))
- return;
- if (this.configComplete) {
- var group = this.resConfig.getGroupByName(name);
- this.resLoader.loadGroup(group, name, priority);
- }
- else {
- this.groupNameList.push({ name: name, priority: priority });
- }
- };
- /**
- * 创建自定义的加载资源组,注意:此方法仅在资源配置文件加载完成后执行才有效。
- * 可以监听ResourceEvent.CONFIG_COMPLETE事件来确认配置加载完成。
- * @method RES.ResourceConfig#createGroup
- * @param name {string} 要创建的加载资源组的组名
- * @param keys {egret.string[]} 要包含的键名列表,key对应配置文件里的name属性或一个资源组名。
- * @param override {boolean} 是否覆盖已经存在的同名资源组,默认false。
- * @returns {boolean}
- */
- Resource.prototype.createGroup = function (name, keys, override) {
- if (override === void 0) { override = false; }
- if (override) {
- var index = this.loadedGroups.indexOf(name);
- if (index != -1) {
- this.loadedGroups.splice(index, 1);
- }
- }
- return this.resConfig.createGroup(name, keys, override);
- };
- /**
- * 队列加载完成事件
- */
- Resource.prototype.onGroupComp = function (event) {
- if (event.groupName == Resource.GROUP_CONFIG) {
- var length_5 = this.loadingConfigList.length;
- for (var i = 0; i < length_5; i++) {
- var config = this.loadingConfigList[i];
- var resolver = this.$getAnalyzerByType(config.type);
- var data = resolver.getRes(config.url);
- resolver.destroyRes(config.url);
- this.resConfig.parseConfig(data, config.resourceRoot);
- }
- this.configComplete = true;
- this.loadingConfigList = null;
- RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.CONFIG_COMPLETE);
- this.loadDelayGroups();
- }
- else {
- this.loadedGroups.push(event.groupName);
- this.dispatchEvent(event);
- }
- };
- /**
- * 启动延迟的组加载
- */
- Resource.prototype.loadDelayGroups = function () {
- var groupNameList = this.groupNameList;
- this.groupNameList = [];
- var length = groupNameList.length;
- for (var i = 0; i < length; i++) {
- var item = groupNameList[i];
- this.loadGroup(item.name, item.priority);
- }
- };
- /**
- * 队列加载失败事件
- */
- Resource.prototype.onGroupError = function (event) {
- if (event.groupName == Resource.GROUP_CONFIG) {
- this.loadingConfigList = null;
- RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.CONFIG_LOAD_ERROR);
- }
- else {
- this.dispatchEvent(event);
- }
- };
- /**
- * 检查配置文件里是否含有指定的资源
- * @method RES.hasRes
- * @param key {string} 对应配置文件里的name属性或sbuKeys属性的一项。
- * @returns {boolean}
- */
- Resource.prototype.hasRes = function (key) {
- var type = this.resConfig.getType(key);
- if (type == "") {
- var prefix = RES.AnalyzerBase.getStringTail(key);
- type = this.resConfig.getType(prefix);
- if (type == "") {
- return false;
- }
- }
- return true;
- };
- /**
- * 运行时动态解析一个配置文件,
- * @param data {any} 配置文件数据,请参考resource.json的配置文件格式。传入对应的json对象即可。
- * @param folder {string} 加载项的路径前缀。
- */
- Resource.prototype.parseConfig = function (data, folder) {
- this.resConfig.parseConfig(data, folder);
- if (!this.configComplete && !this.loadingConfigList) {
- this.configComplete = true;
- this.loadDelayGroups();
- }
- };
- /**
- * 通过key同步获取资源
- * @method RES.getRes
- * @param key {string}
- * @returns {any}
- */
- Resource.prototype.getRes = function (key) {
- var type = this.resConfig.getType(key);
- if (type == "") {
- var prefix = RES.AnalyzerBase.getStringPrefix(key);
- type = this.resConfig.getType(prefix);
- if (type == "") {
- return null;
- }
- }
- var analyzer = this.$getAnalyzerByType(type);
- return analyzer.getRes(key);
- };
- /**
- * 通过key异步获取资源
- * @method RES.getResAsync
- * @param key {string}
- * @param compFunc {Function} 回调函数。示例:compFunc(data,url):void。
- * @param thisObject {any}
- */
- Resource.prototype.getResAsync = function (key, compFunc, thisObject) {
- var type = this.resConfig.getType(key);
- var name = this.resConfig.getName(key);
- if (type == "") {
- name = RES.AnalyzerBase.getStringPrefix(key);
- type = this.resConfig.getType(name);
- if (type == "") {
- egret.$callAsync(compFunc, thisObject);
- return;
- }
- }
- var analyzer = this.$getAnalyzerByType(type);
- var res = analyzer.getRes(key);
- if (res) {
- egret.$callAsync(compFunc, thisObject, res, key);
- return;
- }
- var args = { key: key, compFunc: compFunc, thisObject: thisObject };
- if (this.asyncDic[name]) {
- this.asyncDic[name].push(args);
- }
- else {
- this.asyncDic[name] = [args];
- var resItem = this.resConfig.getResourceItem(name);
- this.resLoader.loadItem(resItem);
- }
- };
- /**
- * 通过url获取资源
- * @method RES.getResByUrl
- * @param url {string}
- * @param compFunc {Function}
- * @param thisObject {any}
- * @param type {string}
- */
- Resource.prototype.getResByUrl = function (url, compFunc, thisObject, type) {
- if (type === void 0) { type = ""; }
- if (!url) {
- egret.$callAsync(compFunc, thisObject);
- return;
- }
- if (!type)
- type = this.getTypeByUrl(url);
- if (this._loadedUrlTypes[url] != null && this._loadedUrlTypes[url] != type) {
- egret.$warn(3202);
- }
- this._loadedUrlTypes[url] = type;
- var analyzer = this.$getAnalyzerByType(type);
- var name = url;
- var res = analyzer.getRes(name);
- if (res) {
- egret.$callAsync(compFunc, thisObject, res, url);
- return;
- }
- var args = { key: name, compFunc: compFunc, thisObject: thisObject };
- if (this.asyncDic[name]) {
- this.asyncDic[name].push(args);
- }
- else {
- this.asyncDic[name] = [args];
- var resItem = new RES.ResourceItem(name, url, type);
- this.resLoader.loadItem(resItem);
- }
- };
- /**
- * 通过url获取文件类型
- */
- Resource.prototype.getTypeByUrl = function (url) {
- var suffix = url.substr(url.lastIndexOf(".") + 1);
- if (suffix) {
- suffix = suffix.toLowerCase();
- }
- var type;
- switch (suffix) {
- case RES.ResourceItem.TYPE_XML:
- case RES.ResourceItem.TYPE_JSON:
- case RES.ResourceItem.TYPE_SHEET:
- type = suffix;
- break;
- case "png":
- case "jpg":
- case "gif":
- case "jpeg":
- case "bmp":
- type = RES.ResourceItem.TYPE_IMAGE;
- break;
- case "fnt":
- type = RES.ResourceItem.TYPE_FONT;
- break;
- case "txt":
- type = RES.ResourceItem.TYPE_TEXT;
- break;
- case "mp3":
- case "ogg":
- case "mpeg":
- case "wav":
- case "m4a":
- case "mp4":
- case "aiff":
- case "wma":
- case "mid":
- type = RES.ResourceItem.TYPE_SOUND;
- break;
- default:
- type = RES.ResourceItem.TYPE_BIN;
- break;
- }
- return type;
- };
- /**
- * 一个加载项加载完成
- */
- Resource.prototype.onResourceItemComp = function (item) {
- var argsList = this.asyncDic[item.name];
- delete this.asyncDic[item.name];
- var analyzer = this.$getAnalyzerByType(item.type);
- var length = argsList.length;
- for (var i = 0; i < length; i++) {
- var args = argsList[i];
- var res = analyzer.getRes(args.key);
- args.compFunc.call(args.thisObject, res, args.key);
- }
- };
- /**
- * 销毁单个资源文件或一组资源的缓存数据,返回是否删除成功。
- * @method RES.destroyRes
- * @param name {string} 配置文件中加载项的name属性或资源组名
- * @param force {boolean} 销毁一个资源组时其他资源组有同样资源情况资源是否会被删除,默认值true
- * @returns {boolean}
- */
- Resource.prototype.destroyRes = function (name, force) {
- if (force === void 0) { force = true; }
- var group = this.resConfig.getRawGroupByName(name);
- if (group && group.length > 0) {
- var index = this.loadedGroups.indexOf(name);
- if (index != -1) {
- this.loadedGroups.splice(index, 1);
- }
- var length_6 = group.length;
- for (var i = 0; i < length_6; i++) {
- var item = group[i];
- if (!force && this.isResInLoadedGroup(item.name)) {
- }
- else {
- item.loaded = false;
- var analyzer = this.$getAnalyzerByType(item.type);
- analyzer.destroyRes(item.name);
- this.removeLoadedGroupsByItemName(item.name);
- }
- }
- return true;
- }
- else {
- var type = this.resConfig.getType(name);
- if (type == "") {
- type = this._loadedUrlTypes[name];
- if (type == null || type == "") {
- return false;
- }
- delete this._loadedUrlTypes[name];
- var analyzer_1 = this.$getAnalyzerByType(type);
- analyzer_1.destroyRes(name);
- return true;
- }
- var item = this.resConfig.getRawResourceItem(name);
- item.loaded = false;
- var analyzer = this.$getAnalyzerByType(type);
- var result = analyzer.destroyRes(name);
- this.removeLoadedGroupsByItemName(item.name);
- return result;
- }
- };
- Resource.prototype.removeLoadedGroupsByItemName = function (name) {
- var loadedGroups = this.loadedGroups;
- var loadedGroupLength = loadedGroups.length;
- for (var i = 0; i < loadedGroupLength; i++) {
- var group = this.resConfig.getRawGroupByName(loadedGroups[i]);
- var length_7 = group.length;
- for (var j = 0; j < length_7; j++) {
- var item = group[j];
- if (item.name == name) {
- loadedGroups.splice(i, 1);
- i--;
- loadedGroupLength = loadedGroups.length;
- break;
- }
- }
- }
- };
- Resource.prototype.isResInLoadedGroup = function (name) {
- var loadedGroups = this.loadedGroups;
- var loadedGroupLength = loadedGroups.length;
- for (var i = 0; i < loadedGroupLength; i++) {
- var group = this.resConfig.getRawGroupByName(loadedGroups[i]);
- var length_8 = group.length;
- for (var j = 0; j < length_8; j++) {
- var item = group[j];
- if (item.name == name) {
- return true;
- }
- }
- }
- return false;
- };
- /**
- * 设置最大并发加载线程数量,默认值是2.
- * @method RES.setMaxLoadingThread
- * @param thread {number} 要设置的并发加载数。
- */
- Resource.prototype.setMaxLoadingThread = function (thread) {
- if (thread < 1) {
- thread = 1;
- }
- this.resLoader.thread = thread;
- };
- /**
- * 设置资源加载失败时的重试次数。
- * @param retry 要设置的重试次数。
- */
- Resource.prototype.setMaxRetryTimes = function (retry) {
- retry = Math.max(retry, 0);
- this.resLoader.maxRetryTimes = retry;
- };
- return Resource;
- }(egret.EventDispatcher));
- /**
- * 配置文件组组名
- */
- Resource.GROUP_CONFIG = "RES__CONFIG";
- __reflect(Resource.prototype, "Resource");
- /**
- * Resource单例
- */
- var instance = new Resource();
- })(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 AnimationAnalyzer = (function (_super) {
- __extends(AnimationAnalyzer, _super);
- function AnimationAnalyzer() {
- var _this = _super.call(this) || this;
- _this.sheetMap = {};
- /**
- * ImageLoader对象池
- */
- _this.recyclerIamge = [];
- _this._dataFormat = egret.HttpResponseType.TEXT;
- return _this;
- }
- /**
- * 一项加载结束
- */
- AnimationAnalyzer.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 {
- this.analyzeBitmap(resItem, request.data);
- }
- }
- if (request instanceof egret.HttpRequest) {
- this.recycler.push(request);
- }
- else {
- this.recyclerIamge.push(request);
- }
- compFunc.call(data.thisObject, resItem);
- };
- /**
- * 解析并缓存加载成功的配置文件
- */
- AnimationAnalyzer.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;
- if (config["file"]) {
- imageUrl = this.getRelativePath(resItem.url, config["file"]);
- }
- else {
- var arr = resItem.url.split("?");
- var arr2 = arr[0].split("/");
- arr2[arr2.length - 1] = arr2[arr2.length - 1].split(".")[0] + ".png";
- imageUrl = "";
- for (var i = 0; i < arr2.length; i++) {
- imageUrl += arr2[i] + (i < arr2.length - 1 ? "/" : "");
- }
- if (arr.length == 2)
- imageUrl += arr[2];
- }
- }
- return imageUrl;
- };
- /**
- * 解析并缓存加载成功的位图数据
- */
- AnimationAnalyzer.prototype.analyzeBitmap = function (resItem, data) {
- var name = resItem.name;
- if (this.fileDic[name] || !data) {
- return;
- }
- var config = this.sheetMap[name];
- delete this.sheetMap[name];
- var targetName = resItem.data && resItem.data.subkeys ? "" : name;
- var spriteSheet = this.parseAnimation(data, config, targetName);
- this.fileDic[name] = spriteSheet;
- };
- /**
- * 获取相对位置
- */
- AnimationAnalyzer.prototype.getRelativePath = function (url, file) {
- url = url.split("\\").join("/");
- var index = url.lastIndexOf("/");
- if (index != -1) {
- url = url.substring(0, index + 1) + file;
- }
- else {
- url = file;
- }
- return url;
- };
- AnimationAnalyzer.prototype.parseAnimation = function (bitmapData, data, name) {
- var attributes = Object.keys(data.mc);
- var list = data.mc[attributes[0]].frames;
- var len = list.length;
- var config;
- var animationFrames = [];
- for (var i = 0; i < len; i++) {
- config = data.res[list[i].res];
- var texture = new egret.Texture();
- texture._bitmapData = bitmapData;
- texture.$initData(config.x, config.y, config.w, config.h, list[i].x, list[i].y, list[i].sourceW, list[i].sourceH, bitmapData.width, bitmapData.height);
- }
- return animationFrames;
- };
- AnimationAnalyzer.prototype.destroyRes = function (name) {
- var sheet = this.fileDic[name];
- if (sheet) {
- delete this.fileDic[name];
- return true;
- }
- return false;
- };
- AnimationAnalyzer.prototype.loadImage = function (url, data) {
- var loader = this.getImageLoader();
- this.resItemDic[loader.hashCode] = data;
- loader.load(RES.$getVirtualUrl(url));
- };
- AnimationAnalyzer.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;
- };
- return AnimationAnalyzer;
- }(RES.BinAnalyzer));
- RES.AnimationAnalyzer = AnimationAnalyzer;
- __reflect(AnimationAnalyzer.prototype, "RES.AnimationAnalyzer");
- })(RES || (RES = {}));
- var egret;
- (function (egret) {
- egret.$locale_strings = egret.$locale_strings || {};
- egret.$locale_strings["en_US"] = egret.$locale_strings["en_US"] || {};
- var locale_strings = egret.$locale_strings["en_US"];
- //RES 3200-3299
- locale_strings[3200] = "RES.createGroup() passed in non-existed key value in configuration: {0}";
- locale_strings[3201] = "RES loaded non-existed or empty resource group:\"{0}\"";
- locale_strings[3202] = "Do not use the different types of ways to load the same material!";
- locale_strings[3203] = "Can't find the analyzer of the specified file type:{0}。 Please register the specified analyzer in the initialization of the project first,then start the resource loading process。";
- })(egret || (egret = {}));
- var egret;
- (function (egret) {
- egret.$locale_strings = egret.$locale_strings || {};
- egret.$locale_strings["zh_CN"] = egret.$locale_strings["zh_CN"] || {};
- var locale_strings = egret.$locale_strings["zh_CN"];
- //RES 3200-3299
- locale_strings[3200] = "RES.createGroup()传入了配置中不存在的键值: {0}";
- locale_strings[3201] = "RES加载了不存在或空的资源组:\"{0}\"";
- locale_strings[3202] = "请不要使用不同的类型方式来加载同一个素材!";
- locale_strings[3203] = "找不到指定文件类型的解析器:{0}。 请先在项目初始化里注册指定文件类型的解析器,再启动资源加载。";
- })(egret || (egret = {}));
|