laya.quickgamemini.js 66 KB

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