laya.quickgamemini.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  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 (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(fileObj.url, 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);
  858. return;
  859. }
  860. if (!MiniFileMgr.getFileInfo(url)) {
  861. var tempUrl = Laya.URL.formatURL(url);
  862. if (url.indexOf('http://usr/') == -1 && (tempUrl.indexOf("http://") != -1 || tempUrl.indexOf("https://") != -1)) {
  863. if (QGMiniAdapter.isZiYu) {
  864. thisLoader._loadImage(url);
  865. }
  866. else {
  867. MiniFileMgr.downOtherFiles(tempUrl, new Laya.Handler(MiniLoader, MiniLoader.onDownImgCallBack, [url, thisLoader]), tempUrl);
  868. }
  869. }
  870. else
  871. thisLoader._loadImage(url);
  872. }
  873. else {
  874. thisLoader._loadImage(url);
  875. }
  876. }
  877. static onDownImgCallBack(sourceUrl, thisLoader, errorCode, tempFilePath = "") {
  878. if (!errorCode)
  879. MiniLoader.onCreateImage(sourceUrl, thisLoader, false, tempFilePath);
  880. else {
  881. thisLoader.onError(null);
  882. }
  883. }
  884. static onCreateImage(sourceUrl, thisLoader, isLocal = false, tempFilePath = "") {
  885. var fileNativeUrl;
  886. if (QGMiniAdapter.autoCacheFile) {
  887. if (!isLocal) {
  888. if (tempFilePath != "") {
  889. fileNativeUrl = tempFilePath;
  890. }
  891. else {
  892. var fileObj = MiniFileMgr.getFileInfo(sourceUrl);
  893. var fileMd5Name = fileObj.md5;
  894. fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  895. }
  896. }
  897. else if (QGMiniAdapter.isZiYu) {
  898. var tempUrl = Laya.URL.formatURL(sourceUrl);
  899. if (MiniFileMgr.ziyuFileTextureData[tempUrl]) {
  900. fileNativeUrl = MiniFileMgr.ziyuFileTextureData[tempUrl];
  901. }
  902. else
  903. fileNativeUrl = sourceUrl;
  904. }
  905. else
  906. fileNativeUrl = sourceUrl;
  907. }
  908. else {
  909. if (!isLocal)
  910. fileNativeUrl = tempFilePath;
  911. else
  912. fileNativeUrl = sourceUrl;
  913. }
  914. thisLoader._loadImage(fileNativeUrl);
  915. }
  916. }
  917. class QGMiniAdapter {
  918. static getJson(data) {
  919. return JSON.parse(data);
  920. }
  921. static enable() {
  922. QGMiniAdapter.init(Laya.Laya.isWXPosMsg, Laya.Laya.isWXOpenDataContext);
  923. }
  924. static init(isPosMsg = false, isSon = false) {
  925. if (QGMiniAdapter._inited)
  926. return;
  927. QGMiniAdapter._inited = true;
  928. QGMiniAdapter.window = window;
  929. if (!QGMiniAdapter.window.hasOwnProperty('qg'))
  930. return;
  931. if (QGMiniAdapter.window.navigator.userAgent.indexOf('OPPO') < 0)
  932. return;
  933. QGMiniAdapter.isZiYu = isSon;
  934. QGMiniAdapter.isPosMsgYu = isPosMsg;
  935. QGMiniAdapter.EnvConfig = {};
  936. if (!QGMiniAdapter.isZiYu) {
  937. MiniFileMgr.setNativeFileDir("/layaairGame");
  938. MiniFileMgr.existDir(MiniFileMgr.fileNativeDir, Laya.Handler.create(QGMiniAdapter, QGMiniAdapter.onMkdirCallBack));
  939. }
  940. QGMiniAdapter.window.qg.getSystemInfo({
  941. success: function (data) {
  942. QGMiniAdapter.systemInfo = data;
  943. }
  944. });
  945. QGMiniAdapter.window.focus = function () {
  946. };
  947. Laya.Laya['_getUrlPath'] = function () {
  948. return "";
  949. };
  950. Laya.Laya['getUrlPath'] = function () {
  951. return "";
  952. };
  953. QGMiniAdapter.window.logtime = function (str) {
  954. };
  955. QGMiniAdapter.window.alertTimeLog = function (str) {
  956. };
  957. QGMiniAdapter.window.resetShareInfo = function () {
  958. };
  959. QGMiniAdapter.window.document.body.appendChild = function () {
  960. };
  961. QGMiniAdapter.EnvConfig.pixelRatioInt = 0;
  962. Laya.Browser["_pixelRatio"] = QGMiniAdapter.pixelRatio();
  963. QGMiniAdapter._preCreateElement = Laya.Browser.createElement;
  964. Laya.Browser["createElement"] = QGMiniAdapter.createElement;
  965. Laya.RunDriver.createShaderCondition = QGMiniAdapter.createShaderCondition;
  966. Laya.Utils['parseXMLFromString'] = QGMiniAdapter.parseXMLFromString;
  967. Laya.Input['_createInputElement'] = MiniInput['_createInputElement'];
  968. Laya.Loader.prototype._loadResourceFilter = MiniLoader.prototype._loadResourceFilter;
  969. Laya.Loader.prototype._loadSound = MiniLoader.prototype._loadSound;
  970. Laya.Loader.prototype._loadHttpRequestWhat = MiniLoader.prototype._loadHttpRequestWhat;
  971. Laya.Config.useRetinalCanvas = true;
  972. QGMiniAdapter.window.qg.onMessage && QGMiniAdapter.window.qg.onMessage(QGMiniAdapter._onMessage);
  973. }
  974. static _onMessage(data) {
  975. switch (data.type) {
  976. case "changeMatrix":
  977. Laya.Laya.stage.transform.identity();
  978. Laya.Laya.stage._width = data.w;
  979. Laya.Laya.stage._height = data.h;
  980. Laya.Laya.stage._canvasTransform = new Laya.Matrix(data.a, data.b, data.c, data.d, data.tx, data.ty);
  981. break;
  982. case "display":
  983. Laya.Laya.stage.frameRate = data.rate || Laya.Stage.FRAME_FAST;
  984. break;
  985. case "undisplay":
  986. Laya.Laya.stage.frameRate = Laya.Stage.FRAME_SLEEP;
  987. break;
  988. }
  989. if (data['isLoad'] == "opendatacontext") {
  990. if (data.url) {
  991. MiniFileMgr.ziyuFileData[data.url] = data.atlasdata;
  992. MiniFileMgr.ziyuFileTextureData[data.imgReadyUrl] = data.imgNativeUrl;
  993. }
  994. }
  995. else if (data['isLoad'] == "openJsondatacontext") {
  996. if (data.url) {
  997. MiniFileMgr.ziyuFileData[data.url] = data.atlasdata;
  998. }
  999. }
  1000. else if (data['isLoad'] == "openJsondatacontextPic") {
  1001. MiniFileMgr.ziyuFileTextureData[data.imgReadyUrl] = data.imgNativeUrl;
  1002. }
  1003. }
  1004. static getUrlEncode(url, type) {
  1005. if (type == "arraybuffer")
  1006. return "";
  1007. return "utf8";
  1008. }
  1009. static downLoadFile(fileUrl, fileType = "", callBack = null, encoding = "utf8") {
  1010. var fileObj = MiniFileMgr.getFileInfo(fileUrl);
  1011. if (!fileObj)
  1012. MiniFileMgr.downLoadFile(fileUrl, fileType, callBack, encoding);
  1013. else {
  1014. callBack != null && callBack.runWith([0]);
  1015. }
  1016. }
  1017. static remove(fileUrl, callBack = null) {
  1018. MiniFileMgr.deleteFile("", fileUrl, callBack, "", 0);
  1019. }
  1020. static removeAll() {
  1021. MiniFileMgr.deleteAll();
  1022. }
  1023. static hasNativeFile(fileUrl) {
  1024. return MiniFileMgr.isLocalNativeFile(fileUrl);
  1025. }
  1026. static getFileInfo(fileUrl) {
  1027. return MiniFileMgr.getFileInfo(fileUrl);
  1028. }
  1029. static getFileList() {
  1030. return MiniFileMgr.filesListObj;
  1031. }
  1032. static exitMiniProgram() {
  1033. QGMiniAdapter.window["wx"].exitMiniProgram();
  1034. }
  1035. static onMkdirCallBack(errorCode, data) {
  1036. if (!errorCode)
  1037. MiniFileMgr.filesListObj = JSON.parse(data.data);
  1038. MiniFileMgr.fakeObj = MiniFileMgr.filesListObj;
  1039. }
  1040. static pixelRatio() {
  1041. if (!QGMiniAdapter.EnvConfig.pixelRatioInt) {
  1042. try {
  1043. QGMiniAdapter.systemInfo.pixelRatio = QGMiniAdapter.window.devicePixelRatio;
  1044. QGMiniAdapter.EnvConfig.pixelRatioInt = QGMiniAdapter.systemInfo.pixelRatio;
  1045. return QGMiniAdapter.systemInfo.pixelRatio;
  1046. }
  1047. catch (error) {
  1048. }
  1049. }
  1050. return QGMiniAdapter.EnvConfig.pixelRatioInt;
  1051. }
  1052. static createElement(type) {
  1053. if (type == "canvas") {
  1054. var _source;
  1055. if (QGMiniAdapter.idx == 1) {
  1056. if (QGMiniAdapter.isZiYu) {
  1057. _source = QGMiniAdapter.window.document.createElement("canvas");
  1058. _source.style = {};
  1059. }
  1060. else {
  1061. _source = QGMiniAdapter.window.__canvas;
  1062. }
  1063. }
  1064. else {
  1065. _source = QGMiniAdapter.window.document.createElement("canvas");
  1066. }
  1067. QGMiniAdapter.idx++;
  1068. return _source;
  1069. }
  1070. else if (type == "textarea" || type == "input") {
  1071. return QGMiniAdapter.onCreateInput(type);
  1072. }
  1073. else if (type == "div") {
  1074. var node = QGMiniAdapter._preCreateElement(type);
  1075. node.contains = function (value) {
  1076. return null;
  1077. };
  1078. node.removeChild = function (value) {
  1079. };
  1080. return node;
  1081. }
  1082. else {
  1083. return QGMiniAdapter._preCreateElement(type);
  1084. }
  1085. }
  1086. static onCreateInput(type) {
  1087. var node = QGMiniAdapter._preCreateElement(type);
  1088. node.focus = MiniInput.wxinputFocus;
  1089. node.blur = MiniInput.wxinputblur;
  1090. node.style = {};
  1091. node.value = 0;
  1092. node.parentElement = {};
  1093. node.placeholder = {};
  1094. node.type = {};
  1095. node.setColor = function (value) {
  1096. };
  1097. node.setType = function (value) {
  1098. };
  1099. node.setFontFace = function (value) {
  1100. };
  1101. node.addEventListener = function (value) {
  1102. };
  1103. node.contains = function (value) {
  1104. return null;
  1105. };
  1106. node.removeChild = function (value) {
  1107. };
  1108. return node;
  1109. }
  1110. static createShaderCondition(conditionScript) {
  1111. var func = function () {
  1112. return this[conditionScript.replace("this.", "")];
  1113. };
  1114. return func;
  1115. }
  1116. static sendAtlasToOpenDataContext(url) {
  1117. if (!QGMiniAdapter.isZiYu) {
  1118. var atlasJson = Laya.Loader.getRes(Laya.URL.formatURL(url));
  1119. if (atlasJson) {
  1120. var textureArr = atlasJson.meta.image.split(",");
  1121. if (atlasJson.meta && atlasJson.meta.image) {
  1122. var toloadPics = atlasJson.meta.image.split(",");
  1123. var split = url.indexOf("/") >= 0 ? "/" : "\\";
  1124. var idx = url.lastIndexOf(split);
  1125. var folderPath = idx >= 0 ? url.substr(0, idx + 1) : "";
  1126. for (var i = 0, len = toloadPics.length; i < len; i++) {
  1127. toloadPics[i] = folderPath + toloadPics[i];
  1128. }
  1129. }
  1130. else {
  1131. toloadPics = [url.replace(".json", ".png")];
  1132. }
  1133. for (i = 0; i < toloadPics.length; i++) {
  1134. var tempAtlasPngUrl = toloadPics[i];
  1135. QGMiniAdapter.postInfoToContext(url, tempAtlasPngUrl, atlasJson);
  1136. }
  1137. }
  1138. else {
  1139. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1140. }
  1141. }
  1142. }
  1143. static postInfoToContext(url, atlaspngUrl, atlasJson) {
  1144. var postData = { "frames": atlasJson.frames, "meta": atlasJson.meta };
  1145. var textureUrl = atlaspngUrl;
  1146. var fileObj = MiniFileMgr.getFileInfo(Laya.URL.formatURL(atlaspngUrl));
  1147. if (fileObj) {
  1148. var fileMd5Name = fileObj.md5;
  1149. var fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  1150. }
  1151. else {
  1152. fileNativeUrl = textureUrl;
  1153. }
  1154. if (fileNativeUrl) {
  1155. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({ url: url, atlasdata: postData, imgNativeUrl: fileNativeUrl, imgReadyUrl: textureUrl, isLoad: "opendatacontext" });
  1156. }
  1157. else {
  1158. throw "获取图集的磁盘url路径不存在!";
  1159. }
  1160. }
  1161. static sendSinglePicToOpenDataContext(url) {
  1162. var tempTextureUrl = Laya.URL.formatURL(url);
  1163. var fileObj = MiniFileMgr.getFileInfo(tempTextureUrl);
  1164. if (fileObj) {
  1165. var fileMd5Name = fileObj.md5;
  1166. var fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  1167. url = tempTextureUrl;
  1168. }
  1169. else {
  1170. fileNativeUrl = url;
  1171. }
  1172. if (fileNativeUrl) {
  1173. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({ url: url, imgNativeUrl: fileNativeUrl, imgReadyUrl: url, isLoad: "openJsondatacontextPic" });
  1174. }
  1175. else {
  1176. throw "获取图集的磁盘url路径不存在!";
  1177. }
  1178. }
  1179. static sendJsonDataToDataContext(url) {
  1180. if (!QGMiniAdapter.isZiYu) {
  1181. var atlasJson = Laya.Loader.getRes(url);
  1182. if (atlasJson) {
  1183. QGMiniAdapter.window.qg.postMessage && QGMiniAdapter.window.qg.postMessage({ url: url, atlasdata: atlasJson, isLoad: "openJsondatacontext" });
  1184. }
  1185. else {
  1186. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1187. }
  1188. }
  1189. }
  1190. }
  1191. QGMiniAdapter._inited = false;
  1192. QGMiniAdapter.systemInfo = {};
  1193. QGMiniAdapter.autoCacheFile = true;
  1194. QGMiniAdapter.minClearSize = (5 * 1024 * 1024);
  1195. QGMiniAdapter.nativefiles = ["layaNativeDir"];
  1196. QGMiniAdapter.subNativeheads = [];
  1197. QGMiniAdapter.subMaps = [];
  1198. QGMiniAdapter.AutoCacheDownFile = false;
  1199. QGMiniAdapter.parseXMLFromString = function (value) {
  1200. var rst;
  1201. value = value.replace(/>\s+</g, '><');
  1202. try {
  1203. rst = (new window.DOMParser()).parseFromString(value, 'text/xml');
  1204. }
  1205. catch (error) {
  1206. throw "需要引入xml解析库文件";
  1207. }
  1208. return rst;
  1209. };
  1210. QGMiniAdapter.idx = 1;
  1211. class MiniAccelerator extends Laya.EventDispatcher {
  1212. constructor() {
  1213. super();
  1214. }
  1215. static __init__() {
  1216. try {
  1217. var Acc;
  1218. Acc = Laya.Accelerator;
  1219. if (!Acc)
  1220. return;
  1221. Acc["prototype"]["on"] = MiniAccelerator["prototype"]["on"];
  1222. Acc["prototype"]["off"] = MiniAccelerator["prototype"]["off"];
  1223. }
  1224. catch (e) {
  1225. }
  1226. }
  1227. static startListen(callBack) {
  1228. MiniAccelerator._callBack = callBack;
  1229. if (MiniAccelerator._isListening)
  1230. return;
  1231. MiniAccelerator._isListening = true;
  1232. try {
  1233. QGMiniAdapter.window.qg.onAccelerometerChange(MiniAccelerator.onAccelerometerChange);
  1234. }
  1235. catch (e) { }
  1236. }
  1237. static stopListen() {
  1238. MiniAccelerator._isListening = false;
  1239. try {
  1240. QGMiniAdapter.window.qg.stopAccelerometer({});
  1241. }
  1242. catch (e) { }
  1243. }
  1244. static onAccelerometerChange(res) {
  1245. var e;
  1246. e = {};
  1247. e.acceleration = res;
  1248. e.accelerationIncludingGravity = res;
  1249. e.rotationRate = {};
  1250. if (MiniAccelerator._callBack != null) {
  1251. MiniAccelerator._callBack(e);
  1252. }
  1253. }
  1254. on(type, caller, listener, args = null) {
  1255. super.on(type, caller, listener, args);
  1256. MiniAccelerator.startListen(this["onDeviceOrientationChange"]);
  1257. return this;
  1258. }
  1259. off(type, caller, listener, onceOnly = false) {
  1260. if (!this.hasListener(type))
  1261. MiniAccelerator.stopListen();
  1262. return super.off(type, caller, listener, onceOnly);
  1263. }
  1264. }
  1265. MiniAccelerator._isListening = false;
  1266. class MiniImage {
  1267. _loadImage(url) {
  1268. var thisLoader = this;
  1269. if (QGMiniAdapter.isZiYu) {
  1270. MiniImage.onCreateImage(url, thisLoader, true);
  1271. return;
  1272. }
  1273. var isTransformUrl;
  1274. if (!MiniFileMgr.isLocalNativeFile(url)) {
  1275. isTransformUrl = true;
  1276. url = Laya.URL.formatURL(url);
  1277. }
  1278. else {
  1279. if (url.indexOf("http://usr/") == -1 && (url.indexOf("http://") != -1 || url.indexOf("https://") != -1)) {
  1280. if (MiniFileMgr.loadPath != "") {
  1281. url = url.split(MiniFileMgr.loadPath)[1];
  1282. }
  1283. else {
  1284. var tempStr = Laya.URL.rootPath != "" ? Laya.URL.rootPath : Laya.URL.basePath;
  1285. var tempUrl = url;
  1286. if (tempStr != "")
  1287. url = url.split(tempStr)[1];
  1288. if (!url) {
  1289. url = tempUrl;
  1290. }
  1291. }
  1292. }
  1293. if (QGMiniAdapter.subNativeFiles && QGMiniAdapter.subNativeheads.length == 0) {
  1294. for (var key in QGMiniAdapter.subNativeFiles) {
  1295. var tempArr = QGMiniAdapter.subNativeFiles[key];
  1296. QGMiniAdapter.subNativeheads = QGMiniAdapter.subNativeheads.concat(tempArr);
  1297. for (var aa = 0; aa < tempArr.length; aa++) {
  1298. QGMiniAdapter.subMaps[tempArr[aa]] = key + "/" + tempArr[aa];
  1299. }
  1300. }
  1301. }
  1302. if (QGMiniAdapter.subNativeFiles && url.indexOf("/") != -1) {
  1303. var curfileHead = url.split("/")[0] + "/";
  1304. if (curfileHead && QGMiniAdapter.subNativeheads.indexOf(curfileHead) != -1) {
  1305. var newfileHead = QGMiniAdapter.subMaps[curfileHead];
  1306. url = url.replace(curfileHead, newfileHead);
  1307. }
  1308. }
  1309. }
  1310. if (!MiniFileMgr.getFileInfo(url)) {
  1311. if (url.indexOf('http://usr/') == -1 && (url.indexOf("http://") != -1 || url.indexOf("https://") != -1)) {
  1312. if (QGMiniAdapter.isZiYu) {
  1313. MiniImage.onCreateImage(url, thisLoader, true);
  1314. }
  1315. else {
  1316. MiniFileMgr.downOtherFiles(encodeURI(url), new Laya.Handler(MiniImage, MiniImage.onDownImgCallBack, [url, thisLoader]), url);
  1317. }
  1318. }
  1319. else
  1320. MiniImage.onCreateImage(url, thisLoader, true);
  1321. }
  1322. else {
  1323. MiniImage.onCreateImage(url, thisLoader, !isTransformUrl);
  1324. }
  1325. }
  1326. static onDownImgCallBack(sourceUrl, thisLoader, errorCode, tempFilePath = "") {
  1327. if (!errorCode)
  1328. MiniImage.onCreateImage(sourceUrl, thisLoader, false, tempFilePath);
  1329. else {
  1330. thisLoader.onError(null);
  1331. }
  1332. }
  1333. static onCreateImage(sourceUrl, thisLoader, isLocal = false, tempFilePath = "") {
  1334. var fileNativeUrl;
  1335. if (QGMiniAdapter.autoCacheFile) {
  1336. if (!isLocal) {
  1337. if (tempFilePath != "") {
  1338. fileNativeUrl = tempFilePath;
  1339. }
  1340. else {
  1341. var fileObj = MiniFileMgr.getFileInfo(sourceUrl);
  1342. var fileMd5Name = fileObj.md5;
  1343. fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  1344. }
  1345. }
  1346. else if (QGMiniAdapter.isZiYu) {
  1347. var tempUrl = Laya.URL.formatURL(sourceUrl);
  1348. if (MiniFileMgr.ziyuFileTextureData[tempUrl]) {
  1349. fileNativeUrl = MiniFileMgr.ziyuFileTextureData[tempUrl];
  1350. }
  1351. else
  1352. fileNativeUrl = sourceUrl;
  1353. }
  1354. else
  1355. fileNativeUrl = sourceUrl;
  1356. }
  1357. else {
  1358. if (!isLocal)
  1359. fileNativeUrl = tempFilePath;
  1360. else
  1361. fileNativeUrl = sourceUrl;
  1362. }
  1363. if (thisLoader._imgCache == null)
  1364. thisLoader._imgCache = {};
  1365. var image;
  1366. function clear() {
  1367. var img = thisLoader._imgCache[sourceUrl];
  1368. if (img) {
  1369. img.onload = null;
  1370. img.onerror = null;
  1371. delete thisLoader._imgCache[sourceUrl];
  1372. }
  1373. }
  1374. var onerror = function () {
  1375. clear();
  1376. delete MiniFileMgr.fakeObj[sourceUrl];
  1377. delete MiniFileMgr.filesListObj[sourceUrl];
  1378. thisLoader.event(Laya.Event.ERROR, "Load image failed");
  1379. };
  1380. if (thisLoader._type == "nativeimage") {
  1381. var onload = function () {
  1382. clear();
  1383. thisLoader.onLoaded(image);
  1384. };
  1385. image = new Laya.Browser.window.Image();
  1386. image.crossOrigin = "";
  1387. image.onload = onload;
  1388. image.onerror = onerror;
  1389. image.src = fileNativeUrl;
  1390. thisLoader._imgCache[sourceUrl] = image;
  1391. }
  1392. else {
  1393. var imageSource = new Laya.Browser.window.Image();
  1394. onload = function () {
  1395. image = Laya.HTMLImage.create(imageSource.width, imageSource.height);
  1396. image.loadImageSource(imageSource, true);
  1397. image._setCreateURL(sourceUrl);
  1398. clear();
  1399. thisLoader.onLoaded(image);
  1400. };
  1401. imageSource.crossOrigin = "";
  1402. imageSource.onload = onload;
  1403. imageSource.onerror = onerror;
  1404. imageSource.src = fileNativeUrl;
  1405. thisLoader._imgCache[sourceUrl] = imageSource;
  1406. }
  1407. }
  1408. }
  1409. class MiniLocation {
  1410. constructor() {
  1411. }
  1412. static __init__() {
  1413. QGMiniAdapter.window.navigator.geolocation.getCurrentPosition = MiniLocation.getCurrentPosition;
  1414. QGMiniAdapter.window.navigator.geolocation.watchPosition = MiniLocation.watchPosition;
  1415. QGMiniAdapter.window.navigator.geolocation.clearWatch = MiniLocation.clearWatch;
  1416. }
  1417. static getCurrentPosition(success = null, error = null, options = null) {
  1418. var paramO;
  1419. paramO = {};
  1420. paramO.success = getSuccess;
  1421. paramO.fail = error;
  1422. QGMiniAdapter.window.qg.getLocation(paramO);
  1423. function getSuccess(res) {
  1424. if (success != null) {
  1425. success(res);
  1426. }
  1427. }
  1428. }
  1429. static watchPosition(success = null, error = null, options = null) {
  1430. MiniLocation._curID++;
  1431. var curWatchO;
  1432. curWatchO = {};
  1433. curWatchO.success = success;
  1434. curWatchO.error = error;
  1435. MiniLocation._watchDic[MiniLocation._curID] = curWatchO;
  1436. Laya.Laya.systemTimer.loop(1000, null, MiniLocation._myLoop);
  1437. return MiniLocation._curID;
  1438. }
  1439. static clearWatch(id) {
  1440. delete MiniLocation._watchDic[id];
  1441. if (!MiniLocation._hasWatch()) {
  1442. Laya.Laya.systemTimer.clear(null, MiniLocation._myLoop);
  1443. }
  1444. }
  1445. static _hasWatch() {
  1446. var key;
  1447. for (key in MiniLocation._watchDic) {
  1448. if (MiniLocation._watchDic[key])
  1449. return true;
  1450. }
  1451. return false;
  1452. }
  1453. static _myLoop() {
  1454. MiniLocation.getCurrentPosition(MiniLocation._mySuccess, MiniLocation._myError);
  1455. }
  1456. static _mySuccess(res) {
  1457. var rst = {};
  1458. rst.coords = res;
  1459. rst.timestamp = Laya.Browser.now();
  1460. var key;
  1461. for (key in MiniLocation._watchDic) {
  1462. if (MiniLocation._watchDic[key].success) {
  1463. MiniLocation._watchDic[key].success(rst);
  1464. }
  1465. }
  1466. }
  1467. static _myError(res) {
  1468. var key;
  1469. for (key in MiniLocation._watchDic) {
  1470. if (MiniLocation._watchDic[key].error) {
  1471. MiniLocation._watchDic[key].error(res);
  1472. }
  1473. }
  1474. }
  1475. }
  1476. MiniLocation._watchDic = {};
  1477. MiniLocation._curID = 0;
  1478. class MiniVideo {
  1479. constructor(width = 320, height = 240) {
  1480. this.videoend = false;
  1481. this.videourl = "";
  1482. this.videoW = width;
  1483. this.videoH = height;
  1484. }
  1485. static __init__() {
  1486. }
  1487. on(eventType, ths, callBack) {
  1488. if (eventType == "loadedmetadata") {
  1489. this.onPlayFunc = callBack.bind(ths);
  1490. }
  1491. else if (eventType == "ended") {
  1492. this.onEndedFunC = callBack.bind(ths);
  1493. }
  1494. this.videoElement.onTimeUpdate = this.onTimeUpdateFunc.bind(this);
  1495. }
  1496. onTimeUpdateFunc(data) {
  1497. this.position = data.position;
  1498. this._duration = data.duration;
  1499. }
  1500. get duration() {
  1501. return this._duration;
  1502. }
  1503. onPlayFunction() {
  1504. if (this.videoElement)
  1505. this.videoElement.readyState = 200;
  1506. this.onPlayFunc != null && this.onPlayFunc();
  1507. }
  1508. onEndedFunction() {
  1509. this.videoend = true;
  1510. this.onEndedFunC != null && this.onEndedFunC();
  1511. }
  1512. off(eventType, ths, callBack) {
  1513. if (eventType == "loadedmetadata") {
  1514. this.onPlayFunc = callBack.bind(ths);
  1515. this.videoElement.offPlay = this.onPlayFunction.bind(this);
  1516. }
  1517. else if (eventType == "ended") {
  1518. this.onEndedFunC = callBack.bind(ths);
  1519. this.videoElement.offEnded = this.onEndedFunction.bind(this);
  1520. }
  1521. }
  1522. load(url) {
  1523. if (!this.videoElement) {
  1524. this.videoElement = QGMiniAdapter.window.qg.createVideo({ width: this.videoW, height: this.videoH, autoplay: true, src: url });
  1525. this.videoElement.onPlay = this.onPlayFunction.bind(this);
  1526. this.videoElement.onEnded = this.onEndedFunction.bind(this);
  1527. }
  1528. else {
  1529. this.videoElement.src = url;
  1530. }
  1531. }
  1532. play() {
  1533. if (!this.videoElement)
  1534. return;
  1535. this.videoend = false;
  1536. this.videoElement.play();
  1537. }
  1538. pause() {
  1539. if (!this.videoElement)
  1540. return;
  1541. this.videoend = true;
  1542. this.videoElement.pause();
  1543. }
  1544. get currentTime() {
  1545. if (!this.videoElement)
  1546. return 0;
  1547. return this.videoElement.initialTime;
  1548. }
  1549. set currentTime(value) {
  1550. if (!this.videoElement)
  1551. return;
  1552. this.videoElement.initialTime = value;
  1553. }
  1554. get videoWidth() {
  1555. if (!this.videoElement)
  1556. return 0;
  1557. return this.videoElement.width;
  1558. }
  1559. get videoHeight() {
  1560. if (!this.videoElement)
  1561. return 0;
  1562. return this.videoElement.height;
  1563. }
  1564. get ended() {
  1565. return this.videoend;
  1566. }
  1567. get loop() {
  1568. if (!this.videoElement)
  1569. return false;
  1570. return this.videoElement.loop;
  1571. }
  1572. set loop(value) {
  1573. if (!this.videoElement)
  1574. return;
  1575. this.videoElement.loop = value;
  1576. }
  1577. get playbackRate() {
  1578. if (!this.videoElement)
  1579. return 0;
  1580. return this.videoElement.playbackRate;
  1581. }
  1582. set playbackRate(value) {
  1583. if (!this.videoElement)
  1584. return;
  1585. this.videoElement.playbackRate = value;
  1586. }
  1587. get muted() {
  1588. if (!this.videoElement)
  1589. return false;
  1590. return this.videoElement.muted;
  1591. }
  1592. set muted(value) {
  1593. if (!this.videoElement)
  1594. return;
  1595. this.videoElement.muted = value;
  1596. }
  1597. get paused() {
  1598. if (!this.videoElement)
  1599. return false;
  1600. return this.videoElement.paused;
  1601. }
  1602. size(width, height) {
  1603. if (!this.videoElement)
  1604. return;
  1605. this.videoElement.width = width;
  1606. this.videoElement.height = height;
  1607. }
  1608. get x() {
  1609. if (!this.videoElement)
  1610. return 0;
  1611. return this.videoElement.x;
  1612. }
  1613. set x(value) {
  1614. if (!this.videoElement)
  1615. return;
  1616. this.videoElement.x = value;
  1617. }
  1618. get y() {
  1619. if (!this.videoElement)
  1620. return 0;
  1621. return this.videoElement.y;
  1622. }
  1623. set y(value) {
  1624. if (!this.videoElement)
  1625. return;
  1626. this.videoElement.y = value;
  1627. }
  1628. get currentSrc() {
  1629. return this.videoElement.src;
  1630. }
  1631. destroy() {
  1632. if (this.videoElement)
  1633. this.videoElement.destroy();
  1634. this.videoElement = null;
  1635. this.onEndedFunC = null;
  1636. this.onPlayFunc = null;
  1637. this.videoend = false;
  1638. this.videourl = null;
  1639. }
  1640. reload() {
  1641. if (!this.videoElement)
  1642. return;
  1643. this.videoElement.src = this.videourl;
  1644. }
  1645. }
  1646. exports.MiniAccelerator = MiniAccelerator;
  1647. exports.MiniFileMgr = MiniFileMgr;
  1648. exports.MiniImage = MiniImage;
  1649. exports.MiniInput = MiniInput;
  1650. exports.MiniLoader = MiniLoader;
  1651. exports.MiniLocation = MiniLocation;
  1652. exports.MiniSound = MiniSound;
  1653. exports.MiniSoundChannel = MiniSoundChannel;
  1654. exports.MiniVideo = MiniVideo;
  1655. exports.QGMiniAdapter = QGMiniAdapter;
  1656. }