laya.xmmini.js 65 KB

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