美素佳儿 litter wizard小游戏
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

res.js 142KB

5 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515
  1. var __reflect = (this && this.__reflect) || function (p, c, t) {
  2. p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
  3. };
  4. var __extends = (this && this.__extends) || function (d, b) {
  5. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. //////////////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Copyright (c) 2014-present, Egret Technology.
  12. // All rights reserved.
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions are met:
  15. //
  16. // * Redistributions of source code must retain the above copyright
  17. // notice, this list of conditions and the following disclaimer.
  18. // * Redistributions in binary form must reproduce the above copyright
  19. // notice, this list of conditions and the following disclaimer in the
  20. // documentation and/or other materials provided with the distribution.
  21. // * Neither the name of the Egret nor the
  22. // names of its contributors may be used to endorse or promote products
  23. // derived from this software without specific prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  28. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  31. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  34. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //////////////////////////////////////////////////////////////////////////////////////
  37. var RES;
  38. (function (RES) {
  39. /**
  40. * @classic
  41. * @private
  42. */
  43. var AnalyzerBase = (function (_super) {
  44. __extends(AnalyzerBase, _super);
  45. function AnalyzerBase() {
  46. var _this = _super.call(this) || this;
  47. _this.resourceConfig = null;
  48. _this.resourceConfig = (RES["configInstance"]);
  49. return _this;
  50. }
  51. /**
  52. * 添加一个二级键名到配置列表。
  53. * @method RES.ResourceConfig#addSubkey
  54. * @param subkey {string} 要添加的二级键名
  55. * @param name {string} 二级键名所属的资源name属性
  56. */
  57. AnalyzerBase.prototype.addSubkey = function (subkey, name) {
  58. this.resourceConfig.addSubkey(subkey, name);
  59. };
  60. /**
  61. * 加载一个资源文件
  62. * @param resItem 加载项信息
  63. * @param compFunc 加载完成回调函数,示例:compFunc(resItem:ResourceItem):void;
  64. * @param thisObject 加载完成回调函数的this引用
  65. */
  66. AnalyzerBase.prototype.loadFile = function (resItem, compFunc, thisObject) {
  67. };
  68. /**
  69. * 同步方式获取解析完成的数据
  70. * @param name 对应配置文件里的name属性。
  71. */
  72. AnalyzerBase.prototype.getRes = function (name) {
  73. };
  74. /**
  75. * 销毁某个资源文件的二进制数据,返回是否删除成功。
  76. * @param name 配置文件中加载项的name属性
  77. */
  78. AnalyzerBase.prototype.destroyRes = function (name) {
  79. return false;
  80. };
  81. /**
  82. * 读取一个字符串里第一个点之前的内容。
  83. * @param name {string} 要读取的字符串
  84. */
  85. AnalyzerBase.getStringPrefix = function (name) {
  86. if (!name) {
  87. return "";
  88. }
  89. var index = name.indexOf(".");
  90. if (index != -1) {
  91. return name.substring(0, index);
  92. }
  93. return "";
  94. };
  95. /**
  96. * 读取一个字符串里第一个点之后的内容。
  97. * @param name {string} 要读取的字符串
  98. */
  99. AnalyzerBase.getStringTail = function (name) {
  100. if (!name) {
  101. return "";
  102. }
  103. var index = name.indexOf(".");
  104. if (index != -1) {
  105. return name.substring(index + 1);
  106. }
  107. return "";
  108. };
  109. return AnalyzerBase;
  110. }(egret.HashObject));
  111. RES.AnalyzerBase = AnalyzerBase;
  112. __reflect(AnalyzerBase.prototype, "RES.AnalyzerBase");
  113. })(RES || (RES = {}));
  114. //////////////////////////////////////////////////////////////////////////////////////
  115. //
  116. // Copyright (c) 2014-present, Egret Technology.
  117. // All rights reserved.
  118. // Redistribution and use in source and binary forms, with or without
  119. // modification, are permitted provided that the following conditions are met:
  120. //
  121. // * Redistributions of source code must retain the above copyright
  122. // notice, this list of conditions and the following disclaimer.
  123. // * Redistributions in binary form must reproduce the above copyright
  124. // notice, this list of conditions and the following disclaimer in the
  125. // documentation and/or other materials provided with the distribution.
  126. // * Neither the name of the Egret nor the
  127. // names of its contributors may be used to endorse or promote products
  128. // derived from this software without specific prior written permission.
  129. //
  130. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  131. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  132. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  133. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  134. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  135. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  136. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  137. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  138. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  139. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  140. //
  141. //////////////////////////////////////////////////////////////////////////////////////
  142. var RES;
  143. (function (RES) {
  144. /**
  145. * @private
  146. */
  147. var BinAnalyzer = (function (_super) {
  148. __extends(BinAnalyzer, _super);
  149. /**
  150. * 构造函数
  151. */
  152. function BinAnalyzer() {
  153. var _this = _super.call(this) || this;
  154. /**
  155. * 字节流数据缓存字典
  156. */
  157. _this.fileDic = {};
  158. /**
  159. * 加载项字典
  160. */
  161. _this.resItemDic = [];
  162. _this._dataFormat = egret.HttpResponseType.ARRAY_BUFFER;
  163. /**
  164. * Loader对象池
  165. */
  166. _this.recycler = [];
  167. return _this;
  168. }
  169. /**
  170. * @inheritDoc
  171. */
  172. BinAnalyzer.prototype.loadFile = function (resItem, compFunc, thisObject) {
  173. if (this.fileDic[resItem.name]) {
  174. compFunc.call(thisObject, resItem);
  175. return;
  176. }
  177. var request = this.getRequest();
  178. this.resItemDic[request.hashCode] = { item: resItem, func: compFunc, thisObject: thisObject };
  179. request.open(RES.$getVirtualUrl(resItem.url));
  180. request.send();
  181. };
  182. /**
  183. * 获取一个URLLoader对象
  184. */
  185. BinAnalyzer.prototype.getRequest = function () {
  186. var request = this.recycler.pop();
  187. if (!request) {
  188. request = new egret.HttpRequest();
  189. request.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
  190. request.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
  191. }
  192. request.responseType = this._dataFormat;
  193. return request;
  194. };
  195. /**
  196. * 一项加载结束
  197. */
  198. BinAnalyzer.prototype.onLoadFinish = function (event) {
  199. var request = (event.target);
  200. var data = this.resItemDic[request.hashCode];
  201. delete this.resItemDic[request.hashCode];
  202. var resItem = data.item;
  203. var compFunc = data.func;
  204. resItem.loaded = (event.type == egret.Event.COMPLETE);
  205. if (resItem.loaded) {
  206. this.analyzeData(resItem, request.response);
  207. }
  208. this.recycler.push(request);
  209. compFunc.call(data.thisObject, resItem);
  210. };
  211. /**
  212. * 解析并缓存加载成功的数据
  213. */
  214. BinAnalyzer.prototype.analyzeData = function (resItem, data) {
  215. var name = resItem.name;
  216. if (this.fileDic[name] || (data != "" && !data)) {
  217. return;
  218. }
  219. this.fileDic[name] = data;
  220. };
  221. /**
  222. * @inheritDoc
  223. */
  224. BinAnalyzer.prototype.getRes = function (name) {
  225. return this.fileDic[name];
  226. };
  227. /**
  228. * @inheritDoc
  229. */
  230. BinAnalyzer.prototype.hasRes = function (name) {
  231. var res = this.getRes(name);
  232. return res != null;
  233. };
  234. /**
  235. * @inheritDoc
  236. */
  237. BinAnalyzer.prototype.destroyRes = function (name) {
  238. if (this.fileDic[name]) {
  239. this.onResourceDestroy(this.fileDic[name]);
  240. delete this.fileDic[name];
  241. return true;
  242. }
  243. return false;
  244. };
  245. BinAnalyzer.prototype.onResourceDestroy = function (resource) {
  246. };
  247. return BinAnalyzer;
  248. }(RES.AnalyzerBase));
  249. RES.BinAnalyzer = BinAnalyzer;
  250. __reflect(BinAnalyzer.prototype, "RES.BinAnalyzer");
  251. })(RES || (RES = {}));
  252. //////////////////////////////////////////////////////////////////////////////////////
  253. //
  254. // Copyright (c) 2014-present, Egret Technology.
  255. // All rights reserved.
  256. // Redistribution and use in source and binary forms, with or without
  257. // modification, are permitted provided that the following conditions are met:
  258. //
  259. // * Redistributions of source code must retain the above copyright
  260. // notice, this list of conditions and the following disclaimer.
  261. // * Redistributions in binary form must reproduce the above copyright
  262. // notice, this list of conditions and the following disclaimer in the
  263. // documentation and/or other materials provided with the distribution.
  264. // * Neither the name of the Egret nor the
  265. // names of its contributors may be used to endorse or promote products
  266. // derived from this software without specific prior written permission.
  267. //
  268. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  269. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  270. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  271. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  272. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  273. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  274. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  275. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  276. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  277. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  278. //
  279. //////////////////////////////////////////////////////////////////////////////////////
  280. var RES;
  281. (function (RES) {
  282. /**
  283. * @language en_US
  284. * Resource term. One of the resources arrays in resource.json.
  285. * @version Egret 2.4
  286. * @platform Web,Native
  287. */
  288. /**
  289. * @language zh_CN
  290. * 资源项。对应 resource.json 中 resources 数组中的一项。
  291. * @version Egret 2.4
  292. * @platform Web,Native
  293. */
  294. var ResourceItem = (function () {
  295. /**
  296. * @language en_US
  297. * Constructor.
  298. * @param name Name of resource term.
  299. * @param url URL of resource term.
  300. * @param type Type of resource term.
  301. * @version Egret 2.4
  302. * @platform Web,Native
  303. */
  304. /**
  305. * @language zh_CN
  306. * 构造函数。
  307. * @param name 加载项名称。
  308. * @param url 要加载的文件地址。
  309. * @param type 加载项文件类型。
  310. * @version Egret 2.4
  311. * @platform Web,Native
  312. */
  313. function ResourceItem(name, url, type) {
  314. /**
  315. * @language en_US
  316. * Name of the resource term group.
  317. * @version Egret 2.4
  318. * @platform Web,Native
  319. */
  320. /**
  321. * @language zh_CN
  322. * 资源所属的组名。
  323. * @version Egret 2.4
  324. * @platform Web,Native
  325. */
  326. this.groupName = "";
  327. /**
  328. * @language en_US
  329. * The raw data object to be referenced.
  330. * @version Egret 2.4
  331. * @platform Web,Native
  332. */
  333. /**
  334. * @language zh_CN
  335. * 被引用的原始数据对象。
  336. * @version Egret 2.4
  337. * @platform Web,Native
  338. */
  339. this.data = null;
  340. this._loaded = false;
  341. this.name = name;
  342. this.url = url;
  343. this.type = type;
  344. }
  345. Object.defineProperty(ResourceItem.prototype, "loaded", {
  346. /**
  347. * @language en_US
  348. * Load complete flag.
  349. * @version Egret 2.4
  350. * @platform Web,Native
  351. */
  352. /**
  353. * @language zh_CN
  354. * 加载完成的标志。
  355. * @version Egret 2.4
  356. * @platform Web,Native
  357. */
  358. get: function () {
  359. return this.data ? this.data.loaded : this._loaded;
  360. },
  361. set: function (value) {
  362. if (this.data)
  363. this.data.loaded = value;
  364. this._loaded = value;
  365. },
  366. enumerable: true,
  367. configurable: true
  368. });
  369. /**
  370. * @language en_US
  371. * Turn into a string.
  372. * @version Egret 2.4
  373. * @platform Web,Native
  374. */
  375. /**
  376. * @language zh_CN
  377. * 转成字符串。
  378. * @version Egret 2.4
  379. * @platform Web,Native
  380. */
  381. ResourceItem.prototype.toString = function () {
  382. return "[ResourceItem name=\"" + this.name + "\" url=\"" + this.url + "\" type=\"" + this.type + "\"]";
  383. };
  384. return ResourceItem;
  385. }());
  386. /**
  387. * @language en_US
  388. * XML file.
  389. * @version Egret 2.4
  390. * @platform Web,Native
  391. */
  392. /**
  393. * @language zh_CN
  394. * XML 文件。
  395. * @version Egret 2.4
  396. * @platform Web,Native
  397. */
  398. ResourceItem.TYPE_XML = "xml";
  399. /**
  400. * @language en_US
  401. * Picture file.
  402. * @version Egret 2.4
  403. * @platform Web,Native
  404. */
  405. /**
  406. * @language zh_CN
  407. * 图片文件。
  408. * @version Egret 2.4
  409. * @platform Web,Native
  410. */
  411. ResourceItem.TYPE_IMAGE = "image";
  412. /**
  413. * @language en_US
  414. * Binary file.
  415. * @version Egret 2.4
  416. * @platform Web
  417. */
  418. /**
  419. * @language zh_CN
  420. * 二进制文件。
  421. * @version Egret 2.4
  422. * @platform Web
  423. */
  424. ResourceItem.TYPE_BIN = "bin";
  425. /**
  426. * @language en_US
  427. * Text file.
  428. * @version Egret 2.4
  429. * @platform Web,Native
  430. */
  431. /**
  432. * @language zh_CN
  433. * 文本文件。
  434. * @version Egret 2.4
  435. * @platform Web,Native
  436. */
  437. ResourceItem.TYPE_TEXT = "text";
  438. /**
  439. * @language en_US
  440. * JSON file.
  441. * @version Egret 2.4
  442. * @platform Web,Native
  443. */
  444. /**
  445. * @language zh_CN
  446. * JSON 文件。
  447. * @version Egret 2.4
  448. * @platform Web,Native
  449. */
  450. ResourceItem.TYPE_JSON = "json";
  451. /**
  452. * @language en_US
  453. * SpriteSheet file.
  454. * @version Egret 2.4
  455. * @platform Web,Native
  456. */
  457. /**
  458. * @language zh_CN
  459. * SpriteSheet 文件。
  460. * @version Egret 2.4
  461. * @platform Web,Native
  462. */
  463. ResourceItem.TYPE_SHEET = "sheet";
  464. /**
  465. * @language en_US
  466. * BitmapTextSpriteSheet file.
  467. * @version Egret 2.4
  468. * @platform Web,Native
  469. */
  470. /**
  471. * @language zh_CN
  472. * BitmapTextSpriteSheet 文件。
  473. * @version Egret 2.4
  474. * @platform Web,Native
  475. */
  476. ResourceItem.TYPE_FONT = "font";
  477. /**
  478. * @language en_US
  479. * Sound file.
  480. * @version Egret 2.4
  481. * @platform Web,Native
  482. */
  483. /**
  484. * @language zh_CN
  485. * 声音文件。
  486. * @version Egret 2.4
  487. * @platform Web,Native
  488. */
  489. ResourceItem.TYPE_SOUND = "sound";
  490. RES.ResourceItem = ResourceItem;
  491. __reflect(ResourceItem.prototype, "RES.ResourceItem");
  492. })(RES || (RES = {}));
  493. ////////////////////////////////////////////////////////////////////////////////////////
  494. ////
  495. //// Copyright (c) 2014-present, Egret Technology.
  496. //// All rights reserved.
  497. //// Redistribution and use in source and binary forms, with or without
  498. //// modification, are permitted provided that the following conditions are met:
  499. ////
  500. //// * Redistributions of source code must retain the above copyright
  501. //// notice, this list of conditions and the following disclaimer.
  502. //// * Redistributions in binary form must reproduce the above copyright
  503. //// notice, this list of conditions and the following disclaimer in the
  504. //// documentation and/or other materials provided with the distribution.
  505. //// * Neither the name of the Egret nor the
  506. //// names of its contributors may be used to endorse or promote products
  507. //// derived from this software without specific prior written permission.
  508. ////
  509. //// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  510. //// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  511. //// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  512. //// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  513. //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  514. //// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  515. //// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  516. //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  517. //// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  518. //// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  519. ////
  520. ////////////////////////////////////////////////////////////////////////////////////////
  521. var RES;
  522. (function (RES) {
  523. /**
  524. * SpriteSheet解析器
  525. * @private
  526. */
  527. var SheetAnalyzer = (function (_super) {
  528. __extends(SheetAnalyzer, _super);
  529. function SheetAnalyzer() {
  530. var _this = _super.call(this) || this;
  531. _this.sheetMap = {};
  532. _this.textureMap = {};
  533. /**
  534. * ImageLoader对象池
  535. */
  536. _this.recyclerIamge = [];
  537. _this._dataFormat = egret.HttpResponseType.TEXT;
  538. return _this;
  539. }
  540. SheetAnalyzer.prototype.getRes = function (name) {
  541. var res = this.fileDic[name];
  542. if (!res) {
  543. res = this.textureMap[name];
  544. }
  545. if (!res) {
  546. var prefix = RES.AnalyzerBase.getStringPrefix(name);
  547. res = this.fileDic[prefix];
  548. if (res) {
  549. var tail = RES.AnalyzerBase.getStringTail(name);
  550. res = res.getTexture(tail);
  551. }
  552. }
  553. return res;
  554. };
  555. /**
  556. * 一项加载结束
  557. */
  558. SheetAnalyzer.prototype.onLoadFinish = function (event) {
  559. var request = event.target;
  560. var data = this.resItemDic[request.$hashCode];
  561. delete this.resItemDic[request.hashCode];
  562. var resItem = data.item;
  563. var compFunc = data.func;
  564. resItem.loaded = (event.type == egret.Event.COMPLETE);
  565. if (resItem.loaded) {
  566. if (request instanceof egret.HttpRequest) {
  567. resItem.loaded = false;
  568. var imageUrl = this.analyzeConfig(resItem, request.response);
  569. if (imageUrl) {
  570. this.loadImage(imageUrl, data);
  571. this.recycler.push(request);
  572. return;
  573. }
  574. }
  575. else {
  576. var texture = new egret.Texture();
  577. texture._setBitmapData(request.data);
  578. this.analyzeBitmap(resItem, texture);
  579. }
  580. }
  581. if (request instanceof egret.HttpRequest) {
  582. this.recycler.push(request);
  583. }
  584. else {
  585. this.recyclerIamge.push(request);
  586. }
  587. compFunc.call(data.thisObject, resItem);
  588. };
  589. /**
  590. * 解析并缓存加载成功的配置文件
  591. */
  592. SheetAnalyzer.prototype.analyzeConfig = function (resItem, data) {
  593. var name = resItem.name;
  594. var config;
  595. var imageUrl = "";
  596. try {
  597. var str = data;
  598. config = JSON.parse(str);
  599. }
  600. catch (e) {
  601. egret.$warn(1017, resItem.url, data);
  602. }
  603. if (config) {
  604. this.sheetMap[name] = config;
  605. imageUrl = this.getRelativePath(resItem.url, config["file"]);
  606. }
  607. return imageUrl;
  608. };
  609. /**
  610. * 解析并缓存加载成功的位图数据
  611. */
  612. SheetAnalyzer.prototype.analyzeBitmap = function (resItem, texture) {
  613. var name = resItem.name;
  614. if (this.fileDic[name] || !texture) {
  615. return;
  616. }
  617. var config = this.sheetMap[name];
  618. delete this.sheetMap[name];
  619. var targetName = resItem.data && resItem.data.subkeys ? "" : name;
  620. var spriteSheet = this.parseSpriteSheet(texture, config, targetName);
  621. this.fileDic[name] = spriteSheet;
  622. };
  623. /**
  624. * 获取相对位置
  625. */
  626. SheetAnalyzer.prototype.getRelativePath = function (url, file) {
  627. url = url.split("\\").join("/");
  628. var params = url.match(/#.*|\?.*/);
  629. var paramUrl = "";
  630. if (params) {
  631. paramUrl = params[0];
  632. }
  633. var index = url.lastIndexOf("/");
  634. if (index != -1) {
  635. url = url.substring(0, index + 1) + file;
  636. }
  637. else {
  638. url = file;
  639. }
  640. return url + paramUrl;
  641. };
  642. SheetAnalyzer.prototype.parseSpriteSheet = function (texture, data, name) {
  643. var frames = data.frames;
  644. if (!frames) {
  645. return null;
  646. }
  647. var spriteSheet = new egret.SpriteSheet(texture);
  648. var textureMap = this.textureMap;
  649. for (var subkey in frames) {
  650. var config = frames[subkey];
  651. var texture_1 = spriteSheet.createTexture(subkey, config.x, config.y, config.w, config.h, config.offX, config.offY, config.sourceW, config.sourceH);
  652. if (config["scale9grid"]) {
  653. var str = config["scale9grid"];
  654. var list = str.split(",");
  655. texture_1["scale9Grid"] = new egret.Rectangle(parseInt(list[0]), parseInt(list[1]), parseInt(list[2]), parseInt(list[3]));
  656. }
  657. if (textureMap[subkey] == null) {
  658. textureMap[subkey] = texture_1;
  659. if (name) {
  660. this.addSubkey(subkey, name);
  661. }
  662. }
  663. }
  664. return spriteSheet;
  665. };
  666. SheetAnalyzer.prototype.destroyRes = function (name) {
  667. var sheet = this.fileDic[name];
  668. if (sheet) {
  669. delete this.fileDic[name];
  670. var texture = void 0;
  671. for (var subkey in sheet._textureMap) {
  672. if (texture == null) {
  673. texture = sheet._textureMap[subkey];
  674. this.onResourceDestroy(texture);
  675. texture = null;
  676. }
  677. delete this.textureMap[subkey];
  678. }
  679. if (sheet.dispose) {
  680. sheet.dispose();
  681. }
  682. return true;
  683. }
  684. return false;
  685. };
  686. SheetAnalyzer.prototype.loadImage = function (url, data) {
  687. var loader = this.getImageLoader();
  688. this.resItemDic[loader.hashCode] = data;
  689. loader.load(RES.$getVirtualUrl(url));
  690. };
  691. SheetAnalyzer.prototype.getImageLoader = function () {
  692. var loader = this.recyclerIamge.pop();
  693. if (!loader) {
  694. loader = new egret.ImageLoader();
  695. loader.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
  696. loader.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
  697. }
  698. return loader;
  699. };
  700. SheetAnalyzer.prototype.onResourceDestroy = function (texture) {
  701. if (texture) {
  702. texture.dispose();
  703. }
  704. };
  705. return SheetAnalyzer;
  706. }(RES.BinAnalyzer));
  707. RES.SheetAnalyzer = SheetAnalyzer;
  708. __reflect(SheetAnalyzer.prototype, "RES.SheetAnalyzer");
  709. })(RES || (RES = {}));
  710. //////////////////////////////////////////////////////////////////////////////////////
  711. //
  712. // Copyright (c) 2014-present, Egret Technology.
  713. // All rights reserved.
  714. // Redistribution and use in source and binary forms, with or without
  715. // modification, are permitted provided that the following conditions are met:
  716. //
  717. // * Redistributions of source code must retain the above copyright
  718. // notice, this list of conditions and the following disclaimer.
  719. // * Redistributions in binary form must reproduce the above copyright
  720. // notice, this list of conditions and the following disclaimer in the
  721. // documentation and/or other materials provided with the distribution.
  722. // * Neither the name of the Egret nor the
  723. // names of its contributors may be used to endorse or promote products
  724. // derived from this software without specific prior written permission.
  725. //
  726. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  727. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  728. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  729. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  730. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  731. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  732. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  733. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  734. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  735. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  736. //
  737. //////////////////////////////////////////////////////////////////////////////////////
  738. var RES;
  739. (function (RES) {
  740. })(RES || (RES = {}));
  741. //////////////////////////////////////////////////////////////////////////////////////
  742. //
  743. // Copyright (c) 2014-present, Egret Technology.
  744. // All rights reserved.
  745. // Redistribution and use in source and binary forms, with or without
  746. // modification, are permitted provided that the following conditions are met:
  747. //
  748. // * Redistributions of source code must retain the above copyright
  749. // notice, this list of conditions and the following disclaimer.
  750. // * Redistributions in binary form must reproduce the above copyright
  751. // notice, this list of conditions and the following disclaimer in the
  752. // documentation and/or other materials provided with the distribution.
  753. // * Neither the name of the Egret nor the
  754. // names of its contributors may be used to endorse or promote products
  755. // derived from this software without specific prior written permission.
  756. //
  757. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  758. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  759. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  760. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  761. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  762. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  763. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  764. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  765. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  766. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  767. //
  768. //////////////////////////////////////////////////////////////////////////////////////
  769. var RES;
  770. (function (RES) {
  771. /**
  772. * @language en_US
  773. * The events of resource loading.
  774. * @version Egret 2.4
  775. * @platform Web,Native
  776. */
  777. /**
  778. * @language zh_CN
  779. * 资源加载事件。
  780. * @version Egret 2.4
  781. * @platform Web,Native
  782. */
  783. var ResourceEvent = (function (_super) {
  784. __extends(ResourceEvent, _super);
  785. /**
  786. * @language en_US
  787. * Creates an Event object to pass as a parameter to event listeners.
  788. * @param type The type of the event, accessible as Event.type.
  789. * @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
  790. * @param cancelable Determines whether the Event object can be canceled. The default values is false.
  791. * @version Egret 2.4
  792. * @platform Web,Native
  793. * @private
  794. */
  795. /**
  796. * @language zh_CN
  797. * 创建一个作为参数传递给事件侦听器的 Event 对象。
  798. * @param type 事件的类型,可以作为 Event.type 访问。
  799. * @param bubbles 确定 Event 对象是否参与事件流的冒泡阶段。默认值为 false。
  800. * @param cancelable 确定是否可以取消 Event 对象。默认值为 false。
  801. * @version Egret 2.4
  802. * @platform Web,Native
  803. * @private
  804. */
  805. function ResourceEvent(type, bubbles, cancelable) {
  806. if (bubbles === void 0) { bubbles = false; }
  807. if (cancelable === void 0) { cancelable = false; }
  808. var _this = _super.call(this, type, bubbles, cancelable) || this;
  809. /**
  810. * @language en_US
  811. * File number that has been loaded.
  812. * @version Egret 2.4
  813. * @platform Web,Native
  814. */
  815. /**
  816. * @language zh_CN
  817. * 已经加载的文件数。
  818. * @version Egret 2.4
  819. * @platform Web,Native
  820. */
  821. _this.itemsLoaded = 0;
  822. /**
  823. * @language en_US
  824. * Total file number to load.
  825. * @version Egret 2.4
  826. * @platform Web,Native
  827. */
  828. /**
  829. * @language zh_CN
  830. * 要加载的总文件数。
  831. * @version Egret 2.4
  832. * @platform Web,Native
  833. */
  834. _this.itemsTotal = 0;
  835. /**
  836. * @language en_US
  837. * Resource group name.
  838. * @version Egret 2.4
  839. * @platform Web,Native
  840. */
  841. /**
  842. * @language zh_CN
  843. * 资源组名。
  844. * @version Egret 2.4
  845. * @platform Web,Native
  846. */
  847. _this.groupName = "";
  848. /**
  849. * @language en_US
  850. * An item of information that is finished by the end of a load.
  851. * @version Egret 2.4
  852. * @platform Web,Native
  853. */
  854. /**
  855. * @language zh_CN
  856. * 一次加载项加载结束的项信息对象。
  857. * @version Egret 2.4
  858. * @platform Web,Native
  859. */
  860. _this.resItem = null;
  861. return _this;
  862. }
  863. /**
  864. * 使用指定的EventDispatcher对象来抛出事件对象。抛出的对象将会缓存在对象池上,供下次循环复用。
  865. * @method RES.ResourceEvent.dispatchResourceEvent
  866. * @param target {egret.IEventDispatcher}
  867. * @param type {string}
  868. * @param groupName {string}
  869. * @param resItem {egret.ResourceItem}
  870. * @param itemsLoaded {number}
  871. * @param itemsTotal {number}
  872. * @private
  873. */
  874. ResourceEvent.dispatchResourceEvent = function (target, type, groupName, resItem, itemsLoaded, itemsTotal) {
  875. if (groupName === void 0) { groupName = ""; }
  876. if (resItem === void 0) { resItem = null; }
  877. if (itemsLoaded === void 0) { itemsLoaded = 0; }
  878. if (itemsTotal === void 0) { itemsTotal = 0; }
  879. var event = egret.Event.create(ResourceEvent, type);
  880. event.groupName = groupName;
  881. event.resItem = resItem;
  882. event.itemsLoaded = itemsLoaded;
  883. event.itemsTotal = itemsTotal;
  884. var result = target.dispatchEvent(event);
  885. egret.Event.release(event);
  886. return result;
  887. };
  888. return ResourceEvent;
  889. }(egret.Event));
  890. /**
  891. * @language en_US
  892. * Failure event for a load item.
  893. * @version Egret 2.4
  894. * @platform Web,Native
  895. */
  896. /**
  897. * @language zh_CN
  898. * 一个加载项加载失败事件。
  899. * @version Egret 2.4
  900. * @platform Web,Native
  901. */
  902. ResourceEvent.ITEM_LOAD_ERROR = "itemLoadError";
  903. /**
  904. * @language en_US
  905. * 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.
  906. * @version Egret 2.4
  907. * @platform Web,Native
  908. */
  909. /**
  910. * @language zh_CN
  911. * 配置文件加载并解析完成事件。注意:若有配置文件加载失败,将不会抛出此事件,若要处理配置加载失败,请同时监听 CONFIG_LOAD_ERROR 事件。
  912. * @version Egret 2.4
  913. * @platform Web,Native
  914. */
  915. ResourceEvent.CONFIG_COMPLETE = "configComplete";
  916. /**
  917. * @language en_US
  918. * Configuration file failed to load.
  919. * @version Egret 2.4
  920. * @platform Web,Native
  921. */
  922. /**
  923. * @language zh_CN
  924. * 配置文件加载失败事件。
  925. * @version Egret 2.4
  926. * @platform Web,Native
  927. */
  928. ResourceEvent.CONFIG_LOAD_ERROR = "configLoadError";
  929. /**
  930. * @language en_US
  931. * Delay load group resource loading progress event.
  932. * @version Egret 2.4
  933. * @platform Web,Native
  934. */
  935. /**
  936. * @language zh_CN
  937. * 延迟加载组资源加载进度事件。
  938. * @version Egret 2.4
  939. * @platform Web,Native
  940. */
  941. ResourceEvent.GROUP_PROGRESS = "groupProgress";
  942. /**
  943. * @language en_US
  944. * 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.
  945. * @version Egret 2.4
  946. * @platform Web,Native
  947. */
  948. /**
  949. * @language zh_CN
  950. * 延迟加载组资源加载完成事件。注意:若组内有资源项加载失败,将不会抛出此事件,若要处理组加载失败,请同时监听 GROUP_LOAD_ERROR 事件。
  951. * @version Egret 2.4
  952. * @platform Web,Native
  953. */
  954. ResourceEvent.GROUP_COMPLETE = "groupComplete";
  955. /**
  956. * @language en_US
  957. * Delayed load group resource failed event.
  958. * @version Egret 2.4
  959. * @platform Web,Native
  960. */
  961. /**
  962. * @language zh_CN
  963. * 延迟加载组资源加载失败事件。
  964. * @version Egret 2.4
  965. * @platform Web,Native
  966. */
  967. ResourceEvent.GROUP_LOAD_ERROR = "groupLoadError";
  968. RES.ResourceEvent = ResourceEvent;
  969. __reflect(ResourceEvent.prototype, "RES.ResourceEvent");
  970. })(RES || (RES = {}));
  971. //////////////////////////////////////////////////////////////////////////////////////
  972. //
  973. // Copyright (c) 2014-present, Egret Technology.
  974. // All rights reserved.
  975. // Redistribution and use in source and binary forms, with or without
  976. // modification, are permitted provided that the following conditions are met:
  977. //
  978. // * Redistributions of source code must retain the above copyright
  979. // notice, this list of conditions and the following disclaimer.
  980. // * Redistributions in binary form must reproduce the above copyright
  981. // notice, this list of conditions and the following disclaimer in the
  982. // documentation and/or other materials provided with the distribution.
  983. // * Neither the name of the Egret nor the
  984. // names of its contributors may be used to endorse or promote products
  985. // derived from this software without specific prior written permission.
  986. //
  987. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  988. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  989. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  990. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  991. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  992. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  993. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  994. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  995. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  996. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  997. //
  998. //////////////////////////////////////////////////////////////////////////////////////
  999. var RES;
  1000. (function (RES) {
  1001. /**
  1002. * @private
  1003. */
  1004. var TextAnalyzer = (function (_super) {
  1005. __extends(TextAnalyzer, _super);
  1006. function TextAnalyzer() {
  1007. var _this = _super.call(this) || this;
  1008. _this._dataFormat = egret.HttpResponseType.TEXT;
  1009. return _this;
  1010. }
  1011. return TextAnalyzer;
  1012. }(RES.BinAnalyzer));
  1013. RES.TextAnalyzer = TextAnalyzer;
  1014. __reflect(TextAnalyzer.prototype, "RES.TextAnalyzer");
  1015. })(RES || (RES = {}));
  1016. //////////////////////////////////////////////////////////////////////////////////////
  1017. //
  1018. // Copyright (c) 2014-present, Egret Technology.
  1019. // All rights reserved.
  1020. // Redistribution and use in source and binary forms, with or without
  1021. // modification, are permitted provided that the following conditions are met:
  1022. //
  1023. // * Redistributions of source code must retain the above copyright
  1024. // notice, this list of conditions and the following disclaimer.
  1025. // * Redistributions in binary form must reproduce the above copyright
  1026. // notice, this list of conditions and the following disclaimer in the
  1027. // documentation and/or other materials provided with the distribution.
  1028. // * Neither the name of the Egret nor the
  1029. // names of its contributors may be used to endorse or promote products
  1030. // derived from this software without specific prior written permission.
  1031. //
  1032. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1033. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1034. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1035. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1036. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1037. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1038. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1039. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1040. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1041. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1042. //
  1043. //////////////////////////////////////////////////////////////////////////////////////
  1044. var RES;
  1045. (function (RES) {
  1046. /**
  1047. * @private
  1048. */
  1049. var JsonAnalyzer = (function (_super) {
  1050. __extends(JsonAnalyzer, _super);
  1051. function JsonAnalyzer() {
  1052. var _this = _super.call(this) || this;
  1053. _this._dataFormat = egret.HttpResponseType.TEXT;
  1054. return _this;
  1055. }
  1056. /**
  1057. * 解析并缓存加载成功的数据
  1058. */
  1059. JsonAnalyzer.prototype.analyzeData = function (resItem, data) {
  1060. var name = resItem.name;
  1061. if (this.fileDic[name] || !data) {
  1062. return;
  1063. }
  1064. try {
  1065. var str = data;
  1066. this.fileDic[name] = JSON.parse(str);
  1067. }
  1068. catch (e) {
  1069. egret.$warn(1017, resItem.url, data);
  1070. }
  1071. };
  1072. return JsonAnalyzer;
  1073. }(RES.BinAnalyzer));
  1074. RES.JsonAnalyzer = JsonAnalyzer;
  1075. __reflect(JsonAnalyzer.prototype, "RES.JsonAnalyzer");
  1076. })(RES || (RES = {}));
  1077. //////////////////////////////////////////////////////////////////////////////////////
  1078. //
  1079. // Copyright (c) 2014-present, Egret Technology.
  1080. // All rights reserved.
  1081. // Redistribution and use in source and binary forms, with or without
  1082. // modification, are permitted provided that the following conditions are met:
  1083. //
  1084. // * Redistributions of source code must retain the above copyright
  1085. // notice, this list of conditions and the following disclaimer.
  1086. // * Redistributions in binary form must reproduce the above copyright
  1087. // notice, this list of conditions and the following disclaimer in the
  1088. // documentation and/or other materials provided with the distribution.
  1089. // * Neither the name of the Egret nor the
  1090. // names of its contributors may be used to endorse or promote products
  1091. // derived from this software without specific prior written permission.
  1092. //
  1093. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1094. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1095. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1096. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1097. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1098. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1099. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1100. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1101. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1102. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1103. //
  1104. //////////////////////////////////////////////////////////////////////////////////////
  1105. var RES;
  1106. (function (RES) {
  1107. /**
  1108. * @class RES.ResourceLoader
  1109. * @classdesc
  1110. * @extends egret.EventDispatcher
  1111. * @private
  1112. */
  1113. var ResourceLoader = (function (_super) {
  1114. __extends(ResourceLoader, _super);
  1115. /**
  1116. * 构造函数
  1117. * @method RES.ResourceLoader#constructor
  1118. */
  1119. function ResourceLoader() {
  1120. var _this = _super.call(this) || this;
  1121. /**
  1122. * 最大并发加载数
  1123. */
  1124. _this.thread = 2;
  1125. /**
  1126. * 正在加载的线程计数
  1127. */
  1128. _this.loadingCount = 0;
  1129. /**
  1130. * 一项加载结束回调函数。无论加载成功或者出错都将执行回调函数。示例:callBack(resItem:ResourceItem):void;
  1131. * @member {Function} RES.ResourceLoader#callBack
  1132. */
  1133. _this.callBack = null;
  1134. /**
  1135. * RES单例的引用
  1136. * @member {any} RES.ResourceLoader#resInstance
  1137. */
  1138. _this.resInstance = null;
  1139. /**
  1140. * 当前组加载的项总个数,key为groupName
  1141. */
  1142. _this.groupTotalDic = {};
  1143. /**
  1144. * 已经加载的项个数,key为groupName
  1145. */
  1146. _this.numLoadedDic = {};
  1147. /**
  1148. * 正在加载的组列表,key为groupName
  1149. */
  1150. _this.itemListDic = {};
  1151. /**
  1152. * 加载失败的组,key为groupName
  1153. */
  1154. _this.groupErrorDic = {};
  1155. _this.retryTimesDic = {};
  1156. _this.maxRetryTimes = 3;
  1157. _this.failedList = new Array();
  1158. /**
  1159. * 优先级队列,key为priority,value为groupName列表
  1160. */
  1161. _this.priorityQueue = {};
  1162. /**
  1163. * 延迟加载队列
  1164. */
  1165. _this.lazyLoadList = new Array();
  1166. /**
  1167. * 资源解析库字典类
  1168. */
  1169. _this.analyzerDic = {};
  1170. /**
  1171. * 当前应该加载同优先级队列的第几列
  1172. */
  1173. _this.queueIndex = 0;
  1174. return _this;
  1175. }
  1176. /**
  1177. * 检查指定的组是否正在加载中
  1178. * @method RES.ResourceLoader#isGroupInLoading
  1179. * @param groupName {string}
  1180. * @returns {boolean}
  1181. */
  1182. ResourceLoader.prototype.isGroupInLoading = function (groupName) {
  1183. return this.itemListDic[groupName] !== undefined;
  1184. };
  1185. /**
  1186. * 开始加载一组文件
  1187. * @method RES.ResourceLoader#loadGroup
  1188. * @param list {egret.Array<ResourceItem>} 加载项列表
  1189. * @param groupName {string} 组名
  1190. * @param priority {number} 加载优先级
  1191. */
  1192. ResourceLoader.prototype.loadGroup = function (list, groupName, priority) {
  1193. if (priority === void 0) { priority = 0; }
  1194. if (this.itemListDic[groupName] || !groupName)
  1195. return;
  1196. if (!list || list.length == 0) {
  1197. egret.$warn(3201, groupName);
  1198. var event_1 = new RES.ResourceEvent(RES.ResourceEvent.GROUP_LOAD_ERROR);
  1199. event_1.groupName = groupName;
  1200. this.dispatchEvent(event_1);
  1201. return;
  1202. }
  1203. if (this.priorityQueue[priority])
  1204. this.priorityQueue[priority].push(groupName);
  1205. else
  1206. this.priorityQueue[priority] = [groupName];
  1207. this.itemListDic[groupName] = list;
  1208. var length = list.length;
  1209. for (var i = 0; i < length; i++) {
  1210. var resItem = list[i];
  1211. resItem.groupName = groupName;
  1212. }
  1213. this.groupTotalDic[groupName] = list.length;
  1214. this.numLoadedDic[groupName] = 0;
  1215. this.next();
  1216. };
  1217. /**
  1218. * 加载一个文件
  1219. * @method RES.ResourceLoader#loadItem
  1220. * @param resItem {egret.ResourceItem} 要加载的项
  1221. */
  1222. ResourceLoader.prototype.loadItem = function (resItem) {
  1223. this.lazyLoadList.push(resItem);
  1224. resItem.groupName = "";
  1225. this.next();
  1226. };
  1227. /**
  1228. * 加载下一项
  1229. */
  1230. ResourceLoader.prototype.next = function () {
  1231. while (this.loadingCount < this.thread) {
  1232. var resItem = this.getOneResourceItem();
  1233. if (!resItem)
  1234. break;
  1235. this.loadingCount++;
  1236. if (resItem.loaded) {
  1237. this.onItemComplete(resItem);
  1238. }
  1239. else {
  1240. var analyzer = this.resInstance.$getAnalyzerByType(resItem.type);
  1241. analyzer.loadFile(resItem, this.onItemComplete, this);
  1242. }
  1243. }
  1244. };
  1245. /**
  1246. * 获取下一个待加载项
  1247. */
  1248. ResourceLoader.prototype.getOneResourceItem = function () {
  1249. if (this.failedList.length > 0)
  1250. return this.failedList.shift();
  1251. var maxPriority = Number.NEGATIVE_INFINITY;
  1252. for (var p in this.priorityQueue) {
  1253. maxPriority = Math.max(maxPriority, p);
  1254. }
  1255. var queue = this.priorityQueue[maxPriority];
  1256. if (!queue || queue.length == 0) {
  1257. if (this.lazyLoadList.length == 0)
  1258. return null;
  1259. //后请求的先加载,以便更快获取当前需要的资源
  1260. return this.lazyLoadList.pop();
  1261. }
  1262. var length = queue.length;
  1263. var list;
  1264. for (var i = 0; i < length; i++) {
  1265. if (this.queueIndex >= length)
  1266. this.queueIndex = 0;
  1267. list = this.itemListDic[queue[this.queueIndex]];
  1268. if (list.length > 0)
  1269. break;
  1270. this.queueIndex++;
  1271. }
  1272. if (list.length == 0)
  1273. return null;
  1274. return list.shift();
  1275. };
  1276. /**
  1277. * 加载结束
  1278. */
  1279. ResourceLoader.prototype.onItemComplete = function (resItem) {
  1280. this.loadingCount--;
  1281. var groupName = resItem.groupName;
  1282. if (!resItem.loaded) {
  1283. var times = this.retryTimesDic[resItem.name] || 1;
  1284. if (times > this.maxRetryTimes) {
  1285. delete this.retryTimesDic[resItem.name];
  1286. RES.ResourceEvent.dispatchResourceEvent(this.resInstance, RES.ResourceEvent.ITEM_LOAD_ERROR, groupName, resItem);
  1287. }
  1288. else {
  1289. this.retryTimesDic[resItem.name] = times + 1;
  1290. this.failedList.push(resItem);
  1291. this.next();
  1292. return;
  1293. }
  1294. }
  1295. if (groupName) {
  1296. this.numLoadedDic[groupName]++;
  1297. var itemsLoaded = this.numLoadedDic[groupName];
  1298. var itemsTotal = this.groupTotalDic[groupName];
  1299. if (!resItem.loaded) {
  1300. this.groupErrorDic[groupName] = true;
  1301. }
  1302. RES.ResourceEvent.dispatchResourceEvent(this.resInstance, RES.ResourceEvent.GROUP_PROGRESS, groupName, resItem, itemsLoaded, itemsTotal);
  1303. if (itemsLoaded == itemsTotal) {
  1304. var groupError = this.groupErrorDic[groupName];
  1305. this.removeGroupName(groupName);
  1306. delete this.groupTotalDic[groupName];
  1307. delete this.numLoadedDic[groupName];
  1308. delete this.itemListDic[groupName];
  1309. delete this.groupErrorDic[groupName];
  1310. if (groupError) {
  1311. RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.GROUP_LOAD_ERROR, groupName);
  1312. }
  1313. else {
  1314. RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.GROUP_COMPLETE, groupName);
  1315. }
  1316. }
  1317. }
  1318. else {
  1319. this.callBack.call(this.resInstance, resItem);
  1320. }
  1321. this.next();
  1322. };
  1323. /**
  1324. * 从优先级队列中移除指定的组名
  1325. */
  1326. ResourceLoader.prototype.removeGroupName = function (groupName) {
  1327. for (var p in this.priorityQueue) {
  1328. var queue = this.priorityQueue[p];
  1329. var index = 0;
  1330. var found = false;
  1331. var length_1 = queue.length;
  1332. for (var i = 0; i < length_1; i++) {
  1333. var name_1 = queue[i];
  1334. if (name_1 == groupName) {
  1335. queue.splice(index, 1);
  1336. found = true;
  1337. break;
  1338. }
  1339. index++;
  1340. }
  1341. if (found) {
  1342. if (queue.length == 0) {
  1343. delete this.priorityQueue[p];
  1344. }
  1345. break;
  1346. }
  1347. }
  1348. };
  1349. return ResourceLoader;
  1350. }(egret.EventDispatcher));
  1351. RES.ResourceLoader = ResourceLoader;
  1352. __reflect(ResourceLoader.prototype, "RES.ResourceLoader");
  1353. })(RES || (RES = {}));
  1354. //////////////////////////////////////////////////////////////////////////////////////
  1355. //
  1356. // Copyright (c) 2014-present, Egret Technology.
  1357. // All rights reserved.
  1358. // Redistribution and use in source and binary forms, with or without
  1359. // modification, are permitted provided that the following conditions are met:
  1360. //
  1361. // * Redistributions of source code must retain the above copyright
  1362. // notice, this list of conditions and the following disclaimer.
  1363. // * Redistributions in binary form must reproduce the above copyright
  1364. // notice, this list of conditions and the following disclaimer in the
  1365. // documentation and/or other materials provided with the distribution.
  1366. // * Neither the name of the Egret nor the
  1367. // names of its contributors may be used to endorse or promote products
  1368. // derived from this software without specific prior written permission.
  1369. //
  1370. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1371. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1372. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1373. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1374. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1375. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1376. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1377. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1378. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1379. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1380. //
  1381. //////////////////////////////////////////////////////////////////////////////////////
  1382. var RES;
  1383. (function (RES) {
  1384. /**
  1385. * @private
  1386. */
  1387. var FontAnalyzer = (function (_super) {
  1388. __extends(FontAnalyzer, _super);
  1389. function FontAnalyzer() {
  1390. return _super.call(this) || this;
  1391. }
  1392. FontAnalyzer.prototype.analyzeConfig = function (resItem, data) {
  1393. var name = resItem.name;
  1394. var config;
  1395. var imageUrl = "";
  1396. try {
  1397. var str = data;
  1398. config = JSON.parse(str);
  1399. }
  1400. catch (e) {
  1401. }
  1402. if (config) {
  1403. imageUrl = this.getRelativePath(resItem.url, config["file"]);
  1404. }
  1405. else {
  1406. config = data;
  1407. imageUrl = this.getTexturePath(resItem.url, config);
  1408. }
  1409. this.sheetMap[name] = config;
  1410. return imageUrl;
  1411. };
  1412. FontAnalyzer.prototype.analyzeBitmap = function (resItem, texture) {
  1413. var name = resItem.name;
  1414. if (this.fileDic[name] || !texture) {
  1415. return;
  1416. }
  1417. var config = this.sheetMap[name];
  1418. delete this.sheetMap[name];
  1419. var bitmapFont = new egret.BitmapFont(texture, config);
  1420. this.fileDic[name] = bitmapFont;
  1421. };
  1422. FontAnalyzer.prototype.getTexturePath = function (url, fntText) {
  1423. var file = "";
  1424. var lines = fntText.split("\n");
  1425. var pngLine = lines[2];
  1426. var index = pngLine.indexOf("file=\"");
  1427. if (index != -1) {
  1428. pngLine = pngLine.substring(index + 6);
  1429. index = pngLine.indexOf("\"");
  1430. file = pngLine.substring(0, index);
  1431. }
  1432. url = url.split("\\").join("/");
  1433. index = url.lastIndexOf("/");
  1434. if (index != -1) {
  1435. url = url.substring(0, index + 1) + file;
  1436. }
  1437. else {
  1438. url = file;
  1439. }
  1440. return url;
  1441. };
  1442. FontAnalyzer.prototype.onResourceDestroy = function (font) {
  1443. if (font) {
  1444. font.dispose();
  1445. }
  1446. };
  1447. return FontAnalyzer;
  1448. }(RES.SheetAnalyzer));
  1449. RES.FontAnalyzer = FontAnalyzer;
  1450. __reflect(FontAnalyzer.prototype, "RES.FontAnalyzer");
  1451. })(RES || (RES = {}));
  1452. //////////////////////////////////////////////////////////////////////////////////////
  1453. //
  1454. // Copyright (c) 2014-present, Egret Technology.
  1455. // All rights reserved.
  1456. // Redistribution and use in source and binary forms, with or without
  1457. // modification, are permitted provided that the following conditions are met:
  1458. //
  1459. // * Redistributions of source code must retain the above copyright
  1460. // notice, this list of conditions and the following disclaimer.
  1461. // * Redistributions in binary form must reproduce the above copyright
  1462. // notice, this list of conditions and the following disclaimer in the
  1463. // documentation and/or other materials provided with the distribution.
  1464. // * Neither the name of the Egret nor the
  1465. // names of its contributors may be used to endorse or promote products
  1466. // derived from this software without specific prior written permission.
  1467. //
  1468. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1469. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1470. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1471. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1472. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1473. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1474. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1475. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1476. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1477. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1478. //
  1479. //////////////////////////////////////////////////////////////////////////////////////
  1480. var RES;
  1481. (function (RES) {
  1482. /**
  1483. * @private
  1484. */
  1485. var SoundAnalyzer = (function (_super) {
  1486. __extends(SoundAnalyzer, _super);
  1487. /**
  1488. * 构造函数
  1489. */
  1490. function SoundAnalyzer() {
  1491. var _this = _super.call(this) || this;
  1492. /**
  1493. * 字节流数据缓存字典
  1494. */
  1495. _this.soundDic = {};
  1496. /**
  1497. * 加载项字典
  1498. */
  1499. _this.resItemDic = [];
  1500. return _this;
  1501. }
  1502. /**
  1503. * @inheritDoc
  1504. */
  1505. SoundAnalyzer.prototype.loadFile = function (resItem, callBack, thisObject) {
  1506. if (this.soundDic[resItem.name]) {
  1507. callBack.call(thisObject, resItem);
  1508. return;
  1509. }
  1510. var sound = new egret.Sound();
  1511. sound.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
  1512. sound.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
  1513. this.resItemDic[sound.$hashCode] = { item: resItem, func: callBack, thisObject: thisObject };
  1514. sound.load(RES.$getVirtualUrl(resItem.url));
  1515. if (resItem.data) {
  1516. sound.type = resItem.data.soundType;
  1517. }
  1518. };
  1519. /**
  1520. * 一项加载结束
  1521. */
  1522. SoundAnalyzer.prototype.onLoadFinish = function (event) {
  1523. var sound = (event.$target);
  1524. sound.removeEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
  1525. sound.removeEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
  1526. var data = this.resItemDic[sound.$hashCode];
  1527. delete this.resItemDic[sound.$hashCode];
  1528. var resItem = data.item;
  1529. var compFunc = data.func;
  1530. resItem.loaded = (event.$type == egret.Event.COMPLETE);
  1531. if (resItem.loaded) {
  1532. this.analyzeData(resItem, sound);
  1533. }
  1534. compFunc.call(data.thisObject, resItem);
  1535. };
  1536. /**
  1537. * 解析并缓存加载成功的数据
  1538. */
  1539. SoundAnalyzer.prototype.analyzeData = function (resItem, data) {
  1540. var name = resItem.name;
  1541. if (this.soundDic[name] || !data) {
  1542. return;
  1543. }
  1544. this.soundDic[name] = data;
  1545. };
  1546. /**
  1547. * @inheritDoc
  1548. */
  1549. SoundAnalyzer.prototype.getRes = function (name) {
  1550. return this.soundDic[name];
  1551. };
  1552. /**
  1553. * @inheritDoc
  1554. */
  1555. SoundAnalyzer.prototype.hasRes = function (name) {
  1556. return !!this.getRes(name);
  1557. };
  1558. /**
  1559. * @inheritDoc
  1560. */
  1561. SoundAnalyzer.prototype.destroyRes = function (name) {
  1562. if (this.soundDic[name]) {
  1563. delete this.soundDic[name];
  1564. return true;
  1565. }
  1566. return false;
  1567. };
  1568. return SoundAnalyzer;
  1569. }(RES.AnalyzerBase));
  1570. RES.SoundAnalyzer = SoundAnalyzer;
  1571. __reflect(SoundAnalyzer.prototype, "RES.SoundAnalyzer");
  1572. })(RES || (RES = {}));
  1573. //////////////////////////////////////////////////////////////////////////////////////
  1574. //
  1575. // Copyright (c) 2014-present, Egret Technology.
  1576. // All rights reserved.
  1577. // Redistribution and use in source and binary forms, with or without
  1578. // modification, are permitted provided that the following conditions are met:
  1579. //
  1580. // * Redistributions of source code must retain the above copyright
  1581. // notice, this list of conditions and the following disclaimer.
  1582. // * Redistributions in binary form must reproduce the above copyright
  1583. // notice, this list of conditions and the following disclaimer in the
  1584. // documentation and/or other materials provided with the distribution.
  1585. // * Neither the name of the Egret nor the
  1586. // names of its contributors may be used to endorse or promote products
  1587. // derived from this software without specific prior written permission.
  1588. //
  1589. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1590. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1591. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1592. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1593. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1594. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1595. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1596. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1597. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1598. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1599. //
  1600. //////////////////////////////////////////////////////////////////////////////////////
  1601. var RES;
  1602. (function (RES) {
  1603. /**
  1604. * @private
  1605. */
  1606. var XMLAnalyzer = (function (_super) {
  1607. __extends(XMLAnalyzer, _super);
  1608. function XMLAnalyzer() {
  1609. var _this = _super.call(this) || this;
  1610. _this._dataFormat = egret.HttpResponseType.TEXT;
  1611. return _this;
  1612. }
  1613. /**
  1614. * 解析并缓存加载成功的数据
  1615. */
  1616. XMLAnalyzer.prototype.analyzeData = function (resItem, data) {
  1617. var name = resItem.name;
  1618. if (this.fileDic[name] || !data) {
  1619. return;
  1620. }
  1621. try {
  1622. var xmlStr = data;
  1623. var xml = egret.XML.parse(xmlStr);
  1624. this.fileDic[name] = xml;
  1625. }
  1626. catch (e) {
  1627. }
  1628. };
  1629. return XMLAnalyzer;
  1630. }(RES.BinAnalyzer));
  1631. RES.XMLAnalyzer = XMLAnalyzer;
  1632. __reflect(XMLAnalyzer.prototype, "RES.XMLAnalyzer");
  1633. })(RES || (RES = {}));
  1634. //////////////////////////////////////////////////////////////////////////////////////
  1635. //
  1636. // Copyright (c) 2014-present, Egret Technology.
  1637. // All rights reserved.
  1638. // Redistribution and use in source and binary forms, with or without
  1639. // modification, are permitted provided that the following conditions are met:
  1640. //
  1641. // * Redistributions of source code must retain the above copyright
  1642. // notice, this list of conditions and the following disclaimer.
  1643. // * Redistributions in binary form must reproduce the above copyright
  1644. // notice, this list of conditions and the following disclaimer in the
  1645. // documentation and/or other materials provided with the distribution.
  1646. // * Neither the name of the Egret nor the
  1647. // names of its contributors may be used to endorse or promote products
  1648. // derived from this software without specific prior written permission.
  1649. //
  1650. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1651. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1652. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1653. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1654. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1655. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1656. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1657. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1658. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1659. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1660. //
  1661. //////////////////////////////////////////////////////////////////////////////////////
  1662. var RES;
  1663. (function (RES) {
  1664. /**
  1665. * @private
  1666. */
  1667. var ImageAnalyzer = (function (_super) {
  1668. __extends(ImageAnalyzer, _super);
  1669. /**
  1670. * 构造函数
  1671. */
  1672. function ImageAnalyzer() {
  1673. var _this = _super.call(this) || this;
  1674. /**
  1675. * 字节流数据缓存字典
  1676. */
  1677. _this.fileDic = {};
  1678. /**
  1679. * 加载项字典
  1680. */
  1681. _this.resItemDic = [];
  1682. /**
  1683. * Loader对象池
  1684. */
  1685. _this.recycler = [];
  1686. return _this;
  1687. }
  1688. /**
  1689. * @inheritDoc
  1690. */
  1691. ImageAnalyzer.prototype.loadFile = function (resItem, compFunc, thisObject) {
  1692. if (this.fileDic[resItem.name]) {
  1693. compFunc.call(thisObject, resItem);
  1694. return;
  1695. }
  1696. var loader = this.getLoader();
  1697. this.resItemDic[loader.$hashCode] = { item: resItem, func: compFunc, thisObject: thisObject };
  1698. loader.load(RES.$getVirtualUrl(resItem.url));
  1699. };
  1700. /**
  1701. * 获取一个Loader对象
  1702. */
  1703. ImageAnalyzer.prototype.getLoader = function () {
  1704. var loader = this.recycler.pop();
  1705. if (!loader) {
  1706. loader = new egret.ImageLoader();
  1707. loader.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
  1708. loader.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
  1709. }
  1710. return loader;
  1711. };
  1712. /**
  1713. * 一项加载结束
  1714. */
  1715. ImageAnalyzer.prototype.onLoadFinish = function (event) {
  1716. var request = (event.$target);
  1717. var data = this.resItemDic[request.$hashCode];
  1718. delete this.resItemDic[request.$hashCode];
  1719. var resItem = data.item;
  1720. var compFunc = data.func;
  1721. resItem.loaded = (event.$type == egret.Event.COMPLETE);
  1722. if (resItem.loaded) {
  1723. var texture = new egret.Texture();
  1724. texture._setBitmapData(request.data);
  1725. this.analyzeData(resItem, texture);
  1726. }
  1727. this.recycler.push(request);
  1728. compFunc.call(data.thisObject, resItem);
  1729. };
  1730. /**
  1731. * 解析并缓存加载成功的数据
  1732. */
  1733. ImageAnalyzer.prototype.analyzeData = function (resItem, texture) {
  1734. var name = resItem.name;
  1735. if (this.fileDic[name] || !texture) {
  1736. return;
  1737. }
  1738. this.fileDic[name] = texture;
  1739. var config = resItem.data;
  1740. if (config && config["scale9grid"]) {
  1741. var str = config["scale9grid"];
  1742. var list = str.split(",");
  1743. texture["scale9Grid"] = new egret.Rectangle(parseInt(list[0]), parseInt(list[1]), parseInt(list[2]), parseInt(list[3]));
  1744. }
  1745. };
  1746. /**
  1747. * @inheritDoc
  1748. */
  1749. ImageAnalyzer.prototype.getRes = function (name) {
  1750. return this.fileDic[name];
  1751. };
  1752. /**
  1753. * @inheritDoc
  1754. */
  1755. ImageAnalyzer.prototype.hasRes = function (name) {
  1756. var res = this.getRes(name);
  1757. return res != null;
  1758. };
  1759. /**
  1760. * @inheritDoc
  1761. */
  1762. ImageAnalyzer.prototype.destroyRes = function (name) {
  1763. if (this.fileDic[name]) {
  1764. this.onResourceDestroy(this.fileDic[name]);
  1765. delete this.fileDic[name];
  1766. return true;
  1767. }
  1768. return false;
  1769. };
  1770. ImageAnalyzer.prototype.onResourceDestroy = function (texture) {
  1771. texture.dispose();
  1772. };
  1773. return ImageAnalyzer;
  1774. }(RES.AnalyzerBase));
  1775. RES.ImageAnalyzer = ImageAnalyzer;
  1776. __reflect(ImageAnalyzer.prototype, "RES.ImageAnalyzer");
  1777. })(RES || (RES = {}));
  1778. //////////////////////////////////////////////////////////////////////////////////////
  1779. //
  1780. // Copyright (c) 2014-present, Egret Technology.
  1781. // All rights reserved.
  1782. // Redistribution and use in source and binary forms, with or without
  1783. // modification, are permitted provided that the following conditions are met:
  1784. //
  1785. // * Redistributions of source code must retain the above copyright
  1786. // notice, this list of conditions and the following disclaimer.
  1787. // * Redistributions in binary form must reproduce the above copyright
  1788. // notice, this list of conditions and the following disclaimer in the
  1789. // documentation and/or other materials provided with the distribution.
  1790. // * Neither the name of the Egret nor the
  1791. // names of its contributors may be used to endorse or promote products
  1792. // derived from this software without specific prior written permission.
  1793. //
  1794. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1795. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1796. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1797. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1798. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1799. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1800. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1801. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1802. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1803. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1804. //
  1805. //////////////////////////////////////////////////////////////////////////////////////
  1806. var RES;
  1807. (function (RES) {
  1808. /**
  1809. * @class RES.ResourceConfig
  1810. * @classdesc
  1811. * @private
  1812. */
  1813. var ResourceConfig = (function () {
  1814. function ResourceConfig() {
  1815. /**
  1816. * 一级键名字典
  1817. */
  1818. this.keyMap = {};
  1819. /**
  1820. * 加载组字典
  1821. */
  1822. this.groupDic = {};
  1823. RES["configInstance"] = this;
  1824. }
  1825. /**
  1826. * 根据组名获取组加载项列表
  1827. * @method RES.ResourceConfig#getGroupByName
  1828. * @param name {string} 组名
  1829. * @returns {Array<egret.ResourceItem>}
  1830. */
  1831. ResourceConfig.prototype.getGroupByName = function (name) {
  1832. var group = new Array();
  1833. if (!this.groupDic[name])
  1834. return group;
  1835. var list = this.groupDic[name];
  1836. var length = list.length;
  1837. for (var i = 0; i < length; i++) {
  1838. var obj = list[i];
  1839. group.push(this.parseResourceItem(obj));
  1840. }
  1841. return group;
  1842. };
  1843. /**
  1844. * 根据组名获取原始的组加载项列表
  1845. * @method RES.ResourceConfig#getRawGroupByName
  1846. * @param name {string} 组名
  1847. * @returns {any[]}
  1848. */
  1849. ResourceConfig.prototype.getRawGroupByName = function (name) {
  1850. if (this.groupDic[name])
  1851. return this.groupDic[name];
  1852. return [];
  1853. };
  1854. /**
  1855. * 创建自定义的加载资源组,注意:此方法仅在资源配置文件加载完成后执行才有效。
  1856. * 可以监听ResourceEvent.CONFIG_COMPLETE事件来确认配置加载完成。
  1857. * @method RES.ResourceConfig#createGroup
  1858. * @param name {string} 要创建的加载资源组的组名
  1859. * @param keys {egret.string[]} 要包含的键名列表,key对应配置文件里的name属性或sbuKeys属性的一项或一个资源组名。
  1860. * @param override {boolean} 是否覆盖已经存在的同名资源组,默认false。
  1861. * @returns {boolean}
  1862. */
  1863. ResourceConfig.prototype.createGroup = function (name, keys, override) {
  1864. if (override === void 0) { override = false; }
  1865. if ((!override && this.groupDic[name]) || !keys || keys.length == 0)
  1866. return false;
  1867. var groupDic = this.groupDic;
  1868. var group = [];
  1869. var length = keys.length;
  1870. for (var i = 0; i < length; i++) {
  1871. var key = keys[i];
  1872. var g = groupDic[key];
  1873. if (g) {
  1874. var len = g.length;
  1875. for (var j = 0; j < len; j++) {
  1876. var item = g[j];
  1877. if (group.indexOf(item) == -1)
  1878. group.push(item);
  1879. }
  1880. }
  1881. else {
  1882. var item = this.keyMap[key];
  1883. if (item) {
  1884. if (group.indexOf(item) == -1)
  1885. group.push(item);
  1886. }
  1887. else {
  1888. egret.$warn(3200, key);
  1889. }
  1890. }
  1891. }
  1892. if (group.length == 0)
  1893. return false;
  1894. this.groupDic[name] = group;
  1895. return true;
  1896. };
  1897. /**
  1898. * 解析一个配置文件
  1899. * @method RES.ResourceConfig#parseConfig
  1900. * @param data {any} 配置文件数据
  1901. * @param folder {string} 加载项的路径前缀。
  1902. */
  1903. ResourceConfig.prototype.parseConfig = function (data, folder) {
  1904. if (!data)
  1905. return;
  1906. var resources = data["resources"];
  1907. if (resources) {
  1908. var length_2 = resources.length;
  1909. for (var i = 0; i < length_2; i++) {
  1910. var item = resources[i];
  1911. var url = item.url;
  1912. if (url && url.indexOf("://") == -1)
  1913. item.url = folder + url;
  1914. this.addItemToKeyMap(item);
  1915. }
  1916. }
  1917. var groups = data["groups"];
  1918. if (groups) {
  1919. var length_3 = groups.length;
  1920. for (var i = 0; i < length_3; i++) {
  1921. var group = groups[i];
  1922. var list = [];
  1923. var keys = group.keys.split(",");
  1924. var l = keys.length;
  1925. for (var j = 0; j < l; j++) {
  1926. var name_2 = keys[j].trim();
  1927. var item = this.keyMap[name_2];
  1928. if (item && list.indexOf(item) == -1) {
  1929. list.push(item);
  1930. }
  1931. }
  1932. this.groupDic[group.name] = list;
  1933. }
  1934. }
  1935. };
  1936. /**
  1937. * 添加一个二级键名到配置列表。
  1938. * @method RES.ResourceConfig#addSubkey
  1939. * @param subkey {string} 要添加的二级键名
  1940. * @param name {string} 二级键名所属的资源name属性
  1941. */
  1942. ResourceConfig.prototype.addSubkey = function (subkey, name) {
  1943. var item = this.keyMap[name];
  1944. if (item && !this.keyMap[subkey]) {
  1945. this.keyMap[subkey] = item;
  1946. }
  1947. };
  1948. /**
  1949. * 添加一个加载项数据到列表
  1950. */
  1951. ResourceConfig.prototype.addItemToKeyMap = function (item) {
  1952. if (!this.keyMap[item.name])
  1953. this.keyMap[item.name] = item;
  1954. if (item.hasOwnProperty("subkeys")) {
  1955. var subkeys = (item.subkeys).split(",");
  1956. item.subkeys = subkeys;
  1957. var length_4 = subkeys.length;
  1958. for (var i = 0; i < length_4; i++) {
  1959. var key = subkeys[i];
  1960. if (this.keyMap[key] != null)
  1961. continue;
  1962. this.keyMap[key] = item;
  1963. }
  1964. }
  1965. };
  1966. /**
  1967. * 获取加载项的name属性
  1968. * @method RES.ResourceConfig#getType
  1969. * @param key {string} 对应配置文件里的name属性或sbuKeys属性的一项。
  1970. * @returns {string}
  1971. */
  1972. ResourceConfig.prototype.getName = function (key) {
  1973. var data = this.keyMap[key];
  1974. return data ? data.name : "";
  1975. };
  1976. /**
  1977. * 获取加载项类型。
  1978. * @method RES.ResourceConfig#getType
  1979. * @param key {string} 对应配置文件里的name属性或sbuKeys属性的一项。
  1980. * @returns {string}
  1981. */
  1982. ResourceConfig.prototype.getType = function (key) {
  1983. var data = this.keyMap[key];
  1984. return data ? data.type : "";
  1985. };
  1986. ResourceConfig.prototype.getRawResourceItem = function (key) {
  1987. return this.keyMap[key];
  1988. };
  1989. /**
  1990. * 获取加载项信息对象
  1991. * @method RES.ResourceConfig#getResourceItem
  1992. * @param key {string} 对应配置文件里的key属性或sbuKeys属性的一项。
  1993. * @returns {egret.ResourceItem}
  1994. */
  1995. ResourceConfig.prototype.getResourceItem = function (key) {
  1996. var data = this.keyMap[key];
  1997. if (data)
  1998. return this.parseResourceItem(data);
  1999. return null;
  2000. };
  2001. /**
  2002. * 转换Object数据为ResourceItem对象
  2003. */
  2004. ResourceConfig.prototype.parseResourceItem = function (data) {
  2005. var resItem = new RES.ResourceItem(data.name, data.url, data.type);
  2006. resItem.data = data;
  2007. return resItem;
  2008. };
  2009. return ResourceConfig;
  2010. }());
  2011. RES.ResourceConfig = ResourceConfig;
  2012. __reflect(ResourceConfig.prototype, "RES.ResourceConfig");
  2013. })(RES || (RES = {}));
  2014. //////////////////////////////////////////////////////////////////////////////////////
  2015. //
  2016. // Copyright (c) 2014-present, Egret Technology.
  2017. // All rights reserved.
  2018. // Redistribution and use in source and binary forms, with or without
  2019. // modification, are permitted provided that the following conditions are met:
  2020. //
  2021. // * Redistributions of source code must retain the above copyright
  2022. // notice, this list of conditions and the following disclaimer.
  2023. // * Redistributions in binary form must reproduce the above copyright
  2024. // notice, this list of conditions and the following disclaimer in the
  2025. // documentation and/or other materials provided with the distribution.
  2026. // * Neither the name of the Egret nor the
  2027. // names of its contributors may be used to endorse or promote products
  2028. // derived from this software without specific prior written permission.
  2029. //
  2030. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2031. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2032. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2033. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2034. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2035. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2036. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2037. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2038. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2039. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2040. //
  2041. //////////////////////////////////////////////////////////////////////////////////////
  2042. var RES;
  2043. (function (RES) {
  2044. var native;
  2045. (function (native) {
  2046. /**
  2047. * @private
  2048. */
  2049. var NativeVersionController = (function () {
  2050. function NativeVersionController() {
  2051. this._versionInfo = {};
  2052. this._versionPath = "";
  2053. this._localFileArr = [];
  2054. }
  2055. NativeVersionController.prototype.fetchVersion = function (callback) {
  2056. if (true) {
  2057. callback.onSuccess(null);
  2058. return;
  2059. }
  2060. var self = this;
  2061. self._versionPath = "all.manifest";
  2062. self._versionInfo = self.getLocalData(self._versionPath);
  2063. if (self._versionInfo == null) {
  2064. egret.callLater(function () {
  2065. callback.onFail(1, null);
  2066. }, self);
  2067. return;
  2068. }
  2069. var count = 0;
  2070. var loadOver = function (paths) {
  2071. if (paths) {
  2072. for (var i = 0; i < paths.length; i++) {
  2073. if (paths[i] && paths[i] != "") {
  2074. self._localFileArr.push("resource/" + paths[i]);
  2075. }
  2076. }
  2077. }
  2078. count++;
  2079. if (count == 2) {
  2080. callback.onSuccess(null);
  2081. }
  2082. };
  2083. self.getList(loadOver, "assets", "resource");
  2084. self.getList(loadOver, "update", "resource");
  2085. };
  2086. NativeVersionController.prototype.getList = function (callback, type, root) {
  2087. if (root === void 0) { root = ""; }
  2088. var promise = egret.PromiseObject.create();
  2089. promise.onSuccessFunc = function (paths) {
  2090. callback(paths);
  2091. };
  2092. promise.onErrorFunc = function () {
  2093. console.error("list files error");
  2094. };
  2095. if (type == "assets") {
  2096. egret_native.Game.listResource(root, promise);
  2097. }
  2098. else {
  2099. egret_native.Game.listUpdate(root, promise);
  2100. }
  2101. };
  2102. /**
  2103. * 获取所有有变化的文件
  2104. * @returns {any[]}
  2105. */
  2106. NativeVersionController.prototype.getChangeList = function () {
  2107. var temp = [];
  2108. var localFileArr = this._localFileArr;
  2109. for (var key in this._versionInfo) {
  2110. if (localFileArr.indexOf(this.getVirtualUrl(key)) < 0) {
  2111. temp.push({ "url": this.getVirtualUrl(key), "size": this._versionInfo[key]["s"] });
  2112. }
  2113. }
  2114. return temp;
  2115. };
  2116. NativeVersionController.prototype.getVirtualUrl = function (url) {
  2117. if (true) {
  2118. return url;
  2119. }
  2120. if (this._versionInfo && this._versionInfo[url]) {
  2121. return "resource/" + this._versionInfo[url]["v"].substring(0, 2) + "/" + this._versionInfo[url]["v"] + "_" + this._versionInfo[url]["s"] + "." + url.substring(url.lastIndexOf(".") + 1);
  2122. }
  2123. else {
  2124. return url;
  2125. }
  2126. };
  2127. NativeVersionController.prototype.getLocalData = function (filePath) {
  2128. if (egret_native.readUpdateFileSync && egret_native.readResourceFileSync) {
  2129. //先取更新目录
  2130. var content = egret_native.readUpdateFileSync(filePath);
  2131. if (content != null) {
  2132. return JSON.parse(content);
  2133. }
  2134. //再取资源目录
  2135. content = egret_native.readResourceFileSync(filePath);
  2136. if (content != null) {
  2137. return JSON.parse(content);
  2138. }
  2139. }
  2140. return null;
  2141. };
  2142. return NativeVersionController;
  2143. }());
  2144. native.NativeVersionController = NativeVersionController;
  2145. __reflect(NativeVersionController.prototype, "RES.native.NativeVersionController", ["RES.VersionController", "RES.IVersionController"]);
  2146. if (egret.Capabilities.runtimeType == egret.RuntimeType.NATIVE) {
  2147. RES.VersionController = NativeVersionController;
  2148. }
  2149. })(native = RES.native || (RES.native = {}));
  2150. })(RES || (RES = {}));
  2151. //////////////////////////////////////////////////////////////////////////////////////
  2152. //
  2153. // Copyright (c) 2014-present, Egret Technology.
  2154. // All rights reserved.
  2155. // Redistribution and use in source and binary forms, with or without
  2156. // modification, are permitted provided that the following conditions are met:
  2157. //
  2158. // * Redistributions of source code must retain the above copyright
  2159. // notice, this list of conditions and the following disclaimer.
  2160. // * Redistributions in binary form must reproduce the above copyright
  2161. // notice, this list of conditions and the following disclaimer in the
  2162. // documentation and/or other materials provided with the distribution.
  2163. // * Neither the name of the Egret nor the
  2164. // names of its contributors may be used to endorse or promote products
  2165. // derived from this software without specific prior written permission.
  2166. //
  2167. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2168. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2169. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2170. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2171. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2172. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2173. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2174. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2175. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2176. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2177. //
  2178. //////////////////////////////////////////////////////////////////////////////////////
  2179. var RES;
  2180. (function (RES) {
  2181. var web;
  2182. (function (web) {
  2183. /**
  2184. * @private
  2185. */
  2186. var Html5VersionController = (function (_super) {
  2187. __extends(Html5VersionController, _super);
  2188. function Html5VersionController() {
  2189. var _this = _super.call(this) || this;
  2190. _this._versionInfo = {};
  2191. return _this;
  2192. }
  2193. Html5VersionController.prototype.fetchVersion = function (callback) {
  2194. callback.onSuccess(null);
  2195. return;
  2196. /*
  2197. todo
  2198. let self = this;
  2199. let virtualUrl:string = "all.manifest";
  2200. let httpLoader:egret.HttpRequest = new egret.HttpRequest();
  2201. httpLoader.addEventListener(egret.Event.COMPLETE, onLoadComplete, this);
  2202. httpLoader.addEventListener(egret.IOErrorEvent.IO_ERROR, onError, this);
  2203. httpLoader.open(virtualUrl + "?r=" + Date.now(), "get");
  2204. httpLoader.send();
  2205. function onError(event:egret.IOErrorEvent) {
  2206. removeListeners();
  2207. self.dispatchEvent(event);
  2208. }
  2209. function onLoadComplete() {
  2210. removeListeners();
  2211. self._versionInfo = JSON.parse(httpLoader.response);
  2212. window.setTimeout(function () {
  2213. self.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
  2214. }, 0);
  2215. }
  2216. function removeListeners():void {
  2217. httpLoader.removeEventListener(egret.Event.COMPLETE, onLoadComplete, self);
  2218. httpLoader.removeEventListener(egret.IOErrorEvent.IO_ERROR, onError, self);
  2219. }
  2220. */
  2221. };
  2222. /**
  2223. * 获取所有有变化的文件
  2224. * @returns {any[]}
  2225. */
  2226. Html5VersionController.prototype.getChangeList = function () {
  2227. return [];
  2228. };
  2229. Html5VersionController.prototype.getVirtualUrl = function (url) {
  2230. return url;
  2231. /*
  2232. todo
  2233. if (DEBUG) {
  2234. return url;
  2235. }
  2236. if (this._versionInfo && this._versionInfo[url]) {
  2237. return "resource/" + this._versionInfo[url]["v"].substring(0, 2) + "/" + this._versionInfo[url]["v"] + "_" + this._versionInfo[url]["s"] + "." + url.substring(url.lastIndexOf(".") + 1);
  2238. }
  2239. else {
  2240. return url;
  2241. }
  2242. */
  2243. };
  2244. return Html5VersionController;
  2245. }(egret.EventDispatcher));
  2246. web.Html5VersionController = Html5VersionController;
  2247. __reflect(Html5VersionController.prototype, "RES.web.Html5VersionController", ["RES.VersionController", "RES.IVersionController"]);
  2248. if (egret.Capabilities.runtimeType == egret.RuntimeType.WEB) {
  2249. RES.VersionController = Html5VersionController;
  2250. }
  2251. })(web = RES.web || (RES.web = {}));
  2252. })(RES || (RES = {}));
  2253. //////////////////////////////////////////////////////////////////////////////////////
  2254. //
  2255. // Copyright (c) 2014-present, Egret Technology.
  2256. // All rights reserved.
  2257. // Redistribution and use in source and binary forms, with or without
  2258. // modification, are permitted provided that the following conditions are met:
  2259. //
  2260. // * Redistributions of source code must retain the above copyright
  2261. // notice, this list of conditions and the following disclaimer.
  2262. // * Redistributions in binary form must reproduce the above copyright
  2263. // notice, this list of conditions and the following disclaimer in the
  2264. // documentation and/or other materials provided with the distribution.
  2265. // * Neither the name of the Egret nor the
  2266. // names of its contributors may be used to endorse or promote products
  2267. // derived from this software without specific prior written permission.
  2268. //
  2269. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2270. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2271. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2272. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2273. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2274. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2275. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2276. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2277. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2278. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2279. //
  2280. //////////////////////////////////////////////////////////////////////////////////////
  2281. /// <reference path="core/ResourceItem.ts" />
  2282. /// <reference path="core/ResourceConfig.ts" />
  2283. /// <reference path="core/ResourceLoader.ts" />
  2284. /// <reference path="events/ResourceEvent.ts" />
  2285. /// <reference path="analyzer/BinAnalyzer.ts" />
  2286. /// <reference path="analyzer/ImageAnalyzer.ts" />
  2287. /// <reference path="analyzer/TextAnalyzer.ts" />
  2288. /// <reference path="analyzer/JsonAnalyzer.ts" />
  2289. /// <reference path="analyzer/SheetAnalyzer.ts" />
  2290. /// <reference path="analyzer/FontAnalyzer.ts" />
  2291. /// <reference path="analyzer/SoundAnalyzer.ts" />
  2292. /// <reference path="analyzer/XMLAnalyzer.ts" />
  2293. /// <reference path="version/IVersionController.ts" />
  2294. /// <reference path="version/HTML5VersionController.ts" />
  2295. /// <reference path="version/NativeVersionController.ts" />
  2296. var RES;
  2297. (function (RES) {
  2298. /**
  2299. * @language en_US
  2300. * Conduct mapping injection with class definition as the value.
  2301. * @param type Injection type.
  2302. * @param analyzerClass Injection type classes need to be resolved.
  2303. * @version Egret 2.4
  2304. * @platform Web,Native
  2305. * @includeExample extension/resource/Resource.ts
  2306. */
  2307. /**
  2308. * @language zh_CN
  2309. * 以类定义为值进行映射注入。
  2310. * @param type 注入的类型。
  2311. * @param analyzerClass 注入类型需要解析的类。
  2312. * @version Egret 2.4
  2313. * @platform Web,Native
  2314. * @includeExample extension/resource/Resource.ts
  2315. */
  2316. function registerAnalyzer(type, analyzerClass) {
  2317. instance.registerAnalyzer(type, analyzerClass);
  2318. }
  2319. RES.registerAnalyzer = registerAnalyzer;
  2320. /**
  2321. * @language en_US
  2322. * Get mapping injection.
  2323. * @param type Injection type.
  2324. * @version Egret 3.2.6
  2325. * @platform Web,Native
  2326. * @includeExample extension/resource/Resource.ts
  2327. */
  2328. /**
  2329. * @language zh_CN
  2330. * 获取映射注入。
  2331. * @param type 注入的类型。
  2332. * @version Egret 3.2.6
  2333. * @platform Web,Native
  2334. * @includeExample extension/resource/Resource.ts
  2335. */
  2336. function getAnalyzer(type) {
  2337. return instance.$getAnalyzerByType(type);
  2338. }
  2339. RES.getAnalyzer = getAnalyzer;
  2340. /**
  2341. * @language en_US
  2342. * Register the VersionController
  2343. * @param vcs The VersionController to register.
  2344. * @version Egret 2.5
  2345. * @platform Web,Native
  2346. */
  2347. /**
  2348. * @language zh_CN
  2349. * 注册版本控制器,通过RES模块加载资源时会从版本控制器获取真实url
  2350. * @param vcs 注入的版本控制器。
  2351. * @version Egret 2.5
  2352. * @platform Web,Native
  2353. */
  2354. function registerVersionController(vcs) {
  2355. instance.$registerVersionController(vcs);
  2356. }
  2357. RES.registerVersionController = registerVersionController;
  2358. /**
  2359. * @language en_US
  2360. * Returns the VersionController
  2361. * @version Egret 2.5
  2362. * @platform Web,Native
  2363. */
  2364. /**
  2365. * @language zh_CN
  2366. * 获得版本控制器.
  2367. * @version Egret 2.5
  2368. * @platform Web,Native
  2369. */
  2370. function getVersionController() {
  2371. return instance.vcs;
  2372. }
  2373. RES.getVersionController = getVersionController;
  2374. /**
  2375. * @language en_US
  2376. * Load configuration file and parse.
  2377. * @param url Configuration file path (path resource.json).
  2378. * @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.
  2379. * @param type Configuration file format. Determine what parser to parse the configuration file. Default "json".
  2380. * @see #setMaxRetryTimes
  2381. * @version Egret 2.4
  2382. * @platform Web,Native
  2383. */
  2384. /**
  2385. * @language zh_CN
  2386. * 加载配置文件并解析。
  2387. * @param url 配置文件路径(resource.json的路径)。
  2388. * @param resourceRoot 资源根路径。配置中的所有url都是这个路径的相对值。最终url是这个字符串与配置里资源项的url相加的值。
  2389. * @param type 配置文件的格式。确定要用什么解析器来解析配置文件。默认"json"
  2390. * @see #setMaxRetryTimes
  2391. * @version Egret 2.4
  2392. * @platform Web,Native
  2393. */
  2394. function loadConfig(url, resourceRoot, type) {
  2395. if (resourceRoot === void 0) { resourceRoot = ""; }
  2396. if (type === void 0) { type = "json"; }
  2397. instance.loadConfig(url, resourceRoot, type);
  2398. }
  2399. RES.loadConfig = loadConfig;
  2400. /**
  2401. * @language en_US
  2402. * Load a set of resources according to the group name.
  2403. * @param name Group name to load the resource group.
  2404. * @param priority Load priority can be negative, the default value is 0.
  2405. * <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.
  2406. * @see #setMaxRetryTimes
  2407. * @version Egret 2.4
  2408. * @platform Web,Native
  2409. */
  2410. /**
  2411. * @language zh_CN
  2412. * 根据组名加载一组资源。
  2413. * @param name 要加载资源组的组名。
  2414. * @param priority 加载优先级,可以为负数,默认值为 0。
  2415. * <br>低优先级的组必须等待高优先级组完全加载结束才能开始,同一优先级的组会同时加载。
  2416. * @see #setMaxRetryTimes
  2417. * @version Egret 2.4
  2418. * @platform Web,Native
  2419. */
  2420. function loadGroup(name, priority) {
  2421. if (priority === void 0) { priority = 0; }
  2422. instance.loadGroup(name, priority);
  2423. }
  2424. RES.loadGroup = loadGroup;
  2425. /**
  2426. * @language en_US
  2427. * Check whether a resource group has been loaded.
  2428. * @param name Group name。
  2429. * @returns Is loading or not.
  2430. * @see #setMaxRetryTimes
  2431. * @version Egret 2.4
  2432. * @platform Web,Native
  2433. */
  2434. /**
  2435. * @language zh_CN
  2436. * 检查某个资源组是否已经加载完成。
  2437. * @param name 组名。
  2438. * @returns 是否正在加载。
  2439. * @see #setMaxRetryTimes
  2440. * @version Egret 2.4
  2441. * @platform Web,Native
  2442. */
  2443. function isGroupLoaded(name) {
  2444. return instance.isGroupLoaded(name);
  2445. }
  2446. RES.isGroupLoaded = isGroupLoaded;
  2447. /**
  2448. * @language en_US
  2449. * A list of groups of loading is obtained according to the group name.
  2450. * @param name Group name.
  2451. * @returns The resource item array of group.
  2452. * @see RES.ResourceItem
  2453. * @see #setMaxRetryTimes
  2454. * @version Egret 2.4
  2455. * @platform Web,Native
  2456. */
  2457. /**
  2458. * @language zh_CN
  2459. * 根据组名获取组加载项列表。
  2460. * @param name 组名。
  2461. * @returns 加载项列表。
  2462. * @see RES.ResourceItem
  2463. * @see #setMaxRetryTimes
  2464. * @version Egret 2.4
  2465. * @platform Web,Native
  2466. */
  2467. function getGroupByName(name) {
  2468. return instance.getGroupByName(name);
  2469. }
  2470. RES.getGroupByName = getGroupByName;
  2471. /**
  2472. * @language en_US
  2473. * Create a custom load resource group, note that this method is valid only after the resource configuration file is loaded.
  2474. * <br>You can monitor the ResourceEvent.CONFIG_COMPLETE event to verify that the configuration is complete.
  2475. * @param name Group name to create the load resource group.
  2476. * @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.
  2477. * @param override Is the default false for the same name resource group already exists.
  2478. * @returns Create success or fail.
  2479. * @see #setMaxRetryTimes
  2480. * @version Egret 2.4
  2481. * @platform Web,Native
  2482. */
  2483. /**
  2484. * @language zh_CN
  2485. * 创建自定义的加载资源组,注意:此方法仅在资源配置文件加载完成后执行才有效。
  2486. * <br>可以监听 ResourceEvent.CONFIG_COMPLETE 事件来确认配置加载完成。
  2487. * @param name 要创建的加载资源组的组名。
  2488. * @param keys 要包含的键名列表,key 对应配置文件里的 name 属性或 sbuKeys 属性的一项或一个资源组名。
  2489. * @param override 是否覆盖已经存在的同名资源组,默认 false。
  2490. * @returns 是否创建成功。
  2491. * @see #setMaxRetryTimes
  2492. * @version Egret 2.4
  2493. * @platform Web,Native
  2494. */
  2495. function createGroup(name, keys, override) {
  2496. if (override === void 0) { override = false; }
  2497. return instance.createGroup(name, keys, override);
  2498. }
  2499. RES.createGroup = createGroup;
  2500. /**
  2501. * @language en_US
  2502. * Check whether the configuration file contains the specified resources.
  2503. * @param key A sbuKeys attribute or name property in a configuration file.
  2504. * @see #setMaxRetryTimes
  2505. * @version Egret 2.4
  2506. * @platform Web,Native
  2507. */
  2508. /**
  2509. * @language zh_CN
  2510. * 检查配置文件里是否含有指定的资源。
  2511. * @param key 对应配置文件里的 name 属性或 sbuKeys 属性的一项。
  2512. * @see #setMaxRetryTimes
  2513. * @version Egret 2.4
  2514. * @platform Web,Native
  2515. */
  2516. function hasRes(key) {
  2517. return instance.hasRes(key);
  2518. }
  2519. RES.hasRes = hasRes;
  2520. /**
  2521. * @language en_US
  2522. * parse a configuration file at run time,it will not clean the exist data.
  2523. * @param data Configuration file data, please refer to the resource.json configuration file format. JSON object can be introduced into the corresponding.
  2524. * @param folder Path prefix for load.
  2525. * @see #setMaxRetryTimes
  2526. * @version Egret 2.4
  2527. * @platform Web,Native
  2528. */
  2529. /**
  2530. * @language zh_CN
  2531. * 运行时动态解析一个配置文件,此操作不会清空之前已存在的配置。
  2532. * @param data 配置文件数据,请参考 resource.json 的配置文件格式。传入对应的 json 对象即可。
  2533. * @param folder 加载项的路径前缀。
  2534. * @see #setMaxRetryTimes
  2535. * @version Egret 2.4
  2536. * @platform Web,Native
  2537. */
  2538. function parseConfig(data, folder) {
  2539. if (folder === void 0) { folder = ""; }
  2540. instance.parseConfig(data, folder);
  2541. }
  2542. RES.parseConfig = parseConfig;
  2543. /**
  2544. * @language en_US
  2545. * The synchronization method for obtaining the cache has been loaded with the success of the resource.
  2546. * <br>The type of resource and the corresponding return value types are as follows:
  2547. * <br>RES.ResourceItem.TYPE_BIN : ArrayBuffer JavaScript primary object
  2548. * <br>RES.ResourceItem.TYPE_IMAGE : img Html Object,or egret.BitmapData interface。
  2549. * <br>RES.ResourceItem.TYPE_JSON : Object
  2550. * <br>RES.ResourceItem.TYPE_SHEET : Object
  2551. * <br> 1. If the incoming parameter is the name of the entire SpriteSheet is returned is {image1: Texture, "image2": Texture}.
  2552. * <br> 2. If the incoming is "sheet.image1", the return is a single resource.
  2553. * <br> 3. If the incoming is the name of the "image1" single resource, the return is a single resource.
  2554. * But if there are two SpriteSheet in a single picture of the same name, the return of the image after the load.
  2555. * <br>RES.ResourceItem.TYPE_SOUND : HtmlSound Html Object
  2556. * <br>RES.ResourceItem.TYPE_TEXT : string
  2557. * @param key A subKeys attribute or name property in a configuration file.
  2558. * @see RES.ResourceItem
  2559. * @see #setMaxRetryTimes
  2560. * @version Egret 2.4
  2561. * @platform Web,Native
  2562. */
  2563. /**
  2564. * @language zh_CN
  2565. * 同步方式获取缓存的已经加载成功的资源。
  2566. * <br>资源类型和对应的返回值类型关系如下:
  2567. * <br>RES.ResourceItem.TYPE_BIN : ArrayBuffer JavaScript 原生对象
  2568. * <br>RES.ResourceItem.TYPE_IMAGE : img Html 对象,或者 egret.BitmapData 接口。
  2569. * <br>RES.ResourceItem.TYPE_JSON : Object
  2570. * <br>RES.ResourceItem.TYPE_SHEET : Object
  2571. * <br> 1. 如果传入的参数是整个 SpriteSheet 的名称返回的是 {"image1":Texture,"image2":Texture} 这样的格式。
  2572. * <br> 2. 如果传入的是 "sheet.image1",返回的是单个资源。
  2573. * <br> 3. 如果传入的是 "image1" 单个资源的名称,返回的是单个资源。但是如果有两张 SpriteSheet 中有单个图片资源名称相同,返回的是后加载的那个图片资源。
  2574. * <br>RES.ResourceItem.TYPE_SOUND : HtmlSound Html 对象
  2575. * <br>RES.ResourceItem.TYPE_TEXT : string
  2576. * @param key 对应配置文件里的 name 属性或 subKeys 属性的一项。
  2577. * @see RES.ResourceItem
  2578. * @see #setMaxRetryTimes
  2579. * @version Egret 2.4
  2580. * @platform Web,Native
  2581. */
  2582. function getRes(key) {
  2583. return instance.getRes(key);
  2584. }
  2585. RES.getRes = getRes;
  2586. /**
  2587. * @language en_US
  2588. * 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.
  2589. * @param key A sbuKeys attribute or name property in a configuration file.
  2590. * @param compFunc Call back function. Example:compFunc(data,key):void.
  2591. * @param thisObject This pointer of call back function.
  2592. * @see #setMaxRetryTimes
  2593. * @version Egret 2.4
  2594. * @platform Web,Native
  2595. */
  2596. /**
  2597. * @language zh_CN
  2598. * 异步方式获取配置里的资源。只要是配置文件里存在的资源,都可以通过异步方式获取。
  2599. * @param key 对应配置文件里的 name 属性或 sbuKeys 属性的一项。
  2600. * @param compFunc 回调函数。示例:compFunc(data,key):void。
  2601. * @param thisObject 回调函数的 this 引用。
  2602. * @see #setMaxRetryTimes
  2603. * @version Egret 2.4
  2604. * @platform Web,Native
  2605. */
  2606. function getResAsync(key, compFunc, thisObject) {
  2607. instance.getResAsync(key, compFunc, thisObject);
  2608. }
  2609. RES.getResAsync = getResAsync;
  2610. /**
  2611. * @language en_US
  2612. * Access to external resources through the full URL.
  2613. * @param url The external path to load the file.
  2614. * @param compFunc Call back function. Example:compFunc(data,url):void。
  2615. * @param thisObject This pointer of call back function.
  2616. * @param type File type (optional). Use the static constants defined in the ResourceItem class. If you do not set the file name extension.
  2617. * @version Egret 2.4
  2618. * @platform Web,Native
  2619. * @includeExample extension/resource/GetResByUrl.ts
  2620. */
  2621. /**
  2622. * @language zh_CN
  2623. * 通过完整URL方式获取外部资源。
  2624. * @param url 要加载文件的外部路径。
  2625. * @param compFunc 回调函数。示例:compFunc(data,url):void。
  2626. * @param thisObject 回调函数的 this 引用。
  2627. * @param type 文件类型(可选)。请使用 ResourceItem 类中定义的静态常量。若不设置将根据文件扩展名生成。
  2628. * @version Egret 2.4
  2629. * @platform Web,Native
  2630. * @includeExample extension/resource/GetResByUrl.ts
  2631. */
  2632. function getResByUrl(url, compFunc, thisObject, type) {
  2633. if (type === void 0) { type = ""; }
  2634. instance.getResByUrl(url, compFunc, thisObject, type);
  2635. }
  2636. RES.getResByUrl = getResByUrl;
  2637. /**
  2638. * @language en_US
  2639. * Destroy a single resource file or a set of resources to the cache data, to return whether to delete success.
  2640. * @param name Name attribute or resource group name of the load item in the configuration file.
  2641. * @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.
  2642. * @returns Are successful destruction.
  2643. * @see #setMaxRetryTimes
  2644. * @version Egret 2.4
  2645. * @platform Web,Native
  2646. */
  2647. /**
  2648. * @language zh_CN
  2649. * 销毁单个资源文件或一组资源的缓存数据,返回是否删除成功。
  2650. * @param name 配置文件中加载项的name属性或资源组名。
  2651. * @param force 销毁一个资源组时其他资源组有同样资源情况资源是否会被删除,默认值 true。
  2652. * @see #setMaxRetryTimes
  2653. * @returns 是否销毁成功。
  2654. * @version Egret 2.4
  2655. * @platform Web,Native
  2656. */
  2657. function destroyRes(name, force) {
  2658. return instance.destroyRes(name, force);
  2659. }
  2660. RES.destroyRes = destroyRes;
  2661. /**
  2662. * @language en_US
  2663. * Sets the maximum number of concurrent load threads, the default value is 2.
  2664. * @param thread The number of concurrent loads to be set.
  2665. * @see #setMaxRetryTimes
  2666. * @version Egret 2.4
  2667. * @platform Web,Native
  2668. */
  2669. /**
  2670. * @language zh_CN
  2671. * 设置最大并发加载线程数量,默认值是 2。
  2672. * @param thread 要设置的并发加载数。
  2673. * @see #setMaxRetryTimes
  2674. * @version Egret 2.4
  2675. * @platform Web,Native
  2676. */
  2677. function setMaxLoadingThread(thread) {
  2678. instance.setMaxLoadingThread(thread);
  2679. }
  2680. RES.setMaxLoadingThread = setMaxLoadingThread;
  2681. /**
  2682. * @language en_US
  2683. * Sets the number of retry times when the resource failed to load, and the default value is 3.
  2684. * @param retry To set the retry count.
  2685. * @includeExample extension/resource/Resource.ts
  2686. * @version Egret 2.4
  2687. * @platform Web,Native
  2688. */
  2689. /**
  2690. * @language zh_CN
  2691. * 设置资源加载失败时的重试次数,默认值是 3。
  2692. * @param retry 要设置的重试次数。
  2693. * @includeExample extension/resource/Resource.ts
  2694. * @version Egret 2.4
  2695. * @platform Web,Native
  2696. */
  2697. function setMaxRetryTimes(retry) {
  2698. instance.setMaxRetryTimes(retry);
  2699. }
  2700. RES.setMaxRetryTimes = setMaxRetryTimes;
  2701. /**
  2702. * @language en_US
  2703. * Add event listeners, reference ResourceEvent defined constants.
  2704. * @param type Event name。
  2705. * @param listener Listener functions for handling events. This function must accept the Event object as its only parameter, and can't return any results,
  2706. * As shown in the following example: function (evt:Event):void can have any name.
  2707. * @param thisObject The this object that is bound to a function.
  2708. * @param useCapture Determine the listener is running on the capture or running on the target and the bubbling phase. Set useCapture to true,
  2709. * then the listener in the capture phase processing events, but not in the target or the bubbling phase processing events.
  2710. * If useCapture is false, then the listener only in the target or the bubbling phase processing events.
  2711. * 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.
  2712. * @param priority Event listener priority. Priority is specified by a 32 - bit integer with a symbol. The higher the number, the higher the priority.
  2713. * All listeners with a priority for n will be processed before the -1 n listener.
  2714. * 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.
  2715. * @see RES.ResourceEvent
  2716. * @version Egret 2.4
  2717. * @platform Web,Native
  2718. */
  2719. /**
  2720. * @language zh_CN
  2721. * 添加事件侦听器,参考 ResourceEvent 定义的常量。
  2722. * @param type 事件的类型。
  2723. * @param listener 处理事件的侦听器函数。此函数必须接受 Event 对象作为其唯一的参数,并且不能返回任何结果,
  2724. * 如下面的示例所示: function(evt:Event):void 函数可以有任何名称。
  2725. * @param thisObject 侦听函数绑定的 this 对象。
  2726. * @param useCapture 确定侦听器是运行于捕获阶段还是运行于目标和冒泡阶段。如果将 useCapture 设置为 true,
  2727. * 则侦听器只在捕获阶段处理事件,而不在目标或冒泡阶段处理事件。如果 useCapture 为 false,则侦听器只在目标或冒泡阶段处理事件。
  2728. * 要在所有三个阶段都侦听事件,请调用 addEventListener 两次:一次将 useCapture 设置为 true,一次将 useCapture 设置为 false。
  2729. * @param priority 事件侦听器的优先级。优先级由一个带符号的 32 位整数指定。数字越大,优先级越高。优先级为 n 的所有侦听器会在
  2730. * 优先级为 n -1 的侦听器之前得到处理。如果两个或更多个侦听器共享相同的优先级,则按照它们的添加顺序进行处理。默认优先级为 0。
  2731. * @see RES.ResourceEvent
  2732. * @see #setMaxRetryTimes
  2733. * @version Egret 2.4
  2734. * @platform Web,Native
  2735. */
  2736. function addEventListener(type, listener, thisObject, useCapture, priority) {
  2737. if (useCapture === void 0) { useCapture = false; }
  2738. if (priority === void 0) { priority = 0; }
  2739. instance.addEventListener(type, listener, thisObject, useCapture, priority);
  2740. }
  2741. RES.addEventListener = addEventListener;
  2742. /**
  2743. * @language en_US
  2744. * Remove event listeners, reference ResourceEvent defined constants.
  2745. * @param type Event name。
  2746. * @param listener Listening function。
  2747. * @param thisObject The this object that is bound to a function.
  2748. * @param useCapture Is used to capture, and this property is only valid in the display list.
  2749. * @version Egret 2.4
  2750. * @platform Web,Native
  2751. */
  2752. /**
  2753. * @language zh_CN
  2754. * 移除事件侦听器,参考ResourceEvent定义的常量。
  2755. * @param type 事件名。
  2756. * @param listener 侦听函数。
  2757. * @param thisObject 侦听函数绑定的this对象。
  2758. * @param useCapture 是否使用捕获,这个属性只在显示列表中生效。
  2759. * @version Egret 2.4
  2760. * @platform Web,Native
  2761. */
  2762. function removeEventListener(type, listener, thisObject, useCapture) {
  2763. if (useCapture === void 0) { useCapture = false; }
  2764. instance.removeEventListener(type, listener, thisObject, useCapture);
  2765. }
  2766. RES.removeEventListener = removeEventListener;
  2767. function $getVirtualUrl(url) {
  2768. if (instance.vcs) {
  2769. return instance.vcs.getVirtualUrl(url);
  2770. }
  2771. else {
  2772. return url;
  2773. }
  2774. }
  2775. RES.$getVirtualUrl = $getVirtualUrl;
  2776. /**
  2777. * @private
  2778. */
  2779. var Resource = (function (_super) {
  2780. __extends(Resource, _super);
  2781. /**
  2782. * 构造函数
  2783. * @method RES.constructor
  2784. * @private
  2785. */
  2786. function Resource() {
  2787. var _this = _super.call(this) || this;
  2788. /**
  2789. * 解析器字典
  2790. */
  2791. _this.analyzerDic = {};
  2792. _this.analyzerClassMap = {};
  2793. _this.configItemList = [];
  2794. _this.callLaterFlag = false;
  2795. /**
  2796. * 配置文件加载解析完成标志
  2797. */
  2798. _this.configComplete = false;
  2799. /**
  2800. * 已经加载过组名列表
  2801. */
  2802. _this.loadedGroups = [];
  2803. _this.groupNameList = [];
  2804. /**
  2805. * 异步获取资源参数缓存字典
  2806. */
  2807. _this.asyncDic = {};
  2808. _this._loadedUrlTypes = {};
  2809. _this.init();
  2810. return _this;
  2811. }
  2812. /**
  2813. * 根据type获取对应的文件解析库
  2814. */
  2815. Resource.prototype.$getAnalyzerByType = function (type) {
  2816. var analyzer = this.analyzerDic[type];
  2817. if (!analyzer) {
  2818. var clazz = this.analyzerClassMap[type];
  2819. if (!clazz) {
  2820. if (true) {
  2821. egret.$error(3203, type);
  2822. }
  2823. return null;
  2824. }
  2825. analyzer = this.analyzerDic[type] = new clazz();
  2826. }
  2827. return analyzer;
  2828. };
  2829. /**
  2830. * 注册一个自定义文件类型解析器
  2831. * @param type 文件类型字符串,例如:bin,text,image,json等。
  2832. * @param analyzerClass 自定义解析器的类定义
  2833. */
  2834. Resource.prototype.registerAnalyzer = function (type, analyzerClass) {
  2835. this.analyzerClassMap[type] = analyzerClass;
  2836. };
  2837. Resource.prototype.$registerVersionController = function (vcs) {
  2838. this.vcs = vcs;
  2839. };
  2840. /**
  2841. * 初始化
  2842. */
  2843. Resource.prototype.init = function () {
  2844. this.vcs = new RES.VersionController();
  2845. var analyzerClassMap = this.analyzerClassMap;
  2846. analyzerClassMap[RES.ResourceItem.TYPE_BIN] = RES.BinAnalyzer;
  2847. analyzerClassMap[RES.ResourceItem.TYPE_IMAGE] = RES.ImageAnalyzer;
  2848. analyzerClassMap[RES.ResourceItem.TYPE_TEXT] = RES.TextAnalyzer;
  2849. analyzerClassMap[RES.ResourceItem.TYPE_JSON] = RES.JsonAnalyzer;
  2850. analyzerClassMap[RES.ResourceItem.TYPE_SHEET] = RES.SheetAnalyzer;
  2851. analyzerClassMap[RES.ResourceItem.TYPE_FONT] = RES.FontAnalyzer;
  2852. analyzerClassMap[RES.ResourceItem.TYPE_SOUND] = RES.SoundAnalyzer;
  2853. analyzerClassMap[RES.ResourceItem.TYPE_XML] = RES.XMLAnalyzer;
  2854. this.resConfig = new RES.ResourceConfig();
  2855. this.resLoader = new RES.ResourceLoader();
  2856. this.resLoader.callBack = this.onResourceItemComp;
  2857. this.resLoader.resInstance = this;
  2858. this.resLoader.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onGroupComp, this);
  2859. this.resLoader.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onGroupError, this);
  2860. };
  2861. /**
  2862. * 开始加载配置
  2863. * @method RES.loadConfig
  2864. * @param url {string}
  2865. * @param resourceRoot {string}
  2866. * @param type {string}
  2867. */
  2868. Resource.prototype.loadConfig = function (url, resourceRoot, type) {
  2869. if (type === void 0) { type = "json"; }
  2870. var configItem = { url: url, resourceRoot: resourceRoot, type: type };
  2871. this.configItemList.push(configItem);
  2872. if (!this.callLaterFlag) {
  2873. egret.callLater(this.startLoadConfig, this);
  2874. this.callLaterFlag = true;
  2875. }
  2876. };
  2877. Resource.prototype.startLoadConfig = function () {
  2878. var _this = this;
  2879. this.callLaterFlag = false;
  2880. var configList = this.configItemList;
  2881. this.configItemList = [];
  2882. this.loadingConfigList = configList;
  2883. var length = configList.length;
  2884. var itemList = [];
  2885. for (var i = 0; i < length; i++) {
  2886. var item = configList[i];
  2887. var resItem = new RES.ResourceItem(item.url, item.url, item.type);
  2888. itemList.push(resItem);
  2889. }
  2890. var callback = {
  2891. onSuccess: function (data) {
  2892. _this.resLoader.loadGroup(itemList, Resource.GROUP_CONFIG, Number.MAX_VALUE);
  2893. },
  2894. onFail: function (err, data) {
  2895. RES.ResourceEvent.dispatchResourceEvent(_this, RES.ResourceEvent.CONFIG_LOAD_ERROR);
  2896. }
  2897. };
  2898. if (this.vcs) {
  2899. this.vcs.fetchVersion(callback);
  2900. }
  2901. else {
  2902. this.resLoader.loadGroup(itemList, Resource.GROUP_CONFIG, Number.MAX_VALUE);
  2903. }
  2904. };
  2905. /**
  2906. * 检查某个资源组是否已经加载完成
  2907. * @method RES.isGroupLoaded
  2908. * @param name {string}
  2909. * @returns {boolean}
  2910. */
  2911. Resource.prototype.isGroupLoaded = function (name) {
  2912. return this.loadedGroups.indexOf(name) != -1;
  2913. };
  2914. /**
  2915. * 根据组名获取组加载项列表
  2916. * @method RES.getGroupByName
  2917. * @param name {string}
  2918. * @returns {Array<egret.ResourceItem>}
  2919. */
  2920. Resource.prototype.getGroupByName = function (name) {
  2921. return this.resConfig.getGroupByName(name);
  2922. };
  2923. /**
  2924. * 根据组名加载一组资源
  2925. * @method RES.loadGroup
  2926. * @param name {string}
  2927. * @param priority {number}
  2928. */
  2929. Resource.prototype.loadGroup = function (name, priority) {
  2930. if (priority === void 0) { priority = 0; }
  2931. if (this.loadedGroups.indexOf(name) != -1) {
  2932. RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.GROUP_COMPLETE, name);
  2933. return;
  2934. }
  2935. if (this.resLoader.isGroupInLoading(name))
  2936. return;
  2937. if (this.configComplete) {
  2938. var group = this.resConfig.getGroupByName(name);
  2939. this.resLoader.loadGroup(group, name, priority);
  2940. }
  2941. else {
  2942. this.groupNameList.push({ name: name, priority: priority });
  2943. }
  2944. };
  2945. /**
  2946. * 创建自定义的加载资源组,注意:此方法仅在资源配置文件加载完成后执行才有效。
  2947. * 可以监听ResourceEvent.CONFIG_COMPLETE事件来确认配置加载完成。
  2948. * @method RES.ResourceConfig#createGroup
  2949. * @param name {string} 要创建的加载资源组的组名
  2950. * @param keys {egret.string[]} 要包含的键名列表,key对应配置文件里的name属性或一个资源组名。
  2951. * @param override {boolean} 是否覆盖已经存在的同名资源组,默认false。
  2952. * @returns {boolean}
  2953. */
  2954. Resource.prototype.createGroup = function (name, keys, override) {
  2955. if (override === void 0) { override = false; }
  2956. if (override) {
  2957. var index = this.loadedGroups.indexOf(name);
  2958. if (index != -1) {
  2959. this.loadedGroups.splice(index, 1);
  2960. }
  2961. }
  2962. return this.resConfig.createGroup(name, keys, override);
  2963. };
  2964. /**
  2965. * 队列加载完成事件
  2966. */
  2967. Resource.prototype.onGroupComp = function (event) {
  2968. if (event.groupName == Resource.GROUP_CONFIG) {
  2969. var length_5 = this.loadingConfigList.length;
  2970. for (var i = 0; i < length_5; i++) {
  2971. var config = this.loadingConfigList[i];
  2972. var resolver = this.$getAnalyzerByType(config.type);
  2973. var data = resolver.getRes(config.url);
  2974. resolver.destroyRes(config.url);
  2975. this.resConfig.parseConfig(data, config.resourceRoot);
  2976. }
  2977. this.configComplete = true;
  2978. this.loadingConfigList = null;
  2979. RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.CONFIG_COMPLETE);
  2980. this.loadDelayGroups();
  2981. }
  2982. else {
  2983. this.loadedGroups.push(event.groupName);
  2984. this.dispatchEvent(event);
  2985. }
  2986. };
  2987. /**
  2988. * 启动延迟的组加载
  2989. */
  2990. Resource.prototype.loadDelayGroups = function () {
  2991. var groupNameList = this.groupNameList;
  2992. this.groupNameList = [];
  2993. var length = groupNameList.length;
  2994. for (var i = 0; i < length; i++) {
  2995. var item = groupNameList[i];
  2996. this.loadGroup(item.name, item.priority);
  2997. }
  2998. };
  2999. /**
  3000. * 队列加载失败事件
  3001. */
  3002. Resource.prototype.onGroupError = function (event) {
  3003. if (event.groupName == Resource.GROUP_CONFIG) {
  3004. this.loadingConfigList = null;
  3005. RES.ResourceEvent.dispatchResourceEvent(this, RES.ResourceEvent.CONFIG_LOAD_ERROR);
  3006. }
  3007. else {
  3008. this.dispatchEvent(event);
  3009. }
  3010. };
  3011. /**
  3012. * 检查配置文件里是否含有指定的资源
  3013. * @method RES.hasRes
  3014. * @param key {string} 对应配置文件里的name属性或sbuKeys属性的一项。
  3015. * @returns {boolean}
  3016. */
  3017. Resource.prototype.hasRes = function (key) {
  3018. var type = this.resConfig.getType(key);
  3019. if (type == "") {
  3020. var prefix = RES.AnalyzerBase.getStringTail(key);
  3021. type = this.resConfig.getType(prefix);
  3022. if (type == "") {
  3023. return false;
  3024. }
  3025. }
  3026. return true;
  3027. };
  3028. /**
  3029. * 运行时动态解析一个配置文件,
  3030. * @param data {any} 配置文件数据,请参考resource.json的配置文件格式。传入对应的json对象即可。
  3031. * @param folder {string} 加载项的路径前缀。
  3032. */
  3033. Resource.prototype.parseConfig = function (data, folder) {
  3034. this.resConfig.parseConfig(data, folder);
  3035. if (!this.configComplete && !this.loadingConfigList) {
  3036. this.configComplete = true;
  3037. this.loadDelayGroups();
  3038. }
  3039. };
  3040. /**
  3041. * 通过key同步获取资源
  3042. * @method RES.getRes
  3043. * @param key {string}
  3044. * @returns {any}
  3045. */
  3046. Resource.prototype.getRes = function (key) {
  3047. var type = this.resConfig.getType(key);
  3048. if (type == "") {
  3049. var prefix = RES.AnalyzerBase.getStringPrefix(key);
  3050. type = this.resConfig.getType(prefix);
  3051. if (type == "") {
  3052. return null;
  3053. }
  3054. }
  3055. var analyzer = this.$getAnalyzerByType(type);
  3056. return analyzer.getRes(key);
  3057. };
  3058. /**
  3059. * 通过key异步获取资源
  3060. * @method RES.getResAsync
  3061. * @param key {string}
  3062. * @param compFunc {Function} 回调函数。示例:compFunc(data,url):void。
  3063. * @param thisObject {any}
  3064. */
  3065. Resource.prototype.getResAsync = function (key, compFunc, thisObject) {
  3066. var type = this.resConfig.getType(key);
  3067. var name = this.resConfig.getName(key);
  3068. if (type == "") {
  3069. name = RES.AnalyzerBase.getStringPrefix(key);
  3070. type = this.resConfig.getType(name);
  3071. if (type == "") {
  3072. egret.$callAsync(compFunc, thisObject);
  3073. return;
  3074. }
  3075. }
  3076. var analyzer = this.$getAnalyzerByType(type);
  3077. var res = analyzer.getRes(key);
  3078. if (res) {
  3079. egret.$callAsync(compFunc, thisObject, res, key);
  3080. return;
  3081. }
  3082. var args = { key: key, compFunc: compFunc, thisObject: thisObject };
  3083. if (this.asyncDic[name]) {
  3084. this.asyncDic[name].push(args);
  3085. }
  3086. else {
  3087. this.asyncDic[name] = [args];
  3088. var resItem = this.resConfig.getResourceItem(name);
  3089. this.resLoader.loadItem(resItem);
  3090. }
  3091. };
  3092. /**
  3093. * 通过url获取资源
  3094. * @method RES.getResByUrl
  3095. * @param url {string}
  3096. * @param compFunc {Function}
  3097. * @param thisObject {any}
  3098. * @param type {string}
  3099. */
  3100. Resource.prototype.getResByUrl = function (url, compFunc, thisObject, type) {
  3101. if (type === void 0) { type = ""; }
  3102. if (!url) {
  3103. egret.$callAsync(compFunc, thisObject);
  3104. return;
  3105. }
  3106. if (!type)
  3107. type = this.getTypeByUrl(url);
  3108. if (this._loadedUrlTypes[url] != null && this._loadedUrlTypes[url] != type) {
  3109. egret.$warn(3202);
  3110. }
  3111. this._loadedUrlTypes[url] = type;
  3112. var analyzer = this.$getAnalyzerByType(type);
  3113. var name = url;
  3114. var res = analyzer.getRes(name);
  3115. if (res) {
  3116. egret.$callAsync(compFunc, thisObject, res, url);
  3117. return;
  3118. }
  3119. var args = { key: name, compFunc: compFunc, thisObject: thisObject };
  3120. if (this.asyncDic[name]) {
  3121. this.asyncDic[name].push(args);
  3122. }
  3123. else {
  3124. this.asyncDic[name] = [args];
  3125. var resItem = new RES.ResourceItem(name, url, type);
  3126. this.resLoader.loadItem(resItem);
  3127. }
  3128. };
  3129. /**
  3130. * 通过url获取文件类型
  3131. */
  3132. Resource.prototype.getTypeByUrl = function (url) {
  3133. var suffix = url.substr(url.lastIndexOf(".") + 1);
  3134. if (suffix) {
  3135. suffix = suffix.toLowerCase();
  3136. }
  3137. var type;
  3138. switch (suffix) {
  3139. case RES.ResourceItem.TYPE_XML:
  3140. case RES.ResourceItem.TYPE_JSON:
  3141. case RES.ResourceItem.TYPE_SHEET:
  3142. type = suffix;
  3143. break;
  3144. case "png":
  3145. case "jpg":
  3146. case "gif":
  3147. case "jpeg":
  3148. case "bmp":
  3149. type = RES.ResourceItem.TYPE_IMAGE;
  3150. break;
  3151. case "fnt":
  3152. type = RES.ResourceItem.TYPE_FONT;
  3153. break;
  3154. case "txt":
  3155. type = RES.ResourceItem.TYPE_TEXT;
  3156. break;
  3157. case "mp3":
  3158. case "ogg":
  3159. case "mpeg":
  3160. case "wav":
  3161. case "m4a":
  3162. case "mp4":
  3163. case "aiff":
  3164. case "wma":
  3165. case "mid":
  3166. type = RES.ResourceItem.TYPE_SOUND;
  3167. break;
  3168. default:
  3169. type = RES.ResourceItem.TYPE_BIN;
  3170. break;
  3171. }
  3172. return type;
  3173. };
  3174. /**
  3175. * 一个加载项加载完成
  3176. */
  3177. Resource.prototype.onResourceItemComp = function (item) {
  3178. var argsList = this.asyncDic[item.name];
  3179. delete this.asyncDic[item.name];
  3180. var analyzer = this.$getAnalyzerByType(item.type);
  3181. var length = argsList.length;
  3182. for (var i = 0; i < length; i++) {
  3183. var args = argsList[i];
  3184. var res = analyzer.getRes(args.key);
  3185. args.compFunc.call(args.thisObject, res, args.key);
  3186. }
  3187. };
  3188. /**
  3189. * 销毁单个资源文件或一组资源的缓存数据,返回是否删除成功。
  3190. * @method RES.destroyRes
  3191. * @param name {string} 配置文件中加载项的name属性或资源组名
  3192. * @param force {boolean} 销毁一个资源组时其他资源组有同样资源情况资源是否会被删除,默认值true
  3193. * @returns {boolean}
  3194. */
  3195. Resource.prototype.destroyRes = function (name, force) {
  3196. if (force === void 0) { force = true; }
  3197. var group = this.resConfig.getRawGroupByName(name);
  3198. if (group && group.length > 0) {
  3199. var index = this.loadedGroups.indexOf(name);
  3200. if (index != -1) {
  3201. this.loadedGroups.splice(index, 1);
  3202. }
  3203. var length_6 = group.length;
  3204. for (var i = 0; i < length_6; i++) {
  3205. var item = group[i];
  3206. if (!force && this.isResInLoadedGroup(item.name)) {
  3207. }
  3208. else {
  3209. item.loaded = false;
  3210. var analyzer = this.$getAnalyzerByType(item.type);
  3211. analyzer.destroyRes(item.name);
  3212. this.removeLoadedGroupsByItemName(item.name);
  3213. }
  3214. }
  3215. return true;
  3216. }
  3217. else {
  3218. var type = this.resConfig.getType(name);
  3219. if (type == "") {
  3220. type = this._loadedUrlTypes[name];
  3221. if (type == null || type == "") {
  3222. return false;
  3223. }
  3224. delete this._loadedUrlTypes[name];
  3225. var analyzer_1 = this.$getAnalyzerByType(type);
  3226. analyzer_1.destroyRes(name);
  3227. return true;
  3228. }
  3229. var item = this.resConfig.getRawResourceItem(name);
  3230. item.loaded = false;
  3231. var analyzer = this.$getAnalyzerByType(type);
  3232. var result = analyzer.destroyRes(name);
  3233. this.removeLoadedGroupsByItemName(item.name);
  3234. return result;
  3235. }
  3236. };
  3237. Resource.prototype.removeLoadedGroupsByItemName = function (name) {
  3238. var loadedGroups = this.loadedGroups;
  3239. var loadedGroupLength = loadedGroups.length;
  3240. for (var i = 0; i < loadedGroupLength; i++) {
  3241. var group = this.resConfig.getRawGroupByName(loadedGroups[i]);
  3242. var length_7 = group.length;
  3243. for (var j = 0; j < length_7; j++) {
  3244. var item = group[j];
  3245. if (item.name == name) {
  3246. loadedGroups.splice(i, 1);
  3247. i--;
  3248. loadedGroupLength = loadedGroups.length;
  3249. break;
  3250. }
  3251. }
  3252. }
  3253. };
  3254. Resource.prototype.isResInLoadedGroup = function (name) {
  3255. var loadedGroups = this.loadedGroups;
  3256. var loadedGroupLength = loadedGroups.length;
  3257. for (var i = 0; i < loadedGroupLength; i++) {
  3258. var group = this.resConfig.getRawGroupByName(loadedGroups[i]);
  3259. var length_8 = group.length;
  3260. for (var j = 0; j < length_8; j++) {
  3261. var item = group[j];
  3262. if (item.name == name) {
  3263. return true;
  3264. }
  3265. }
  3266. }
  3267. return false;
  3268. };
  3269. /**
  3270. * 设置最大并发加载线程数量,默认值是2.
  3271. * @method RES.setMaxLoadingThread
  3272. * @param thread {number} 要设置的并发加载数。
  3273. */
  3274. Resource.prototype.setMaxLoadingThread = function (thread) {
  3275. if (thread < 1) {
  3276. thread = 1;
  3277. }
  3278. this.resLoader.thread = thread;
  3279. };
  3280. /**
  3281. * 设置资源加载失败时的重试次数。
  3282. * @param retry 要设置的重试次数。
  3283. */
  3284. Resource.prototype.setMaxRetryTimes = function (retry) {
  3285. retry = Math.max(retry, 0);
  3286. this.resLoader.maxRetryTimes = retry;
  3287. };
  3288. return Resource;
  3289. }(egret.EventDispatcher));
  3290. /**
  3291. * 配置文件组组名
  3292. */
  3293. Resource.GROUP_CONFIG = "RES__CONFIG";
  3294. __reflect(Resource.prototype, "Resource");
  3295. /**
  3296. * Resource单例
  3297. */
  3298. var instance = new Resource();
  3299. })(RES || (RES = {}));
  3300. ////////////////////////////////////////////////////////////////////////////////////////
  3301. ////
  3302. //// Copyright (c) 2014-present, Egret Technology.
  3303. //// All rights reserved.
  3304. //// Redistribution and use in source and binary forms, with or without
  3305. //// modification, are permitted provided that the following conditions are met:
  3306. ////
  3307. //// * Redistributions of source code must retain the above copyright
  3308. //// notice, this list of conditions and the following disclaimer.
  3309. //// * Redistributions in binary form must reproduce the above copyright
  3310. //// notice, this list of conditions and the following disclaimer in the
  3311. //// documentation and/or other materials provided with the distribution.
  3312. //// * Neither the name of the Egret nor the
  3313. //// names of its contributors may be used to endorse or promote products
  3314. //// derived from this software without specific prior written permission.
  3315. ////
  3316. //// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3317. //// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3318. //// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3319. //// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3320. //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3321. //// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3322. //// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3323. //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3324. //// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3325. //// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3326. ////
  3327. ////////////////////////////////////////////////////////////////////////////////////////
  3328. var RES;
  3329. (function (RES) {
  3330. /**
  3331. * SpriteSheet解析器
  3332. * @private
  3333. */
  3334. var AnimationAnalyzer = (function (_super) {
  3335. __extends(AnimationAnalyzer, _super);
  3336. function AnimationAnalyzer() {
  3337. var _this = _super.call(this) || this;
  3338. _this.sheetMap = {};
  3339. /**
  3340. * ImageLoader对象池
  3341. */
  3342. _this.recyclerIamge = [];
  3343. _this._dataFormat = egret.HttpResponseType.TEXT;
  3344. return _this;
  3345. }
  3346. /**
  3347. * 一项加载结束
  3348. */
  3349. AnimationAnalyzer.prototype.onLoadFinish = function (event) {
  3350. var request = event.target;
  3351. var data = this.resItemDic[request.$hashCode];
  3352. delete this.resItemDic[request.hashCode];
  3353. var resItem = data.item;
  3354. var compFunc = data.func;
  3355. resItem.loaded = (event.type == egret.Event.COMPLETE);
  3356. if (resItem.loaded) {
  3357. if (request instanceof egret.HttpRequest) {
  3358. resItem.loaded = false;
  3359. var imageUrl = this.analyzeConfig(resItem, request.response);
  3360. if (imageUrl) {
  3361. this.loadImage(imageUrl, data);
  3362. this.recycler.push(request);
  3363. return;
  3364. }
  3365. }
  3366. else {
  3367. this.analyzeBitmap(resItem, request.data);
  3368. }
  3369. }
  3370. if (request instanceof egret.HttpRequest) {
  3371. this.recycler.push(request);
  3372. }
  3373. else {
  3374. this.recyclerIamge.push(request);
  3375. }
  3376. compFunc.call(data.thisObject, resItem);
  3377. };
  3378. /**
  3379. * 解析并缓存加载成功的配置文件
  3380. */
  3381. AnimationAnalyzer.prototype.analyzeConfig = function (resItem, data) {
  3382. var name = resItem.name;
  3383. var config;
  3384. var imageUrl = "";
  3385. try {
  3386. var str = data;
  3387. config = JSON.parse(str);
  3388. }
  3389. catch (e) {
  3390. egret.$warn(1017, resItem.url, data);
  3391. }
  3392. if (config) {
  3393. this.sheetMap[name] = config;
  3394. if (config["file"]) {
  3395. imageUrl = this.getRelativePath(resItem.url, config["file"]);
  3396. }
  3397. else {
  3398. var arr = resItem.url.split("?");
  3399. var arr2 = arr[0].split("/");
  3400. arr2[arr2.length - 1] = arr2[arr2.length - 1].split(".")[0] + ".png";
  3401. imageUrl = "";
  3402. for (var i = 0; i < arr2.length; i++) {
  3403. imageUrl += arr2[i] + (i < arr2.length - 1 ? "/" : "");
  3404. }
  3405. if (arr.length == 2)
  3406. imageUrl += arr[2];
  3407. }
  3408. }
  3409. return imageUrl;
  3410. };
  3411. /**
  3412. * 解析并缓存加载成功的位图数据
  3413. */
  3414. AnimationAnalyzer.prototype.analyzeBitmap = function (resItem, data) {
  3415. var name = resItem.name;
  3416. if (this.fileDic[name] || !data) {
  3417. return;
  3418. }
  3419. var config = this.sheetMap[name];
  3420. delete this.sheetMap[name];
  3421. var targetName = resItem.data && resItem.data.subkeys ? "" : name;
  3422. var spriteSheet = this.parseAnimation(data, config, targetName);
  3423. this.fileDic[name] = spriteSheet;
  3424. };
  3425. /**
  3426. * 获取相对位置
  3427. */
  3428. AnimationAnalyzer.prototype.getRelativePath = function (url, file) {
  3429. url = url.split("\\").join("/");
  3430. var index = url.lastIndexOf("/");
  3431. if (index != -1) {
  3432. url = url.substring(0, index + 1) + file;
  3433. }
  3434. else {
  3435. url = file;
  3436. }
  3437. return url;
  3438. };
  3439. AnimationAnalyzer.prototype.parseAnimation = function (bitmapData, data, name) {
  3440. var attributes = Object.keys(data.mc);
  3441. var list = data.mc[attributes[0]].frames;
  3442. var len = list.length;
  3443. var config;
  3444. var animationFrames = [];
  3445. for (var i = 0; i < len; i++) {
  3446. config = data.res[list[i].res];
  3447. var texture = new egret.Texture();
  3448. texture._bitmapData = bitmapData;
  3449. 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);
  3450. }
  3451. return animationFrames;
  3452. };
  3453. AnimationAnalyzer.prototype.destroyRes = function (name) {
  3454. var sheet = this.fileDic[name];
  3455. if (sheet) {
  3456. delete this.fileDic[name];
  3457. return true;
  3458. }
  3459. return false;
  3460. };
  3461. AnimationAnalyzer.prototype.loadImage = function (url, data) {
  3462. var loader = this.getImageLoader();
  3463. this.resItemDic[loader.hashCode] = data;
  3464. loader.load(RES.$getVirtualUrl(url));
  3465. };
  3466. AnimationAnalyzer.prototype.getImageLoader = function () {
  3467. var loader = this.recyclerIamge.pop();
  3468. if (!loader) {
  3469. loader = new egret.ImageLoader();
  3470. loader.addEventListener(egret.Event.COMPLETE, this.onLoadFinish, this);
  3471. loader.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onLoadFinish, this);
  3472. }
  3473. return loader;
  3474. };
  3475. return AnimationAnalyzer;
  3476. }(RES.BinAnalyzer));
  3477. RES.AnimationAnalyzer = AnimationAnalyzer;
  3478. __reflect(AnimationAnalyzer.prototype, "RES.AnimationAnalyzer");
  3479. })(RES || (RES = {}));
  3480. var egret;
  3481. (function (egret) {
  3482. egret.$locale_strings = egret.$locale_strings || {};
  3483. egret.$locale_strings["en_US"] = egret.$locale_strings["en_US"] || {};
  3484. var locale_strings = egret.$locale_strings["en_US"];
  3485. //RES 3200-3299
  3486. locale_strings[3200] = "RES.createGroup() passed in non-existed key value in configuration: {0}";
  3487. locale_strings[3201] = "RES loaded non-existed or empty resource group:\"{0}\"";
  3488. locale_strings[3202] = "Do not use the different types of ways to load the same material!";
  3489. 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。";
  3490. })(egret || (egret = {}));
  3491. var egret;
  3492. (function (egret) {
  3493. egret.$locale_strings = egret.$locale_strings || {};
  3494. egret.$locale_strings["zh_CN"] = egret.$locale_strings["zh_CN"] || {};
  3495. var locale_strings = egret.$locale_strings["zh_CN"];
  3496. //RES 3200-3299
  3497. locale_strings[3200] = "RES.createGroup()传入了配置中不存在的键值: {0}";
  3498. locale_strings[3201] = "RES加载了不存在或空的资源组:\"{0}\"";
  3499. locale_strings[3202] = "请不要使用不同的类型方式来加载同一个素材!";
  3500. locale_strings[3203] = "找不到指定文件类型的解析器:{0}。 请先在项目初始化里注册指定文件类型的解析器,再启动资源加载。";
  3501. })(egret || (egret = {}));