laya.quickgamemini.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939
  1. window=window||global;if(!window.layalib){window.layalib=function(f,i){(window._layalibs || (window._layalibs=[])).push({f:f,i:i});}}
  2. window.layalib(function(window,document,Laya){
  3. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  4. var Browser=laya.utils.Browser,Config=Laya.Config,Event=laya.events.Event,EventDispatcher=laya.events.EventDispatcher;
  5. var HTMLImage=laya.resource.HTMLImage,Handler=laya.utils.Handler,Input=laya.display.Input,Loader=laya.net.Loader;
  6. var LocalStorage=laya.net.LocalStorage,Matrix=laya.maths.Matrix,Render=laya.renders.Render,RunDriver=laya.utils.RunDriver;
  7. var SoundChannel=laya.media.SoundChannel,SoundManager=laya.media.SoundManager,Stage=laya.display.Stage,URL=laya.net.URL;
  8. var Utils=laya.utils.Utils;
  9. /**@private **/
  10. //class laya.qg.mini.MiniLocation
  11. var MiniLocation$3=(function(){
  12. function MiniLocation(){}
  13. __class(MiniLocation,'laya.qg.mini.MiniLocation',null,'MiniLocation$3');
  14. MiniLocation.__init__=function(){
  15. QGMiniAdapter.window.navigator.geolocation.getCurrentPosition=MiniLocation.getCurrentPosition;
  16. QGMiniAdapter.window.navigator.geolocation.watchPosition=MiniLocation.watchPosition;
  17. QGMiniAdapter.window.navigator.geolocation.clearWatch=MiniLocation.clearWatch;
  18. }
  19. MiniLocation.getCurrentPosition=function(success,error,options){
  20. var paramO;
  21. paramO={};
  22. paramO.success=getSuccess;
  23. paramO.fail=error;
  24. QGMiniAdapter.window.qg.getLocation(paramO);
  25. function getSuccess (res){
  26. if (success !=null){
  27. success(res);
  28. }
  29. }
  30. }
  31. MiniLocation.watchPosition=function(success,error,options){
  32. MiniLocation._curID++;
  33. var curWatchO;
  34. curWatchO={};
  35. curWatchO.success=success;
  36. curWatchO.error=error;
  37. MiniLocation._watchDic[MiniLocation._curID]=curWatchO;
  38. Laya.systemTimer.loop(1000,null,MiniLocation._myLoop);
  39. return MiniLocation._curID;
  40. }
  41. MiniLocation.clearWatch=function(id){
  42. delete MiniLocation._watchDic[id];
  43. if (!MiniLocation._hasWatch()){
  44. Laya.systemTimer.clear(null,MiniLocation._myLoop);
  45. }
  46. }
  47. MiniLocation._hasWatch=function(){
  48. var key;
  49. for (key in MiniLocation._watchDic){
  50. if (MiniLocation._watchDic[key])return true;
  51. }
  52. return false;
  53. }
  54. MiniLocation._myLoop=function(){
  55. MiniLocation.getCurrentPosition(MiniLocation._mySuccess,MiniLocation._myError);
  56. }
  57. MiniLocation._mySuccess=function(res){
  58. var rst={};
  59. rst.coords=res;
  60. rst.timestamp=Browser.now();
  61. var key;
  62. for (key in MiniLocation._watchDic){
  63. if (MiniLocation._watchDic[key].success){
  64. MiniLocation._watchDic[key].success(rst);
  65. }
  66. }
  67. }
  68. MiniLocation._myError=function(res){
  69. var key;
  70. for (key in MiniLocation._watchDic){
  71. if (MiniLocation._watchDic[key].error){
  72. MiniLocation._watchDic[key].error(res);
  73. }
  74. }
  75. }
  76. MiniLocation._watchDic={};
  77. MiniLocation._curID=0;
  78. return MiniLocation;
  79. })()
  80. /**@private **/
  81. //class laya.qg.mini.MiniFileMgr
  82. var MiniFileMgr$3=(function(){
  83. function MiniFileMgr(){}
  84. __class(MiniFileMgr,'laya.qg.mini.MiniFileMgr',null,'MiniFileMgr$3');
  85. MiniFileMgr.isLocalNativeFile=function(url){
  86. for(var i=0,sz=QGMiniAdapter.nativefiles.length;i<sz;i++){
  87. if(url.indexOf(QGMiniAdapter.nativefiles[i])!=-1)
  88. return true;
  89. }
  90. return false;
  91. }
  92. MiniFileMgr.getFileInfo=function(fileUrl){
  93. var fileNativePath=fileUrl;
  94. var fileObj=MiniFileMgr.filesListObj[fileNativePath];
  95. if (fileObj==null)
  96. return null;
  97. else
  98. return fileObj;
  99. return null;
  100. }
  101. MiniFileMgr.read=function(filePath,encoding,callBack,readyUrl,isSaveFile,fileType){
  102. (encoding===void 0)&& (encoding="ascill");
  103. (readyUrl===void 0)&& (readyUrl="");
  104. (isSaveFile===void 0)&& (isSaveFile=false);
  105. (fileType===void 0)&& (fileType="");
  106. var fileUrl;
  107. if(readyUrl!="" && (readyUrl.indexOf("http://")!=-1 || readyUrl.indexOf("https://")!=-1)){
  108. fileUrl=MiniFileMgr.getFileNativePath(filePath)
  109. }else{
  110. fileUrl=filePath;
  111. }
  112. fileUrl=URL.getAdptedFilePath(fileUrl);
  113. MiniFileMgr.fs.readFile({filePath:fileUrl,encoding:encoding,success:function (data){
  114. callBack !=null && callBack.runWith([0,data]);
  115. },fail:function (data){
  116. if (data && readyUrl !="")
  117. MiniFileMgr.downFiles(readyUrl,encoding,callBack,readyUrl,isSaveFile,fileType);
  118. else
  119. callBack !=null && callBack.runWith([1]);
  120. }});
  121. }
  122. MiniFileMgr.downFiles=function(fileUrl,encoding,callBack,readyUrl,isSaveFile,fileType,isAutoClear){
  123. (encoding===void 0)&& (encoding="ascii");
  124. (readyUrl===void 0)&& (readyUrl="");
  125. (isSaveFile===void 0)&& (isSaveFile=false);
  126. (fileType===void 0)&& (fileType="");
  127. (isAutoClear===void 0)&& (isAutoClear=true);
  128. var downloadTask=MiniFileMgr.wxdown({url:fileUrl,success:function (data){
  129. if (data.statusCode===200)
  130. MiniFileMgr.readFile(data.tempFilePath,encoding,callBack,readyUrl,isSaveFile,fileType,isAutoClear);
  131. else
  132. if(data.statusCode===403){
  133. callBack !=null && callBack.runWith([0,fileUrl]);
  134. }else{
  135. callBack !=null && callBack.runWith([1,data]);
  136. }
  137. },fail:function (data){
  138. callBack !=null && callBack.runWith([1,data]);
  139. }});
  140. downloadTask.onProgressUpdate(function(data){
  141. callBack !=null && callBack.runWith([2,data.progress]);
  142. });
  143. }
  144. MiniFileMgr.readFile=function(filePath,encoding,callBack,readyUrl,isSaveFile,fileType,isAutoClear){
  145. (encoding===void 0)&& (encoding="ascill");
  146. (readyUrl===void 0)&& (readyUrl="");
  147. (isSaveFile===void 0)&& (isSaveFile=false);
  148. (fileType===void 0)&& (fileType="");
  149. (isAutoClear===void 0)&& (isAutoClear=true);
  150. filePath=URL.getAdptedFilePath(filePath);
  151. MiniFileMgr.fs.readFile({filePath:filePath,encoding:encoding,success:function (data){
  152. if (filePath.indexOf("http://")!=-1 || filePath.indexOf("https://")!=-1){
  153. if(QGMiniAdapter.autoCacheFile || isSaveFile){
  154. MiniFileMgr.copyFile(filePath,readyUrl,callBack,encoding,isAutoClear);
  155. }
  156. }
  157. else
  158. callBack !=null && callBack.runWith([0,data]);
  159. },fail:function (data){
  160. if (data)
  161. callBack !=null && callBack.runWith([1,data]);
  162. }});
  163. }
  164. MiniFileMgr.downOtherFiles=function(fileUrl,callBack,readyUrl,isSaveFile,isAutoClear){
  165. (readyUrl===void 0)&& (readyUrl="");
  166. (isSaveFile===void 0)&& (isSaveFile=false);
  167. (isAutoClear===void 0)&& (isAutoClear=true);
  168. MiniFileMgr.wxdown({url:fileUrl,success:function (data){
  169. if (data.statusCode===200){
  170. if((QGMiniAdapter.autoCacheFile || isSaveFile)&& readyUrl.indexOf("qlogo.cn")==-1 && readyUrl.indexOf(".php")==-1)
  171. MiniFileMgr.copyFile(data.tempFilePath,readyUrl,callBack,"",isAutoClear);
  172. else
  173. callBack !=null && callBack.runWith([0,data.tempFilePath]);
  174. }else{
  175. callBack !=null && callBack.runWith([1,data]);
  176. }
  177. },fail:function (data){
  178. console.log("====downloadfile fail:"+JSON.stringify(data));
  179. callBack !=null && callBack.runWith([1,data]);
  180. }});
  181. }
  182. MiniFileMgr.downLoadFile=function(fileUrl,fileType,callBack,encoding){
  183. (fileType===void 0)&& (fileType="");
  184. (encoding===void 0)&& (encoding="ascii");
  185. if(QGMiniAdapter.window.navigator.userAgent.indexOf('MiniGame')<0 && QGMiniAdapter.window.navigator.userAgent.indexOf('OPPO')<0){
  186. Laya.loader.load(fileUrl,callBack);
  187. }else{
  188. if(fileType==/*laya.net.Loader.IMAGE*/"image" || fileType==/*laya.net.Loader.SOUND*/"sound")
  189. MiniFileMgr.downOtherFiles(fileUrl,callBack,fileUrl,true,false);
  190. else
  191. MiniFileMgr.downFiles(fileUrl,encoding,callBack,fileUrl,true,fileType,false);
  192. }
  193. }
  194. MiniFileMgr.copyFile=function(tempFilePath,readyUrl,callBack,encoding,isAutoClear){
  195. (encoding===void 0)&& (encoding="");
  196. (isAutoClear===void 0)&& (isAutoClear=true);
  197. var temp=tempFilePath.split("/");
  198. var tempFileName=temp[temp.length-1];
  199. var fileurlkey=readyUrl;
  200. var fileObj=MiniFileMgr.getFileInfo(readyUrl);
  201. var saveFilePath=MiniFileMgr.getFileNativePath(tempFileName);
  202. var totalSize=50 *1024 *1024;
  203. var chaSize=4 *1024 *1024;
  204. var fileUseSize=MiniFileMgr.getCacheUseSize();
  205. if (fileObj){
  206. if (fileObj.readyUrl !=readyUrl){
  207. MiniFileMgr.fs.getFileInfo({
  208. filePath:tempFilePath,
  209. success:function (data){
  210. if((isAutoClear && (fileUseSize+chaSize+data.size)>=totalSize)){
  211. if(data.size > QGMiniAdapter.minClearSize)
  212. QGMiniAdapter.minClearSize=data.size;
  213. MiniFileMgr.onClearCacheRes();
  214. }
  215. MiniFileMgr.deleteFile(tempFileName,readyUrl,callBack,encoding,data.size);
  216. },
  217. fail:function (data){
  218. callBack !=null && callBack.runWith([1,data]);
  219. }
  220. });
  221. }
  222. else
  223. callBack !=null && callBack.runWith([0]);
  224. }else{
  225. MiniFileMgr.fs.getFileInfo({
  226. filePath:tempFilePath,
  227. success:function (data){
  228. if((isAutoClear && (fileUseSize+chaSize+data.size)>=totalSize)){
  229. if(data.size > QGMiniAdapter.minClearSize)
  230. QGMiniAdapter.minClearSize=data.size;
  231. MiniFileMgr.onClearCacheRes();
  232. }
  233. MiniFileMgr.fs.copyFile({srcPath:tempFilePath,destPath:saveFilePath,success:function (data2){
  234. MiniFileMgr.onSaveFile(readyUrl,tempFileName,true,encoding,callBack,data.size);
  235. },fail:function (data){
  236. callBack !=null && callBack.runWith([1,data]);
  237. }});
  238. },
  239. fail:function (data){
  240. callBack !=null && callBack.runWith([1,data]);
  241. }
  242. });
  243. }
  244. }
  245. MiniFileMgr.onClearCacheRes=function(){
  246. var memSize=QGMiniAdapter.minClearSize;
  247. var tempFileListArr=[];
  248. for(var key in MiniFileMgr.filesListObj){
  249. tempFileListArr.push(MiniFileMgr.filesListObj[key]);
  250. }
  251. MiniFileMgr.sortOn(tempFileListArr,"times",16);
  252. var clearSize=0;
  253. for(var i=1,sz=tempFileListArr.length;i<sz;i++){
  254. var fileObj=tempFileListArr[i];
  255. if(clearSize >=memSize)
  256. break ;
  257. clearSize+=fileObj.size;
  258. MiniFileMgr.deleteFile("",fileObj.readyUrl);
  259. }
  260. }
  261. MiniFileMgr.sortOn=function(array,name,options){
  262. (options===void 0)&& (options=0);
  263. if (options==16)return array.sort(function(a,b){return a[name]-b[name];});
  264. if (options==(16 | 2))return array.sort(function(a,b){return b[name]-a[name];});
  265. return array.sort(function(a,b){return a[name]-b[name] });
  266. }
  267. MiniFileMgr.getFileNativePath=function(fileName){
  268. return laya.qg.mini.MiniFileMgr.fileNativeDir+"/"+fileName;
  269. }
  270. MiniFileMgr.deleteFile=function(tempFileName,readyUrl,callBack,encoding,fileSize){
  271. (readyUrl===void 0)&& (readyUrl="");
  272. (encoding===void 0)&& (encoding="");
  273. (fileSize===void 0)&& (fileSize=0);
  274. var fileObj=MiniFileMgr.getFileInfo(readyUrl);
  275. var deleteFileUrl=MiniFileMgr.getFileNativePath(fileObj.md5);
  276. MiniFileMgr.fs.unlink({filePath:deleteFileUrl,success:function (data){
  277. var isAdd=tempFileName !="" ? true :false;
  278. if(tempFileName !=""){
  279. var saveFilePath=MiniFileMgr.getFileNativePath(tempFileName);
  280. MiniFileMgr.fs.copyFile({srcPath:tempFileName,destPath:saveFilePath,success:function (data){
  281. MiniFileMgr.onSaveFile(readyUrl,tempFileName,isAdd,encoding,callBack,data.size);
  282. },fail:function (data){
  283. callBack !=null && callBack.runWith([1,data]);
  284. }});
  285. }else{
  286. MiniFileMgr.onSaveFile(readyUrl,tempFileName,isAdd,encoding,callBack,fileSize);
  287. }
  288. },fail:function (data){
  289. }});
  290. }
  291. MiniFileMgr.deleteAll=function(){
  292. var tempFileListArr=[];
  293. for(var key in MiniFileMgr.filesListObj){
  294. tempFileListArr.push(MiniFileMgr.filesListObj[key]);
  295. }
  296. for(var i=1,sz=tempFileListArr.length;i<sz;i++){
  297. var fileObj=tempFileListArr[i];
  298. MiniFileMgr.deleteFile("",fileObj.readyUrl);
  299. }
  300. if(laya.qg.mini.MiniFileMgr.filesListObj && laya.qg.mini.MiniFileMgr.filesListObj.fileUsedSize){
  301. laya.qg.mini.MiniFileMgr.filesListObj.fileUsedSize=0;
  302. }
  303. laya.qg.mini.MiniFileMgr.writeFilesList("",JSON.stringify({}),false);
  304. }
  305. MiniFileMgr.onSaveFile=function(readyUrl,md5Name,isAdd,encoding,callBack,fileSize){
  306. (isAdd===void 0)&& (isAdd=true);
  307. (encoding===void 0)&& (encoding="");
  308. (fileSize===void 0)&& (fileSize=0);
  309. var fileurlkey=readyUrl;
  310. if(MiniFileMgr.filesListObj['fileUsedSize']==null)
  311. MiniFileMgr.filesListObj['fileUsedSize']=0;
  312. if(isAdd){
  313. var fileNativeName=MiniFileMgr.getFileNativePath(md5Name);
  314. MiniFileMgr.filesListObj[fileurlkey]={md5:md5Name,readyUrl:readyUrl,size:fileSize,times:Browser.now(),encoding:encoding};
  315. MiniFileMgr.filesListObj['fileUsedSize']=parseInt(MiniFileMgr.filesListObj['fileUsedSize'])+fileSize;
  316. MiniFileMgr.writeFilesList(fileurlkey,JSON.stringify(MiniFileMgr.filesListObj),true);
  317. callBack !=null && callBack.runWith([0]);
  318. }else{
  319. if(MiniFileMgr.filesListObj[fileurlkey]){
  320. var deletefileSize=parseInt(MiniFileMgr.filesListObj[fileurlkey].size);
  321. MiniFileMgr.filesListObj['fileUsedSize']=parseInt(MiniFileMgr.filesListObj['fileUsedSize'])-deletefileSize;
  322. delete MiniFileMgr.filesListObj[fileurlkey];
  323. MiniFileMgr.writeFilesList(fileurlkey,JSON.stringify(MiniFileMgr.filesListObj),false);
  324. callBack !=null && callBack.runWith([0]);
  325. }
  326. }
  327. }
  328. MiniFileMgr.writeFilesList=function(fileurlkey,filesListStr,isAdd){
  329. var listFilesPath=MiniFileMgr.fileNativeDir+"/"+MiniFileMgr.fileListName;
  330. MiniFileMgr.fs.writeFile({filePath:listFilesPath,encoding:'utf8',data:filesListStr,success:function (data){
  331. },fail:function (data){
  332. }});
  333. if(!QGMiniAdapter.isZiYu &&QGMiniAdapter.isPosMsgYu){
  334. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({url:fileurlkey,data:MiniFileMgr.filesListObj[fileurlkey],isLoad:"filenative",isAdd:isAdd});
  335. }
  336. }
  337. MiniFileMgr.getCacheUseSize=function(){
  338. if(MiniFileMgr.filesListObj && MiniFileMgr.filesListObj['fileUsedSize'])
  339. return MiniFileMgr.filesListObj['fileUsedSize'];
  340. return 0;
  341. }
  342. MiniFileMgr.existDir=function(dirPath,callBack){
  343. MiniFileMgr.fs.mkdir({dirPath:dirPath,success:function (data){
  344. callBack !=null && callBack.runWith([0,{data:JSON.stringify({})}]);
  345. },fail:function (data){
  346. if (data.errMsg.indexOf("file already exists")!=-1)
  347. MiniFileMgr.readSync(MiniFileMgr.fileListName,"utf8",callBack);
  348. else
  349. callBack !=null && callBack.runWith([1,data]);
  350. }});
  351. }
  352. MiniFileMgr.readSync=function(filePath,encoding,callBack,readyUrl){
  353. (encoding===void 0)&& (encoding="ascill");
  354. (readyUrl===void 0)&& (readyUrl="");
  355. var fileUrl=MiniFileMgr.getFileNativePath(filePath);
  356. var filesListStr
  357. try{
  358. MiniFileMgr.fs.readFile({
  359. filePath:fileUrl,
  360. encoding:encoding,
  361. success:function (data){
  362. filesListStr=data.data;
  363. callBack !=null && callBack.runWith([0,{data:filesListStr}]);
  364. },
  365. fail:function (){
  366. callBack !=null && callBack.runWith([1]);
  367. }
  368. });
  369. }
  370. catch(error){
  371. callBack !=null && callBack.runWith([1]);
  372. }
  373. }
  374. MiniFileMgr.setNativeFileDir=function(value){
  375. MiniFileMgr.fileNativeDir=QGMiniAdapter.window.qg.env.USER_DATA_PATH+value;
  376. }
  377. MiniFileMgr.filesListObj={};
  378. MiniFileMgr.fileNativeDir=null;
  379. MiniFileMgr.fileListName="layaairfiles.txt";
  380. MiniFileMgr.ziyuFileData={};
  381. MiniFileMgr.ziyuFileTextureData={};
  382. MiniFileMgr.loadPath="";
  383. MiniFileMgr.DESCENDING=2;
  384. MiniFileMgr.NUMERIC=16;
  385. __static(MiniFileMgr,
  386. ['fs',function(){return this.fs=QGMiniAdapter.window.qg.getFileSystemManager();},'wxdown',function(){return this.wxdown=QGMiniAdapter.window.qg.downloadFile;}
  387. ]);
  388. return MiniFileMgr;
  389. })()
  390. /**
  391. *视频类
  392. *@author xiaosong
  393. *@date-2019-04-22
  394. */
  395. //class laya.qg.mini.MiniVideo
  396. var MiniVideo$1=(function(){
  397. function MiniVideo(width,height){
  398. /**视频是否播放结束**/
  399. this.videoend=false;
  400. this.videourl="";
  401. this.videoElement=null;
  402. this.videoW=NaN;
  403. this.videoH=NaN;
  404. this.onPlayFunc=null;
  405. this.onEndedFunC=null;
  406. /**视频的总时⻓长,单位为秒**/
  407. this._duration=NaN;
  408. /**视频播放的当前位置**/
  409. this.position=NaN;
  410. (width===void 0)&& (width=320);
  411. (height===void 0)&& (height=240);
  412. this.videoW=width;
  413. this.videoH=height;
  414. }
  415. __class(MiniVideo,'laya.qg.mini.MiniVideo',null,'MiniVideo$1');
  416. var __proto=MiniVideo.prototype;
  417. __proto.on=function(eventType,ths,callBack){
  418. if(eventType=="loadedmetadata"){
  419. this.onPlayFunc=callBack.bind(ths);
  420. }else if(eventType=="ended"){
  421. this.onEndedFunC=callBack.bind(ths);
  422. }
  423. this.videoElement.onTimeUpdate=this.onTimeUpdateFunc.bind(this);
  424. }
  425. __proto.onTimeUpdateFunc=function(data){
  426. this.position=data.position;
  427. this._duration=data.duration;
  428. }
  429. __proto.onPlayFunction=function(){
  430. if(this.videoElement)
  431. this.videoElement.readyState=200;
  432. this.onPlayFunc !=null && this.onPlayFunc();
  433. }
  434. __proto.onEndedFunction=function(){
  435. this.videoend=true;
  436. this.onEndedFunC !=null && this.onEndedFunC();
  437. }
  438. __proto.off=function(eventType,ths,callBack){
  439. if(eventType=="loadedmetadata"){
  440. this.onPlayFunc=callBack.bind(ths);
  441. this.videoElement.offPlay=this.onPlayFunction.bind(this);
  442. }else if(eventType=="ended"){
  443. this.onEndedFunC=callBack.bind(ths);
  444. this.videoElement.offEnded=this.onEndedFunction.bind(this);
  445. }
  446. }
  447. /**
  448. *设置播放源。
  449. *@param url 播放源路径。
  450. */
  451. __proto.load=function(url){
  452. if(!this.videoElement){
  453. this.videoElement=QGMiniAdapter.window.qg.createVideo({width:this.videoW,height:this.videoH,autoplay:true,src:url});
  454. this.videoElement.onPlay=this.onPlayFunction.bind(this);
  455. this.videoElement.onEnded=this.onEndedFunction.bind(this);
  456. }else{
  457. this.videoElement.src=url;
  458. }
  459. }
  460. /**
  461. *开始播放视频。
  462. */
  463. __proto.play=function(){
  464. if(!this.videoElement)
  465. return;
  466. this.videoend=false;
  467. this.videoElement.play();
  468. }
  469. /**
  470. *暂停视频播放。
  471. */
  472. __proto.pause=function(){
  473. if(!this.videoElement)
  474. return;
  475. this.videoend=true;
  476. this.videoElement.pause();
  477. }
  478. /**
  479. *设置大小
  480. *@param width
  481. *@param height
  482. */
  483. __proto.size=function(width,height){
  484. if(!this.videoElement)
  485. return;
  486. this.videoElement.width=width;
  487. this.videoElement.height=height;
  488. }
  489. __proto.destroy=function(){
  490. if(this.videoElement)
  491. this.videoElement.destroy();
  492. this.videoElement=null;
  493. this.onEndedFunC=null;
  494. this.onPlayFunc=null;
  495. this.videoend=false;
  496. this.videourl=null;
  497. }
  498. /**
  499. *重新加载视频。
  500. */
  501. __proto.reload=function(){
  502. if(!this.videoElement)
  503. return;
  504. this.videoElement.src=this.videourl;
  505. }
  506. /**
  507. *获取视频长度(秒)。ready事件触发后可用。
  508. */
  509. __getset(0,__proto,'duration',function(){
  510. return this._duration;
  511. });
  512. /**
  513. *返回视频是否暂停
  514. */
  515. __getset(0,__proto,'paused',function(){
  516. if(!this.videoElement)
  517. return false;
  518. return this.videoElement.paused;
  519. });
  520. /**
  521. *设置或返回音频/视频是否应在结束时重新播放。
  522. */
  523. __getset(0,__proto,'loop',function(){
  524. if(!this.videoElement)
  525. return false;
  526. return this.videoElement.loop;
  527. },function(value){
  528. if(!this.videoElement)
  529. return;
  530. this.videoElement.loop=value;
  531. });
  532. /**
  533. *设置和获取当前播放头位置。
  534. */
  535. __getset(0,__proto,'currentTime',function(){
  536. if(!this.videoElement)
  537. return 0;
  538. return this.videoElement.initialTime;
  539. },function(value){
  540. if(!this.videoElement)
  541. return;
  542. this.videoElement.initialTime=value;
  543. });
  544. /**
  545. *返回音频/视频的播放是否已结束
  546. */
  547. __getset(0,__proto,'ended',function(){
  548. return this.videoend;
  549. });
  550. /**
  551. *获取和设置静音状态。
  552. */
  553. __getset(0,__proto,'muted',function(){
  554. if(!this.videoElement)
  555. return false;
  556. return this.videoElement.muted;
  557. },function(value){
  558. if(!this.videoElement)
  559. return;
  560. this.videoElement.muted=value;
  561. });
  562. /**
  563. *获取视频源尺寸。ready事件触发后可用。
  564. */
  565. __getset(0,__proto,'videoWidth',function(){
  566. if(!this.videoElement)
  567. return 0;
  568. return this.videoElement.width;
  569. });
  570. __getset(0,__proto,'videoHeight',function(){
  571. if(!this.videoElement)
  572. return 0;
  573. return this.videoElement.height;
  574. });
  575. /**
  576. *playbackRate 属性设置或返回音频/视频的当前播放速度。如:
  577. *<ul>
  578. *<li>1.0 正常速度</li>
  579. *<li>0.5 半速(更慢)</li>
  580. *<li>2.0 倍速(更快)</li>
  581. *<li>-1.0 向后,正常速度</li>
  582. *<li>-0.5 向后,半速</li>
  583. *</ul>
  584. *<p>只有 Google Chrome 和 Safari 支持 playbackRate 属性。</p>
  585. */
  586. __getset(0,__proto,'playbackRate',function(){
  587. if(!this.videoElement)
  588. return 0;
  589. return this.videoElement.playbackRate;
  590. },function(value){
  591. if(!this.videoElement)
  592. return;
  593. this.videoElement.playbackRate=value;
  594. });
  595. __getset(0,__proto,'x',function(){
  596. if(!this.videoElement)
  597. return 0;
  598. return this.videoElement.x;
  599. },function(value){
  600. if(!this.videoElement)
  601. return;
  602. this.videoElement.x=value;
  603. });
  604. __getset(0,__proto,'y',function(){
  605. if(!this.videoElement)
  606. return 0;
  607. return this.videoElement.y;
  608. },function(value){
  609. if(!this.videoElement)
  610. return;
  611. this.videoElement.y=value;
  612. });
  613. /**
  614. *获取当前播放源路径。
  615. */
  616. __getset(0,__proto,'currentSrc',function(){
  617. return this.videoElement.src;
  618. });
  619. MiniVideo.__init__=function(){
  620. /*__JS__ */laya.device.media.Video=MiniVideo;
  621. }
  622. return MiniVideo;
  623. })()
  624. /**@private **/
  625. //class laya.qg.mini.MiniLocalStorage
  626. var MiniLocalStorage$3=(function(){
  627. function MiniLocalStorage(){}
  628. __class(MiniLocalStorage,'laya.qg.mini.MiniLocalStorage',null,'MiniLocalStorage$3');
  629. MiniLocalStorage.__init__=function(){
  630. MiniLocalStorage.items=MiniLocalStorage;
  631. }
  632. MiniLocalStorage.setItem=function(key,value){
  633. try{
  634. QGMiniAdapter.window.qg.setStorageSync(key,value);
  635. }
  636. catch(error){
  637. QGMiniAdapter.window.qg.setStorage({
  638. key:key,
  639. data:value
  640. });
  641. }
  642. }
  643. MiniLocalStorage.getItem=function(key){
  644. return QGMiniAdapter.window.qg.getStorageSync(key);
  645. }
  646. MiniLocalStorage.setJSON=function(key,value){
  647. try{
  648. MiniLocalStorage.setItem(key,JSON.stringify(value));
  649. }
  650. catch(error){
  651. MiniLocalStorage.setItem(key,value);
  652. }
  653. }
  654. MiniLocalStorage.getJSON=function(key){
  655. try{
  656. return JSON.parse(MiniLocalStorage.getItem(key));
  657. }
  658. catch(error){
  659. return MiniLocalStorage.getItem(key);
  660. }
  661. }
  662. MiniLocalStorage.removeItem=function(key){
  663. QGMiniAdapter.window.qg.removeStorageSync(key);
  664. }
  665. MiniLocalStorage.clear=function(){
  666. QGMiniAdapter.window.qg.clearStorageSync();
  667. }
  668. MiniLocalStorage.getStorageInfoSync=function(){
  669. try {
  670. var res=QGMiniAdapter.window.qg.getStorageInfoSync()
  671. console.log(res.keys)
  672. console.log(res.currentSize)
  673. console.log(res.limitSize)
  674. return res;
  675. }catch (e){}
  676. return null;
  677. }
  678. MiniLocalStorage.support=true;
  679. MiniLocalStorage.items=null;
  680. return MiniLocalStorage;
  681. })()
  682. /**@private **/
  683. //class laya.qg.mini.MiniImage
  684. var MiniImage$3=(function(){
  685. function MiniImage(){}
  686. __class(MiniImage,'laya.qg.mini.MiniImage',null,'MiniImage$3');
  687. var __proto=MiniImage.prototype;
  688. /**@private **/
  689. __proto._loadImage=function(url){
  690. var thisLoader=this;
  691. if (QGMiniAdapter.isZiYu){
  692. MiniImage.onCreateImage(url,thisLoader,true);
  693. return;
  694. };
  695. var isTransformUrl=false;
  696. if (!MiniFileMgr$3.isLocalNativeFile(url)){
  697. isTransformUrl=true;
  698. url=URL.formatURL(url);
  699. }else{
  700. if (url.indexOf("http://usr/")==-1&&(url.indexOf("http://")!=-1 || url.indexOf("https://")!=-1)){
  701. if(MiniFileMgr$3.loadPath !=""){
  702. url=url.split(MiniFileMgr$3.loadPath)[1];
  703. }else{
  704. var tempStr=URL.rootPath !="" ? URL.rootPath :URL.basePath;
  705. var tempUrl=url;
  706. if(tempStr !="")
  707. url=url.split(tempStr)[1];
  708. if(!url){
  709. url=tempUrl;
  710. }
  711. }
  712. }
  713. if (QGMiniAdapter.subNativeFiles && QGMiniAdapter.subNativeheads.length==0){
  714. for (var key in QGMiniAdapter.subNativeFiles){
  715. var tempArr=QGMiniAdapter.subNativeFiles[key];
  716. QGMiniAdapter.subNativeheads=QGMiniAdapter.subNativeheads.concat(tempArr);
  717. for (var aa=0;aa < tempArr.length;aa++){
  718. QGMiniAdapter.subMaps[tempArr[aa]]=key+"/"+tempArr[aa];
  719. }
  720. }
  721. }
  722. if(QGMiniAdapter.subNativeFiles && url.indexOf("/")!=-1){
  723. var curfileHead=url.split("/")[0]+"/";
  724. if(curfileHead && QGMiniAdapter.subNativeheads.indexOf(curfileHead)!=-1){
  725. var newfileHead=QGMiniAdapter.subMaps[curfileHead];
  726. url=url.replace(curfileHead,newfileHead);
  727. }
  728. }
  729. }
  730. if (!MiniFileMgr$3.getFileInfo(url)){
  731. if (url.indexOf('http://usr/')==-1&&(url.indexOf("http://")!=-1 || url.indexOf("https://")!=-1)){
  732. if(QGMiniAdapter.isZiYu){
  733. MiniImage.onCreateImage(url,thisLoader,true);
  734. }else{
  735. MiniFileMgr$3.downOtherFiles(encodeURI(url),new Handler(MiniImage,MiniImage.onDownImgCallBack,[url,thisLoader]),url);
  736. }
  737. }
  738. else
  739. MiniImage.onCreateImage(url,thisLoader,true);
  740. }else {
  741. MiniImage.onCreateImage(url,thisLoader,!isTransformUrl);
  742. }
  743. }
  744. MiniImage.onDownImgCallBack=function(sourceUrl,thisLoader,errorCode,tempFilePath){
  745. (tempFilePath===void 0)&& (tempFilePath="");
  746. if (!errorCode)
  747. MiniImage.onCreateImage(sourceUrl,thisLoader,false,tempFilePath);
  748. else {
  749. thisLoader.onError(null);
  750. }
  751. }
  752. MiniImage.onCreateImage=function(sourceUrl,thisLoader,isLocal,tempFilePath){
  753. (isLocal===void 0)&& (isLocal=false);
  754. (tempFilePath===void 0)&& (tempFilePath="");
  755. var fileNativeUrl;
  756. if(QGMiniAdapter.autoCacheFile){
  757. if (!isLocal){
  758. if(tempFilePath !=""){
  759. fileNativeUrl=tempFilePath;
  760. }else{
  761. var fileObj=MiniFileMgr$3.getFileInfo(sourceUrl);
  762. var fileMd5Name=fileObj.md5;
  763. fileNativeUrl=MiniFileMgr$3.getFileNativePath(fileMd5Name);
  764. }
  765. }else
  766. if(QGMiniAdapter.isZiYu){
  767. var tempUrl=URL.formatURL(sourceUrl);
  768. if(MiniFileMgr$3.ziyuFileTextureData[tempUrl]){
  769. fileNativeUrl=MiniFileMgr$3.ziyuFileTextureData[tempUrl];
  770. }else
  771. fileNativeUrl=sourceUrl;
  772. }else
  773. fileNativeUrl=sourceUrl;
  774. }else{
  775. if(!isLocal)
  776. fileNativeUrl=tempFilePath;
  777. else
  778. fileNativeUrl=sourceUrl;
  779. }
  780. if (thisLoader._imgCache==null)
  781. thisLoader._imgCache={};
  782. var image;
  783. function clear (){
  784. var img=thisLoader._imgCache[sourceUrl];
  785. if (img){
  786. img.onload=null;
  787. img.onerror=null;
  788. delete thisLoader._imgCache[sourceUrl];
  789. }
  790. };
  791. var onerror=function (){
  792. clear();
  793. thisLoader.event(/*laya.events.Event.ERROR*/"error","Load image failed");
  794. }
  795. if (thisLoader._type=="nativeimage"){
  796. var onload=function (){
  797. clear();
  798. thisLoader.onLoaded(image);
  799. };
  800. image=new Browser.window.Image();
  801. image.crossOrigin="";
  802. image.onload=onload;
  803. image.onerror=onerror;
  804. image.src=fileNativeUrl;
  805. thisLoader._imgCache[sourceUrl]=image;
  806. }else {
  807. var imageSource=new Browser.window.Image();
  808. onload=function (){
  809. image=HTMLImage.create(imageSource.width,imageSource.height);
  810. image.loadImageSource(imageSource,true);
  811. image._setCreateURL(sourceUrl);
  812. clear();
  813. thisLoader.onLoaded(image);
  814. };
  815. imageSource.crossOrigin="";
  816. imageSource.onload=onload;
  817. imageSource.onerror=onerror;
  818. imageSource.src=fileNativeUrl;
  819. thisLoader._imgCache[sourceUrl]=imageSource;
  820. }
  821. }
  822. return MiniImage;
  823. })()
  824. //class laya.qg.mini.QGMiniAdapter
  825. var QGMiniAdapter=(function(){
  826. function QGMiniAdapter(){}
  827. __class(QGMiniAdapter,'laya.qg.mini.QGMiniAdapter');
  828. QGMiniAdapter.getJson=function(data){
  829. return JSON.parse(data);
  830. }
  831. QGMiniAdapter.enable=function(){
  832. QGMiniAdapter.init(Laya.isWXPosMsg,Laya.isWXOpenDataContext);
  833. }
  834. QGMiniAdapter.init=function(isPosMsg,isSon){
  835. (isPosMsg===void 0)&& (isPosMsg=false);
  836. (isSon===void 0)&& (isSon=false);
  837. if (QGMiniAdapter._inited)return;
  838. QGMiniAdapter._inited=true;
  839. QGMiniAdapter.window=/*__JS__ */window;
  840. if (!QGMiniAdapter.window.hasOwnProperty('qg')&&QGMiniAdapter.window.navigator.userAgent.indexOf('OPPO')< 0)return;
  841. QGMiniAdapter.isZiYu=isSon;
  842. QGMiniAdapter.isPosMsgYu=isPosMsg;
  843. QGMiniAdapter.EnvConfig={};
  844. if (!QGMiniAdapter.isZiYu){
  845. MiniFileMgr$3.setNativeFileDir("/layaairGame");
  846. MiniFileMgr$3.existDir(MiniFileMgr$3.fileNativeDir,Handler.create(QGMiniAdapter,QGMiniAdapter.onMkdirCallBack));
  847. }
  848. QGMiniAdapter.window.qg.getSystemInfo({
  849. success:function (data){
  850. QGMiniAdapter.systemInfo=data;
  851. }
  852. });
  853. QGMiniAdapter.window.focus=function (){
  854. };
  855. Laya['_getUrlPath']=function (){
  856. return "";
  857. };
  858. Laya['getUrlPath']=function (){
  859. return "";
  860. };
  861. QGMiniAdapter.window.logtime=function (str){
  862. };
  863. QGMiniAdapter.window.alertTimeLog=function (str){
  864. };
  865. QGMiniAdapter.window.resetShareInfo=function (){
  866. };
  867. QGMiniAdapter.window.document.body.appendChild=function (){
  868. };
  869. QGMiniAdapter.EnvConfig.pixelRatioInt=0;
  870. Browser["_pixelRatio"]=QGMiniAdapter.pixelRatio();
  871. QGMiniAdapter._preCreateElement=Browser.createElement;
  872. Browser["createElement"]=QGMiniAdapter.createElement;
  873. RunDriver.createShaderCondition=QGMiniAdapter.createShaderCondition;
  874. Utils['parseXMLFromString']=QGMiniAdapter.parseXMLFromString;
  875. Input['_createInputElement']=MiniInput$3['_createInputElement'];
  876. QGMiniAdapter.EnvConfig.load=Loader.prototype.load;
  877. Loader.prototype.load=MiniLoader$3.prototype.load;
  878. Loader.prototype._loadImage=MiniImage$3.prototype._loadImage;
  879. Config.useRetinalCanvas=true;
  880. QGMiniAdapter.window.qg.onMessage && QGMiniAdapter.window.qg.onMessage(QGMiniAdapter._onMessage);
  881. }
  882. QGMiniAdapter._onMessage=function(data){
  883. switch (data.type){
  884. case "changeMatrix":
  885. Laya.stage.transform.identity();
  886. Laya.stage._width=data.w;
  887. Laya.stage._height=data.h;
  888. Laya.stage._canvasTransform=new Matrix(data.a,data.b,data.c,data.d,data.tx,data.ty);
  889. break ;
  890. case "display":
  891. Laya.stage.frameRate=data.rate || /*laya.display.Stage.FRAME_FAST*/"fast";
  892. break ;
  893. case "undisplay":
  894. Laya.stage.frameRate=/*laya.display.Stage.FRAME_SLEEP*/"sleep";
  895. break ;
  896. }
  897. if (data['isLoad']=="opendatacontext"){
  898. if (data.url){
  899. MiniFileMgr$3.ziyuFileData[data.url]=data.atlasdata;
  900. MiniFileMgr$3.ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl;
  901. }
  902. }else if (data['isLoad']=="openJsondatacontext"){
  903. if (data.url){
  904. MiniFileMgr$3.ziyuFileData[data.url]=data.atlasdata;
  905. }
  906. }else if (data['isLoad']=="openJsondatacontextPic"){
  907. MiniFileMgr$3.ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl;
  908. }
  909. }
  910. QGMiniAdapter.getUrlEncode=function(url,type){
  911. if (type=="arraybuffer")
  912. return "";
  913. return "utf8";
  914. }
  915. QGMiniAdapter.downLoadFile=function(fileUrl,fileType,callBack,encoding){
  916. (fileType===void 0)&& (fileType="");
  917. (encoding===void 0)&& (encoding="utf8");
  918. var fileObj=MiniFileMgr$3.getFileInfo(fileUrl);
  919. if (!fileObj)
  920. MiniFileMgr$3.downLoadFile(fileUrl,fileType,callBack,encoding);
  921. else {
  922. callBack !=null && callBack.runWith([0]);
  923. }
  924. }
  925. QGMiniAdapter.remove=function(fileUrl,callBack){
  926. MiniFileMgr$3.deleteFile("",fileUrl,callBack,"",0);
  927. }
  928. QGMiniAdapter.removeAll=function(){
  929. MiniFileMgr$3.deleteAll();
  930. }
  931. QGMiniAdapter.hasNativeFile=function(fileUrl){
  932. return MiniFileMgr$3.isLocalNativeFile(fileUrl);
  933. }
  934. QGMiniAdapter.getFileInfo=function(fileUrl){
  935. return MiniFileMgr$3.getFileInfo(fileUrl);
  936. }
  937. QGMiniAdapter.getFileList=function(){
  938. return MiniFileMgr$3.filesListObj;
  939. }
  940. QGMiniAdapter.exitMiniProgram=function(){
  941. QGMiniAdapter.window["wx"].exitMiniProgram();
  942. }
  943. QGMiniAdapter.onMkdirCallBack=function(errorCode,data){
  944. if (!errorCode)
  945. MiniFileMgr$3.filesListObj=JSON.parse(data.data);
  946. }
  947. QGMiniAdapter.pixelRatio=function(){
  948. if (!QGMiniAdapter.EnvConfig.pixelRatioInt){
  949. try {
  950. QGMiniAdapter.systemInfo.pixelRatio=QGMiniAdapter.window.devicePixelRatio;
  951. QGMiniAdapter.EnvConfig.pixelRatioInt=QGMiniAdapter.systemInfo.pixelRatio;
  952. return QGMiniAdapter.systemInfo.pixelRatio;
  953. }catch (error){}
  954. }
  955. return QGMiniAdapter.EnvConfig.pixelRatioInt;
  956. }
  957. QGMiniAdapter.createElement=function(type){
  958. if (type=="canvas"){
  959. var _source;
  960. if (QGMiniAdapter.idx==1){
  961. if(QGMiniAdapter.isZiYu){
  962. _source=QGMiniAdapter.window.document.createElement("canvas");
  963. _source.style={};
  964. }else{
  965. _source=QGMiniAdapter.window.__canvas;
  966. }
  967. }else {
  968. _source=QGMiniAdapter.window.document.createElement("canvas");
  969. }
  970. QGMiniAdapter.idx++;
  971. return _source;
  972. }else if (type=="textarea" || type=="input"){
  973. return QGMiniAdapter.onCreateInput(type);
  974. }else if (type=="div"){
  975. var node=QGMiniAdapter._preCreateElement(type);
  976. node.contains=function (value){
  977. return null
  978. };
  979. node.removeChild=function (value){
  980. };
  981. return node;
  982. }
  983. else {
  984. return QGMiniAdapter._preCreateElement(type);
  985. }
  986. }
  987. QGMiniAdapter.onCreateInput=function(type){
  988. var node=QGMiniAdapter._preCreateElement(type);
  989. node.focus=MiniInput$3.wxinputFocus;
  990. node.blur=MiniInput$3.wxinputblur;
  991. node.style={};
  992. node.value=0;
  993. node.parentElement={};
  994. node.placeholder={};
  995. node.type={};
  996. node.setColor=function (value){
  997. };
  998. node.setType=function (value){
  999. };
  1000. node.setFontFace=function (value){
  1001. };
  1002. node.addEventListener=function (value){
  1003. };
  1004. node.contains=function (value){
  1005. return null
  1006. };
  1007. node.removeChild=function (value){
  1008. };
  1009. return node;
  1010. }
  1011. QGMiniAdapter.createShaderCondition=function(conditionScript){
  1012. var _$this=this;
  1013. var func=function (){
  1014. var abc=conditionScript;
  1015. return _$this[conditionScript.replace("this.","")];
  1016. }
  1017. return func;
  1018. }
  1019. QGMiniAdapter.sendAtlasToOpenDataContext=function(url){
  1020. if (!laya.qg.mini.QGMiniAdapter.isZiYu){
  1021. var atlasJson=Loader.getRes(URL.formatURL(url));
  1022. if (atlasJson){
  1023. var textureArr=(atlasJson.meta.image).split(",");
  1024. if (atlasJson.meta && atlasJson.meta.image){
  1025. var toloadPics=atlasJson.meta.image.split(",");
  1026. var split=url.indexOf("/")>=0 ? "/" :"\\";
  1027. var idx=url.lastIndexOf(split);
  1028. var folderPath=idx >=0 ? url.substr(0,idx+1):"";
  1029. for (var i=0,len=toloadPics.length;i < len;i++){
  1030. toloadPics[i]=folderPath+toloadPics[i];
  1031. }
  1032. }else {
  1033. toloadPics=[url.replace(".json",".png")];
  1034. }
  1035. for (i=0;i < toloadPics.length;i++){
  1036. var tempAtlasPngUrl=toloadPics[i];
  1037. QGMiniAdapter.postInfoToContext(url,tempAtlasPngUrl,atlasJson);
  1038. }
  1039. }else {
  1040. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1041. }
  1042. }
  1043. }
  1044. QGMiniAdapter.postInfoToContext=function(url,atlaspngUrl,atlasJson){
  1045. var postData={"frames":atlasJson.frames,"meta":atlasJson.meta};
  1046. var textureUrl=atlaspngUrl;
  1047. var fileObj=MiniFileMgr$3.getFileInfo(URL.formatURL(atlaspngUrl));
  1048. if (fileObj){
  1049. var fileMd5Name=fileObj.md5;
  1050. var fileNativeUrl=MiniFileMgr$3.getFileNativePath(fileMd5Name);
  1051. }else {
  1052. fileNativeUrl=textureUrl;
  1053. }
  1054. if (fileNativeUrl){
  1055. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({url:url,atlasdata:postData,imgNativeUrl:fileNativeUrl,imgReadyUrl:textureUrl,isLoad:"opendatacontext"});
  1056. }else {
  1057. throw "获取图集的磁盘url路径不存在!";
  1058. }
  1059. }
  1060. QGMiniAdapter.sendSinglePicToOpenDataContext=function(url){
  1061. var tempTextureUrl=URL.formatURL(url);
  1062. var fileObj=MiniFileMgr$3.getFileInfo(tempTextureUrl);
  1063. if (fileObj){
  1064. var fileMd5Name=fileObj.md5;
  1065. var fileNativeUrl=MiniFileMgr$3.getFileNativePath(fileMd5Name);
  1066. url=tempTextureUrl;
  1067. }else {
  1068. fileNativeUrl=url;
  1069. }
  1070. if (fileNativeUrl){
  1071. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({url:url,imgNativeUrl:fileNativeUrl,imgReadyUrl:url,isLoad:"openJsondatacontextPic"});
  1072. }else {
  1073. throw "获取图集的磁盘url路径不存在!";
  1074. }
  1075. }
  1076. QGMiniAdapter.sendJsonDataToDataContext=function(url){
  1077. if (!laya.qg.mini.QGMiniAdapter.isZiYu){
  1078. var atlasJson=Loader.getRes(url);
  1079. if (atlasJson){
  1080. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({url:url,atlasdata:atlasJson,isLoad:"openJsondatacontext"});
  1081. }else {
  1082. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1083. }
  1084. }
  1085. }
  1086. QGMiniAdapter.EnvConfig=null;
  1087. QGMiniAdapter.window=null;
  1088. QGMiniAdapter._preCreateElement=null;
  1089. QGMiniAdapter._inited=false;
  1090. QGMiniAdapter.systemInfo={};
  1091. QGMiniAdapter.isZiYu=false;
  1092. QGMiniAdapter.isPosMsgYu=false;
  1093. QGMiniAdapter.autoCacheFile=true;
  1094. QGMiniAdapter.minClearSize=(5 *1024 *1024);
  1095. QGMiniAdapter.subNativeFiles=null;
  1096. QGMiniAdapter.subNativeheads=[];
  1097. QGMiniAdapter.subMaps=[];
  1098. QGMiniAdapter.AutoCacheDownFile=false;
  1099. QGMiniAdapter.parseXMLFromString=function(value){
  1100. var rst;
  1101. var Parser;
  1102. value=value.replace(/>\s+</g,'><');
  1103. try {
  1104. /*__JS__ */rst=(new window.DOMParser()).parseFromString(value,'text/xml');
  1105. }catch (error){
  1106. throw "需要引入xml解析库文件";
  1107. }
  1108. return rst;
  1109. }
  1110. QGMiniAdapter.idx=1;
  1111. __static(QGMiniAdapter,
  1112. ['nativefiles',function(){return this.nativefiles=["layaNativeDir","wxlocal"];}
  1113. ]);
  1114. return QGMiniAdapter;
  1115. })()
  1116. /**@private **/
  1117. //class laya.qg.mini.MiniInput
  1118. var MiniInput$3=(function(){
  1119. function MiniInput(){}
  1120. __class(MiniInput,'laya.qg.mini.MiniInput',null,'MiniInput$3');
  1121. MiniInput._createInputElement=function(){
  1122. Input['_initInput'](Input['area']=Browser.createElement("textarea"));
  1123. Input['_initInput'](Input['input']=Browser.createElement("input"));
  1124. Input['inputContainer']=Browser.createElement("div");
  1125. Input['inputContainer'].style.position="absolute";
  1126. Input['inputContainer'].style.zIndex=1E5;
  1127. Browser.container.appendChild(Input['inputContainer']);
  1128. Input['inputContainer'].setPos=function (x,y){Input['inputContainer'].style.left=x+'px';Input['inputContainer'].style.top=y+'px';};
  1129. Laya.stage.on("resize",null,MiniInput._onStageResize);
  1130. QGMiniAdapter.window.qg.onWindowResize && QGMiniAdapter.window.qg.onWindowResize(function(res){
  1131. QGMiniAdapter.window.dispatchEvent && QGMiniAdapter.window.dispatchEvent("resize");
  1132. });
  1133. SoundManager._soundClass=MiniSound$3;
  1134. SoundManager._musicClass=MiniSound$3;
  1135. var model=QGMiniAdapter.systemInfo.model;
  1136. var system=QGMiniAdapter.systemInfo.system;
  1137. if(model && model.indexOf("iPhone")!=-1){
  1138. Browser.onIPhone=true;
  1139. Browser.onIOS=true;
  1140. Browser.onIPad=true;
  1141. Browser.onAndroid=false;
  1142. }
  1143. if(system && (system.indexOf("Android")!=-1 || system.indexOf("Adr")!=-1)){
  1144. Browser.onAndroid=true;
  1145. Browser.onIPhone=false;
  1146. Browser.onIOS=false;
  1147. Browser.onIPad=false;
  1148. }
  1149. }
  1150. MiniInput._onStageResize=function(){}
  1151. MiniInput.wxinputFocus=function(e){
  1152. var _inputTarget=Input['inputElement'].target;
  1153. if (_inputTarget && !_inputTarget.editable){
  1154. return;
  1155. }
  1156. QGMiniAdapter.window.qg.offKeyboardConfirm();
  1157. QGMiniAdapter.window.qg.offKeyboardInput();
  1158. QGMiniAdapter.window.qg.showKeyboard({defaultValue:_inputTarget.text,maxLength:_inputTarget.maxChars,multiple:_inputTarget.multiline,confirmHold:true,confirmType:_inputTarget["confirmType"]||'done',success:function (res){
  1159. },fail:function (res){
  1160. }});
  1161. QGMiniAdapter.window.qg.onKeyboardConfirm(function(res){
  1162. var str=res ? res.value :"";
  1163. if (_inputTarget._restrictPattern){
  1164. str=str.replace(/\u2006|\x27/g,"");
  1165. if (_inputTarget._restrictPattern.test(str)){
  1166. str=str.replace(_inputTarget._restrictPattern,"");
  1167. }
  1168. }
  1169. _inputTarget.text=str;
  1170. _inputTarget.event(/*laya.events.Event.INPUT*/"input");
  1171. laya.qg.mini.MiniInput.inputEnter(true);
  1172. _inputTarget.event("confirm");
  1173. })
  1174. QGMiniAdapter.window.qg.onKeyboardInput(function(res){
  1175. var str=res ? res.value :"";
  1176. if (!_inputTarget.multiline){
  1177. if (str.indexOf("\n")!=-1){
  1178. laya.qg.mini.MiniInput.inputEnter(false);
  1179. return;
  1180. }
  1181. }
  1182. if (_inputTarget._restrictPattern){
  1183. str=str.replace(/\u2006|\x27/g,"");
  1184. if (_inputTarget._restrictPattern.test(str)){
  1185. str=str.replace(_inputTarget._restrictPattern,"");
  1186. }
  1187. }
  1188. _inputTarget.text=str;
  1189. _inputTarget.event(/*laya.events.Event.INPUT*/"input");
  1190. laya.qg.mini.MiniInput.inputEnter(false);
  1191. });
  1192. }
  1193. MiniInput.inputEnter=function(isBool){
  1194. if(isBool){
  1195. MiniInput.hideKeyboard();
  1196. }
  1197. if(!Input['inputElement'].target)
  1198. return;
  1199. Input['inputElement'].target.focus=false;
  1200. }
  1201. MiniInput.wxinputblur=function(){}
  1202. MiniInput.hideKeyboard=function(){
  1203. QGMiniAdapter.window.qg.offKeyboardConfirm();
  1204. QGMiniAdapter.window.qg.offKeyboardInput();
  1205. QGMiniAdapter.window.qg.hideKeyboard({success:function (res){
  1206. console.log('隐藏键盘')
  1207. },fail:function (res){
  1208. console.log("隐藏键盘出错:"+(res ? res.errMsg :""));
  1209. }});
  1210. }
  1211. return MiniInput;
  1212. })()
  1213. /**@private **/
  1214. //class laya.qg.mini.MiniSound extends laya.events.EventDispatcher
  1215. var MiniSound$3=(function(_super){
  1216. function MiniSound(){
  1217. /**@private **/
  1218. this._sound=null;
  1219. /**
  1220. *@private
  1221. *声音URL
  1222. */
  1223. this.url=null;
  1224. /**
  1225. *@private
  1226. *是否已加载完成
  1227. */
  1228. this.loaded=false;
  1229. /**@private **/
  1230. this.readyUrl=null;
  1231. MiniSound.__super.call(this);
  1232. }
  1233. __class(MiniSound,'laya.qg.mini.MiniSound',_super,'MiniSound$3');
  1234. var __proto=MiniSound.prototype;
  1235. /**
  1236. *@private
  1237. *加载声音。
  1238. *@param url 地址。
  1239. *
  1240. */
  1241. __proto.load=function(url){
  1242. if (!MiniFileMgr$3.isLocalNativeFile(url)){
  1243. url=URL.formatURL(url);
  1244. }else{
  1245. if (url.indexOf("http://")!=-1 || url.indexOf("https://")!=-1){
  1246. if(MiniFileMgr$3.loadPath !=""){
  1247. url=url.split(MiniFileMgr$3.loadPath)[1];
  1248. }else{
  1249. var tempStr=URL.rootPath !="" ? URL.rootPath :URL.basePath;
  1250. if(tempStr !="")
  1251. url=url.split(tempStr)[1];
  1252. }
  1253. }
  1254. }
  1255. this.url=url;
  1256. this.readyUrl=url;
  1257. if (MiniSound._audioCache[this.readyUrl]){
  1258. this.event(/*laya.events.Event.COMPLETE*/"complete");
  1259. return;
  1260. }
  1261. if(QGMiniAdapter.autoCacheFile&&MiniFileMgr$3.getFileInfo(url)){
  1262. this.onDownLoadCallBack(url,0);
  1263. }else{
  1264. if(!QGMiniAdapter.autoCacheFile){
  1265. this.onDownLoadCallBack(url,0);
  1266. }else{
  1267. if (MiniFileMgr$3.isLocalNativeFile(url)){
  1268. tempStr=URL.rootPath !="" ? URL.rootPath :URL.basePath;
  1269. var tempUrl=url;
  1270. if(tempStr !="")
  1271. url=url.split(tempStr)[1];
  1272. if (!url){
  1273. url=tempUrl;
  1274. }
  1275. if (QGMiniAdapter.subNativeFiles && QGMiniAdapter.subNativeheads.length==0){
  1276. for (var key in QGMiniAdapter.subNativeFiles){
  1277. var tempArr=QGMiniAdapter.subNativeFiles[key];
  1278. QGMiniAdapter.subNativeheads=QGMiniAdapter.subNativeheads.concat(tempArr);
  1279. for (var aa=0;aa < tempArr.length;aa++){
  1280. QGMiniAdapter.subMaps[tempArr[aa]]=key+"/"+tempArr[aa];
  1281. }
  1282. }
  1283. }
  1284. if(QGMiniAdapter.subNativeFiles && url.indexOf("/")!=-1){
  1285. var curfileHead=url.split("/")[0]+"/";
  1286. if(curfileHead && QGMiniAdapter.subNativeheads.indexOf(curfileHead)!=-1){
  1287. var newfileHead=QGMiniAdapter.subMaps[curfileHead];
  1288. url=url.replace(curfileHead,newfileHead);
  1289. }
  1290. }
  1291. this.onDownLoadCallBack(url,0);
  1292. }else{
  1293. if (!MiniFileMgr$3.isLocalNativeFile(url)&& (url.indexOf("http://")==-1 && url.indexOf("https://")==-1)|| (url.indexOf("http://usr/")!=-1)){
  1294. this.onDownLoadCallBack(url,0);
  1295. }else{
  1296. MiniFileMgr$3.downOtherFiles(url,Handler.create(this,this.onDownLoadCallBack,[url]),url);
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. /**@private **/
  1303. __proto.onDownLoadCallBack=function(sourceUrl,errorCode){
  1304. if (!errorCode){
  1305. var fileNativeUrl;
  1306. if(QGMiniAdapter.autoCacheFile){
  1307. if (MiniFileMgr$3.isLocalNativeFile(sourceUrl)){
  1308. var tempStr=URL.rootPath !="" ? URL.rootPath :URL.basePath;
  1309. var tempUrl=sourceUrl;
  1310. if(tempStr !="" && (sourceUrl.indexOf("http://")!=-1 || sourceUrl.indexOf("https://")!=-1))
  1311. fileNativeUrl=sourceUrl.split(tempStr)[1];
  1312. if(!fileNativeUrl){
  1313. fileNativeUrl=tempUrl;
  1314. }
  1315. }else{
  1316. var fileObj=MiniFileMgr$3.getFileInfo(sourceUrl);
  1317. if(fileObj && fileObj.md5){
  1318. var fileMd5Name=fileObj.md5;
  1319. fileNativeUrl=MiniFileMgr$3.getFileNativePath(fileMd5Name);
  1320. }else{
  1321. fileNativeUrl=sourceUrl;
  1322. }
  1323. }
  1324. this._sound=MiniSound._createSound();
  1325. this._sound.src=this.url=fileNativeUrl;
  1326. }else{
  1327. this._sound=MiniSound._createSound();
  1328. this._sound.src=sourceUrl;
  1329. }
  1330. this._sound.onCanplay(MiniSound.bindToThis(this.onCanPlay,this));
  1331. this._sound.onError(MiniSound.bindToThis(this.onError,this));
  1332. }else{
  1333. this.event(/*laya.events.Event.ERROR*/"error");
  1334. }
  1335. }
  1336. /**@private **/
  1337. __proto.onError=function(error){
  1338. try{
  1339. console.log("-----1---------------minisound-----id:"+MiniSound._id);
  1340. console.log(error);
  1341. }
  1342. catch(error){
  1343. console.log("-----2---------------minisound-----id:"+MiniSound._id);
  1344. console.log(error);
  1345. }
  1346. this.event(/*laya.events.Event.ERROR*/"error");
  1347. this._sound.offError(null);
  1348. }
  1349. /**@private **/
  1350. __proto.onCanPlay=function(){
  1351. this.loaded=true;
  1352. this.event(/*laya.events.Event.COMPLETE*/"complete");
  1353. this._sound.offCanplay(null);
  1354. }
  1355. /**
  1356. *@private
  1357. *播放声音。
  1358. *@param startTime 开始时间,单位秒
  1359. *@param loops 循环次数,0表示一直循环
  1360. *@return 声道 SoundChannel 对象。
  1361. *
  1362. */
  1363. __proto.play=function(startTime,loops){
  1364. (startTime===void 0)&& (startTime=0);
  1365. (loops===void 0)&& (loops=0);
  1366. var tSound;
  1367. if (this.url==SoundManager._bgMusic){
  1368. if (!MiniSound._musicAudio)MiniSound._musicAudio=MiniSound._createSound();
  1369. tSound=MiniSound._musicAudio;
  1370. }else {
  1371. if(MiniSound._audioCache[this.readyUrl]){
  1372. tSound=MiniSound._audioCache[this.readyUrl]._sound;
  1373. }else{
  1374. tSound=MiniSound._createSound();
  1375. }
  1376. }
  1377. if(!tSound)
  1378. return null;
  1379. if(QGMiniAdapter.autoCacheFile&&MiniFileMgr$3.getFileInfo(this.url)){
  1380. var fileNativeUrl;
  1381. var fileObj=MiniFileMgr$3.getFileInfo(this.url);
  1382. var fileMd5Name=fileObj.md5;
  1383. tSound.src=this.url=MiniFileMgr$3.getFileNativePath(fileMd5Name);
  1384. }else{
  1385. tSound.src=this.url;
  1386. };
  1387. var channel=new MiniSoundChannel$3(tSound,this);
  1388. channel.url=this.url;
  1389. channel.loops=loops;
  1390. channel.loop=(loops===0 ? true :false);
  1391. channel.startTime=startTime;
  1392. channel.play();
  1393. SoundManager.addChannel(channel);
  1394. return channel;
  1395. }
  1396. /**
  1397. *@private
  1398. *释放声音资源。
  1399. *
  1400. */
  1401. __proto.dispose=function(){
  1402. var ad=MiniSound._audioCache[this.readyUrl];
  1403. if (ad){
  1404. ad.src="";
  1405. if(ad._sound){
  1406. ad._sound.destroy();
  1407. ad._sound=null;
  1408. ad=null;
  1409. }
  1410. delete MiniSound._audioCache[this.readyUrl];
  1411. }
  1412. }
  1413. /**
  1414. *@private
  1415. *获取总时间。
  1416. */
  1417. __getset(0,__proto,'duration',function(){
  1418. return this._sound.duration;
  1419. });
  1420. MiniSound._createSound=function(){
  1421. MiniSound._id++;
  1422. return QGMiniAdapter.window.qg.createInnerAudioContext();
  1423. }
  1424. MiniSound.bindToThis=function(fun,scope){
  1425. var rst=fun;
  1426. /*__JS__ */rst=fun.bind(scope);;
  1427. return rst;
  1428. }
  1429. MiniSound._musicAudio=null;
  1430. MiniSound._id=0;
  1431. MiniSound._audioCache={};
  1432. return MiniSound;
  1433. })(EventDispatcher)
  1434. /**@private **/
  1435. //class laya.qg.mini.MiniAccelerator extends laya.events.EventDispatcher
  1436. var MiniAccelerator$3=(function(_super){
  1437. function MiniAccelerator(){
  1438. MiniAccelerator.__super.call(this);
  1439. }
  1440. __class(MiniAccelerator,'laya.qg.mini.MiniAccelerator',_super,'MiniAccelerator$3');
  1441. var __proto=MiniAccelerator.prototype;
  1442. /**
  1443. *侦听加速器运动。
  1444. *@param observer 回调函数接受4个参数,见类说明。
  1445. */
  1446. __proto.on=function(type,caller,listener,args){
  1447. _super.prototype.on.call(this,type,caller,listener,args);
  1448. MiniAccelerator.startListen(this["onDeviceOrientationChange"]);
  1449. return this;
  1450. }
  1451. /**
  1452. *取消侦听加速器。
  1453. *@param handle 侦听加速器所用处理器。
  1454. */
  1455. __proto.off=function(type,caller,listener,onceOnly){
  1456. (onceOnly===void 0)&& (onceOnly=false);
  1457. if (!this.hasListener(type))
  1458. MiniAccelerator.stopListen();
  1459. return _super.prototype.off.call(this,type,caller,listener,onceOnly);
  1460. }
  1461. MiniAccelerator.__init__=function(){
  1462. try{
  1463. var Acc;
  1464. Acc=/*__JS__ */laya.device.motion.Accelerator;
  1465. if (!Acc)return;
  1466. Acc["prototype"]["on"]=MiniAccelerator["prototype"]["on"];
  1467. Acc["prototype"]["off"]=MiniAccelerator["prototype"]["off"];
  1468. }catch (e){
  1469. }
  1470. }
  1471. MiniAccelerator.startListen=function(callBack){
  1472. MiniAccelerator._callBack=callBack;
  1473. if (MiniAccelerator._isListening)return;
  1474. MiniAccelerator._isListening=true;
  1475. try{
  1476. QGMiniAdapter.window.qg.onAccelerometerChange(laya.qg.mini.MiniAccelerator.onAccelerometerChange);
  1477. }catch(e){}
  1478. }
  1479. MiniAccelerator.stopListen=function(){
  1480. MiniAccelerator._isListening=false;
  1481. try{
  1482. QGMiniAdapter.window.qg.stopAccelerometer({});
  1483. }catch(e){}
  1484. }
  1485. MiniAccelerator.onAccelerometerChange=function(res){
  1486. var e;
  1487. e={};
  1488. e.acceleration=res;
  1489. e.accelerationIncludingGravity=res;
  1490. e.rotationRate={};
  1491. if (MiniAccelerator._callBack !=null){
  1492. MiniAccelerator._callBack(e);
  1493. }
  1494. }
  1495. MiniAccelerator._isListening=false;
  1496. MiniAccelerator._callBack=null;
  1497. return MiniAccelerator;
  1498. })(EventDispatcher)
  1499. /**@private **/
  1500. //class laya.qg.mini.MiniLoader extends laya.events.EventDispatcher
  1501. var MiniLoader$3=(function(_super){
  1502. function MiniLoader(){
  1503. MiniLoader.__super.call(this);
  1504. }
  1505. __class(MiniLoader,'laya.qg.mini.MiniLoader',_super,'MiniLoader$3');
  1506. var __proto=MiniLoader.prototype;
  1507. /**
  1508. *@private
  1509. *@param url
  1510. *@param type
  1511. *@param cache
  1512. *@param group
  1513. *@param ignoreCache
  1514. */
  1515. __proto.load=function(url,type,cache,group,ignoreCache){
  1516. (cache===void 0)&& (cache=true);
  1517. (ignoreCache===void 0)&& (ignoreCache=false);
  1518. var thisLoader=this;
  1519. thisLoader._url=url;
  1520. if (!url){
  1521. thisLoader.onLoaded(null);
  1522. return;
  1523. }
  1524. url=URL.customFormat(url);
  1525. if (url.indexOf("data:image")===0)thisLoader._type=type=/*laya.net.Loader.IMAGE*/"image";
  1526. else {
  1527. thisLoader._type=type || (type=Loader.getTypeFromUrl(thisLoader._url));
  1528. }
  1529. thisLoader._cache=cache;
  1530. thisLoader._data=null;
  1531. if (!ignoreCache && Loader.loadedMap[URL.formatURL(url)]){
  1532. thisLoader._data=Loader.loadedMap[URL.formatURL(url)];
  1533. this.event(/*laya.events.Event.PROGRESS*/"progress",1);
  1534. this.event(/*laya.events.Event.COMPLETE*/"complete",thisLoader._data);
  1535. return;
  1536. }
  1537. if (Loader.parserMap[type] !=null){
  1538. thisLoader._customParse=true;
  1539. if (((Loader.parserMap[type])instanceof laya.utils.Handler ))Loader.parserMap[type].runWith(this);
  1540. else Loader.parserMap[type].call(null,this);
  1541. return;
  1542. };
  1543. var contentType;
  1544. switch (type){
  1545. case /*laya.net.Loader.ATLAS*/"atlas":
  1546. case /*laya.net.Loader.PREFAB*/"prefab":
  1547. case /*laya.net.Loader.PLF*/"plf":
  1548. contentType=/*laya.net.Loader.JSON*/"json";
  1549. break ;
  1550. case /*laya.net.Loader.FONT*/"font":
  1551. contentType=/*laya.net.Loader.XML*/"xml";
  1552. break ;
  1553. case /*laya.net.Loader.PLFB*/"plfb":
  1554. contentType=/*laya.net.Loader.BUFFER*/"arraybuffer";
  1555. break ;
  1556. default :
  1557. contentType=type;
  1558. }
  1559. if (Loader.preLoadedMap[URL.formatURL(url)]){
  1560. thisLoader.onLoaded(Loader.preLoadedMap[URL.formatURL(url)]);
  1561. return;
  1562. };
  1563. var encoding=QGMiniAdapter.getUrlEncode(url,contentType);
  1564. var urlType=Utils.getFileExtension(url);
  1565. if ((MiniLoader._fileTypeArr.indexOf(urlType)!=-1)){
  1566. QGMiniAdapter.EnvConfig.load.call(this,url,type,cache,group,ignoreCache);
  1567. }else {
  1568. if(QGMiniAdapter.isZiYu && !MiniFileMgr$3.ziyuFileData[url]){
  1569. url=URL.formatURL(url);
  1570. }
  1571. if(QGMiniAdapter.isZiYu && MiniFileMgr$3.ziyuFileData[url]){
  1572. var tempData=MiniFileMgr$3.ziyuFileData[url];
  1573. thisLoader.onLoaded(tempData);
  1574. return;
  1575. }
  1576. if (!MiniFileMgr$3.getFileInfo(url)){
  1577. if (MiniFileMgr$3.isLocalNativeFile(url)){
  1578. if (QGMiniAdapter.subNativeFiles && QGMiniAdapter.subNativeheads.length==0){
  1579. for (var key in QGMiniAdapter.subNativeFiles){
  1580. var tempArr=QGMiniAdapter.subNativeFiles[key];
  1581. QGMiniAdapter.subNativeheads=QGMiniAdapter.subNativeheads.concat(tempArr);
  1582. for (var aa=0;aa < tempArr.length;aa++){
  1583. QGMiniAdapter.subMaps[tempArr[aa]]=key+"/"+tempArr[aa];
  1584. }
  1585. }
  1586. }
  1587. if(QGMiniAdapter.subNativeFiles && url.indexOf("/")!=-1){
  1588. var curfileHead=url.split("/")[0]+"/";
  1589. if(curfileHead && QGMiniAdapter.subNativeheads.indexOf(curfileHead)!=-1){
  1590. var newfileHead=QGMiniAdapter.subMaps[curfileHead];
  1591. url=url.replace(curfileHead,newfileHead);
  1592. }
  1593. };
  1594. var tempStr=URL.rootPath !="" ? URL.rootPath :URL.basePath;
  1595. var tempUrl=url;
  1596. if (tempStr !="")
  1597. url=url.split(tempStr)[1];
  1598. if (!url){
  1599. url=tempUrl;
  1600. }
  1601. MiniFileMgr$3.read(url,encoding,new Handler(MiniLoader,MiniLoader.onReadNativeCallBack,[encoding,url,type,cache,group,ignoreCache,thisLoader]));
  1602. return;
  1603. };
  1604. var tempurl=URL.formatURL(url);
  1605. if (tempurl.indexOf("http://usr/")==-1&& (tempurl.indexOf("http://")!=-1 || tempurl.indexOf("https://")!=-1)&& !QGMiniAdapter.AutoCacheDownFile){
  1606. QGMiniAdapter.EnvConfig.load.call(thisLoader,url,type,cache,group,ignoreCache);
  1607. }else {
  1608. MiniFileMgr$3.readFile(url,encoding,new Handler(MiniLoader,MiniLoader.onReadNativeCallBack,[encoding,url,type,cache,group,ignoreCache,thisLoader]),url);
  1609. }
  1610. }else {
  1611. var fileObj=MiniFileMgr$3.getFileInfo(url);
  1612. fileObj.encoding=fileObj.encoding==null ? "utf8" :fileObj.encoding;
  1613. MiniFileMgr$3.readFile(url,fileObj.encoding,new Handler(MiniLoader,MiniLoader.onReadNativeCallBack,[encoding,url,type,cache,group,ignoreCache,thisLoader]),url);
  1614. }
  1615. }
  1616. }
  1617. MiniLoader.onReadNativeCallBack=function(encoding,url,type,cache,group,ignoreCache,thisLoader,errorCode,data){
  1618. (cache===void 0)&& (cache=true);
  1619. (ignoreCache===void 0)&& (ignoreCache=false);
  1620. (errorCode===void 0)&& (errorCode=0);
  1621. if (!errorCode){
  1622. var tempData;
  1623. if (type==/*laya.net.Loader.JSON*/"json" || type==/*laya.net.Loader.ATLAS*/"atlas" || type==/*laya.net.Loader.PREFAB*/"prefab" || type==/*laya.net.Loader.PLF*/"plf"){
  1624. tempData=QGMiniAdapter.getJson(data.data);
  1625. }else if (type==/*laya.net.Loader.XML*/"xml"){
  1626. tempData=Utils.parseXMLFromString(data.data);
  1627. }else {
  1628. tempData=data.data;
  1629. }
  1630. if(!QGMiniAdapter.isZiYu &&QGMiniAdapter.isPosMsgYu && type !=/*laya.net.Loader.BUFFER*/"arraybuffer"){
  1631. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({url:url,data:tempData,isLoad:"filedata"});
  1632. }
  1633. thisLoader.onLoaded(tempData);
  1634. }else if (errorCode==1){
  1635. QGMiniAdapter.EnvConfig.load.call(thisLoader,url,type,cache,group,ignoreCache);
  1636. }
  1637. }
  1638. __static(MiniLoader,
  1639. ['_fileTypeArr',function(){return this._fileTypeArr=['png','jpg','bmp','jpeg','gif'];}
  1640. ]);
  1641. return MiniLoader;
  1642. })(EventDispatcher)
  1643. /**@private **/
  1644. //class laya.qg.mini.MiniSoundChannel extends laya.media.SoundChannel
  1645. var MiniSoundChannel$3=(function(_super){
  1646. function MiniSoundChannel(audio,miniSound){
  1647. /**@private **/
  1648. this._audio=null;
  1649. /**@private **/
  1650. this._onEnd=null;
  1651. /**@private **/
  1652. this._miniSound=null;
  1653. MiniSoundChannel.__super.call(this);
  1654. this._audio=audio;
  1655. this._miniSound=miniSound;
  1656. this._onEnd=MiniSoundChannel.bindToThis(this.__onEnd,this);
  1657. audio.onEnded(this._onEnd);
  1658. }
  1659. __class(MiniSoundChannel,'laya.qg.mini.MiniSoundChannel',_super,'MiniSoundChannel$3');
  1660. var __proto=MiniSoundChannel.prototype;
  1661. /**@private **/
  1662. __proto.__onEnd=function(){
  1663. MiniSound$3._audioCache[this.url]=this._miniSound;
  1664. if (this.loops==1){
  1665. if (this.completeHandler){
  1666. Laya.systemTimer.once(10,this,this.__runComplete,[this.completeHandler],false);
  1667. this.completeHandler=null;
  1668. }
  1669. this.stop();
  1670. this.event(/*laya.events.Event.COMPLETE*/"complete");
  1671. return;
  1672. }
  1673. if (this.loops > 0){
  1674. this.loops--;
  1675. }
  1676. this.startTime=0;
  1677. this.play();
  1678. }
  1679. /**
  1680. *@private
  1681. *播放
  1682. */
  1683. __proto.play=function(){
  1684. this.isStopped=false;
  1685. SoundManager.addChannel(this);
  1686. this._audio.play();
  1687. }
  1688. /**
  1689. *@private
  1690. *停止播放
  1691. *
  1692. */
  1693. __proto.stop=function(){
  1694. this.isStopped=true;
  1695. SoundManager.removeChannel(this);
  1696. this.completeHandler=null;
  1697. if (!this._audio)
  1698. return;
  1699. this._audio.stop();
  1700. this._audio.offEnded(null);
  1701. this._miniSound.dispose();
  1702. this._audio=null;
  1703. this._miniSound=null;
  1704. this._onEnd=null;
  1705. }
  1706. /**@private **/
  1707. __proto.pause=function(){
  1708. this.isStopped=true;
  1709. this._audio.pause();
  1710. }
  1711. /**@private **/
  1712. __proto.resume=function(){
  1713. if (!this._audio)
  1714. return;
  1715. this.isStopped=false;
  1716. SoundManager.addChannel(this);
  1717. this._audio.play();
  1718. }
  1719. /**
  1720. *设置开始时间
  1721. *@param time
  1722. */
  1723. __getset(0,__proto,'startTime',null,function(time){
  1724. if(this._audio){
  1725. this._audio.startTime=time;
  1726. }
  1727. });
  1728. /**@private **/
  1729. /**
  1730. *@private
  1731. *自动播放
  1732. *@param value
  1733. */
  1734. __getset(0,__proto,'autoplay',function(){
  1735. return this._audio.autoplay;
  1736. },function(value){
  1737. this._audio.autoplay=value;
  1738. });
  1739. /**
  1740. *@private
  1741. *当前播放到的位置
  1742. *@return
  1743. *
  1744. */
  1745. __getset(0,__proto,'position',function(){
  1746. if (!this._audio)
  1747. return 0;
  1748. return this._audio.currentTime;
  1749. });
  1750. /**
  1751. *@private
  1752. *获取总时间。
  1753. */
  1754. __getset(0,__proto,'duration',function(){
  1755. if (!this._audio)
  1756. return 0;
  1757. return this._audio.duration;
  1758. });
  1759. /**@private **/
  1760. /**@private **/
  1761. __getset(0,__proto,'loop',function(){
  1762. return this._audio.loop;
  1763. },function(value){
  1764. this._audio.loop=value;
  1765. });
  1766. /**
  1767. *@private
  1768. *设置音量
  1769. *@param v
  1770. *
  1771. */
  1772. /**
  1773. *@private
  1774. *获取音量
  1775. *@return
  1776. */
  1777. __getset(0,__proto,'volume',function(){
  1778. if (!this._audio)return 1;
  1779. return this._audio.volume;
  1780. },function(v){
  1781. if (!this._audio)return;
  1782. this._audio.volume=v;
  1783. });
  1784. MiniSoundChannel.bindToThis=function(fun,scope){
  1785. var rst=fun;
  1786. /*__JS__ */rst=fun.bind(scope);;
  1787. return rst;
  1788. }
  1789. return MiniSoundChannel;
  1790. })(SoundChannel)
  1791. },1003);