laya.quickgamemini.js 65 KB

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