laya.xmmini.js 65 KB

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