subGame.nvue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. <template>
  2. <view>
  3. <!-- :src="url" src = 'http://192.168.0.112:7456/build/index.html' src = 'http://192.168.0.109:7456/'-->
  4. <!-- @receivedtitle="onReceivedTitle" @pagefinish="onPageFinish" http://192.168.31.223:7456/-->
  5. <view class="web-view">
  6. <web-view class="web-view-child" :src="url" ref="webview" @pagestart="onPageStart"
  7. @onPostMessage="handlePostMessage" @error="onError"></web-view>
  8. </view>
  9. <view class="web-back" @click="navBack">
  10. <image style="width: 40rpx;height: 40rpx;" src="/static/gameCloseW.png"></image>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import reqUtil from "@/util/util-js/requstUtil.js";
  16. import config from "@/common/config.js";
  17. import fruit from "@/components/fruitMachine/fruit.js"
  18. // import AccAndOri from "@/util/util-js/AccAndOri.js"
  19. import puchConfig from "@/util/util-js/puchConfig.js"
  20. import EquipmentAction from "@/util/util-js/EquipmentAction.js"
  21. import ActionJump from "@/util/util-js/action/jump-0.2.js"
  22. var currentWebview;
  23. var orientId = null,
  24. accId = null;
  25. import {
  26. mapState,
  27. mapMutations
  28. } from 'vuex';
  29. export default {
  30. computed: mapState([
  31. 'avatarUrl', 'gender', 'userName', 'city', 'BLEConnectDevice', 'instructionState',
  32. 'currentInstruction',
  33. 'cIndex', 'globalAcc', 'globalOri', 'LocationGameUrl',
  34. 'ConnectBindingDevice',
  35. 'currentModeIndex',
  36. 'bOldDeviceType'
  37. ]),
  38. data() {
  39. return {
  40. url: '',
  41. pagefinish: '',
  42. error: '',
  43. PageStart: false, // 记录网页请求的加载状态,true 加载成功 false 加载失败
  44. gameQuitListener: false, //游戏是否初始化退出监听
  45. xA: 0,
  46. yA: 0,
  47. zA: 0,
  48. oldxA: 0,
  49. oldzA: 0,
  50. bUpdateOnce: false,
  51. bDelayOnce: false,
  52. mass: puchConfig.BOXING_MASS,
  53. //X轴的变化数组值
  54. xAccArray: [],
  55. xMax: 0,
  56. maxTimeoutId: null,
  57. bMaxPause: false,
  58. xMin: 0,
  59. minTimeoutId: null,
  60. bMinPause: false,
  61. bCalculation: false,
  62. calTimeout: null,
  63. //角度比 z/x
  64. angleRatio: 1, //
  65. //当前选择的item
  66. decodeItem: null,
  67. //拳击数据判断对象
  68. EquipmentActionObj: null,
  69. BLENum: 0,
  70. BLEACX: 0,
  71. BLEACYL: 0,
  72. //是否是游戏里面开启的监听,如果是的话,退出游戏界面时候需要关闭相应的监听,如加速计和陀螺仪
  73. bGameOpenListen: false,
  74. //手机陀螺仪和加速计android模块
  75. bMyAttitudeListen: false,
  76. /**
  77. * 跳绳相应数据
  78. */
  79. //跳绳数据判断对象
  80. actionJumpObj: null,
  81. BLEAccIndex: 0,
  82. //定义事件映射表
  83. handlers: new Map()
  84. }
  85. },
  86. onLoad() {
  87. let _self = this;
  88. var pages = getCurrentPages();
  89. var page = pages[pages.length - 1];
  90. currentWebview = page.$getAppWebview();
  91. //监听一次调用setOnceGameOption
  92. console.log("子组件初始化");
  93. uni.$once("setOnceGameOption", (option) => {
  94. console.log("setOnceGameOption=", option);
  95. if (option && option.item) {
  96. this.decodeItem = JSON.parse(decodeURIComponent(option.item));
  97. this.url = this.decodeItem.gameWebUrl;
  98. let temp = {
  99. fObjectId: this.decodeItem.gameId,
  100. recentlyType: 0
  101. }
  102. // console.log("game temp:", config.URL.RECENTLYPLAYINGADD);
  103. //添加最近在玩的游戏
  104. reqUtil.requestData(config.URL.RECENTLYPLAYINGADD, temp).then(res => {
  105. console.log('RECENTLYPLAYINGADD =====', res);
  106. if (res.code == 0) {}
  107. },
  108. e => {
  109. console.log(e)
  110. });
  111. }
  112. });
  113. //子窗体onload 后获取父窗体的onload数据
  114. uni.$emit("game-load");
  115. uni.getCurrentSubNVue().addEventListener("hide", function() {
  116. console.log("subNVue子窗体已隐藏!");
  117. //通知游戏,页面退出
  118. _self.sendMessage("onSubHide", {
  119. msg: '退出页面'
  120. });
  121. uni.$off('updateBLEDeviceData', _self.BLECallback);
  122. //json
  123. uni.$off('updateBLEDeviceJson', _self.BLEJsonCallback);
  124. //去掉监听
  125. if (_self.bMyAttitudeListen) {
  126. _self.gStopSimulateBLEUpdate();
  127. }
  128. //停止脸部检测
  129. _self.handleFaceStopDetect();
  130. // console.log(_self.BLEConnectDevice);
  131. //如果连接了蓝牙设备是手柄
  132. if (_self.BLEConnectDevice && (_self.BLEConnectDevice.deviceType == "BLEHandle" || _self
  133. .BLEConnectDevice.deviceType == "BLEIntelligent")) {
  134. //开启设备回调 3/4关闭
  135. _self.onWriteBLEConnectionValue({
  136. value: "4"
  137. });
  138. //关闭json 回调
  139. _self.onWriteBLEConnectionValue({
  140. value: "6"
  141. });
  142. uni.$off('updateBLEDeviceData', _self.gWatchBLEUpdate);
  143. if (0 === _self.currentModeIndex) {
  144. //拳击柱
  145. _self.uploadUserData_hitCount();
  146. }
  147. } //关闭跳绳模式指令
  148. else if (_self.BLEConnectDevice && _self.BLEConnectDevice.deviceType == "BLERope") {
  149. console.warn("还没设置关闭跳绳模式")
  150. _self.B_CloseRopeSkipping();
  151. uni.$off('updateBLEDeviceData', _self.gWatchBLEUpdate);
  152. }
  153. uni.$emit("game-unload", {
  154. globalAcc: _self.globalAcc,
  155. globalOri: _self.globalOri,
  156. bGameOpenListen: _self.bGameOpenListen
  157. });
  158. });
  159. //*****注释蓝牙操作******
  160. // 监听事件
  161. // uni.$on('callbackCloseBLE', this.callbackCloseBLE);
  162. // uni.$on('callbackBLEState', this.callbackBLEState);
  163. // uni.$on('updateBLEDeviceData', this.BLECallback);
  164. //监听物理返回按钮
  165. plus.key.addEventListener('backbutton', () => {
  166. this.navBack();
  167. }, false);
  168. //设置store状态
  169. _self.$store.state.bGamePlaying = true;
  170. // 注册事件
  171. _self.registerHandlers();
  172. },
  173. onUnload() {
  174. this.$store.state.bGamePlaying = false;
  175. console.log("subNVue子窗体 onUnload!");
  176. //*****注释蓝牙操作******
  177. // uni.$off('callbackCloseBLE', this.callbackCloseBLE);
  178. // uni.$off('callbackBLEState', this.callbackBLEState);
  179. //取消相应的绑定事件
  180. uni.$off('watchAcceleration', this.gWatchAcceleration);
  181. uni.$off("watchAcceleration", this.gWatchBoxingAcc);
  182. uni.$off("watchAcceleration", this.gWatchHitBoxingAcc);
  183. uni.$off('watchOrientation', this.gWatchOrientation);
  184. uni.$emit("game-unload");
  185. },
  186. methods: {
  187. ...mapMutations(['addlocalCalorie', 'syncRequestEvent', 'onWriteBLEConnectionValue',
  188. 'B_WriteHexToBLECharacteristic',
  189. 'gCreateFilterObj', 'gUpdateFilter', 'B_OpenRopeSkipping', 'B_CloseRopeSkipping',
  190. 'gStopSimulateBLEUpdate', 'gStartSimulateBLEUpdate', 'gIntelligentUpdateSandbagAlgorithm',
  191. 'gUpdateSandbagAlgorithm',
  192. 'gCreateSandbagAlgorithm', 'gIntelligentCreateSandbagAlgorithm', 'onConvertDeviceData',
  193. 'addSandbagHitCount', 'uploadUserData_hitCount',
  194. 'jumpIdenModule_onJump6AxisDataUpdate',
  195. //面部识别START
  196. 'faceModule_startDetect', 'faceModule_stopDetect', 'faceModule_setPreview'
  197. //面部识别END
  198. ]),
  199. navBack() {
  200. this.sendMessage("onQuit", {
  201. type: "right-button",
  202. msg: '点击右上角按钮退出游戏'
  203. });
  204. uni.showModal({
  205. title: '提示',
  206. content: '是否退出游戏?',
  207. success: (res) => {
  208. //如果游戏需要监听退出,则需要走完游戏端流程,才能退出,否则直接退出
  209. if (this.gameQuitListener) {
  210. this.sendMessage("onQuitModal", {
  211. data: res,
  212. msg: '退出提示'
  213. });
  214. } else {
  215. if (res.confirm) {
  216. uni.getCurrentSubNVue().hide('auto');
  217. }
  218. }
  219. }
  220. })
  221. },
  222. //蓝牙断开连接时候
  223. callbackCloseBLE() {
  224. this.sendMessage("onDeviceClose", {
  225. msg: '设备断开连接。'
  226. });
  227. },
  228. //蓝牙状态回调
  229. callbackBLEState(res) {
  230. // console.log("game callbackBLEState==", res);
  231. // 暂时只返回数据连接错误信息
  232. // uni.$emit("callbackBLEState", {
  233. // state: -1,
  234. // msg: "设备数据错误"
  235. // });
  236. this.sendMessage("onDeviceState", res)
  237. },
  238. BLECallback(data) {
  239. let dataType = 'Box';
  240. // if (data.hasOwnProperty("ax")) {
  241. // dataType = "Accelerometer"
  242. // }else if(data.hasOwnProperty("gx")){
  243. // dataType = "Gyroscope"
  244. // }
  245. // 设备回调后面用这个接口
  246. let BLEState = {
  247. device: this.BLEConnectDevice, //连接的蓝牙设备
  248. instructionState: this.instructionState, //开启的指令状态
  249. currentInstruction: this.currentInstruction, //当前发送的指令记录
  250. dataType: dataType, //回调的数据类型
  251. data: data //蓝牙回调的数据
  252. }
  253. this.sendMessage("onDeviceUpdateData", BLEState);
  254. },
  255. BLEJsonCallback(data) {
  256. let dataType = 'Json';
  257. // 设备回调后面用这个接口
  258. let BLEState = {
  259. device: this.BLEConnectDevice, //连接的蓝牙设备
  260. instructionState: this.instructionState, //开启的指令状态
  261. currentInstruction: this.currentInstruction, //当前发送的指令记录
  262. dataType: dataType, //回调的数据类型
  263. data: data //蓝牙回调的数据
  264. }
  265. this.sendMessage("onDeviceUpdateJson", BLEState);
  266. },
  267. /**
  268. * 图片转化base64
  269. * @param {Object} url
  270. * @param {Object} callback
  271. */
  272. urlToBase64(url, callback) {
  273. let toBase64Url;
  274. uni.request({
  275. url: url,
  276. method: 'GET',
  277. responseType: 'arraybuffer',
  278. success: async res => {
  279. let base64 = uni.arrayBufferToBase64(res.data);
  280. toBase64Url = 'data:image/jpeg;base64,' + base64;
  281. if (callback)
  282. callback(toBase64Url, res.data);
  283. }
  284. })
  285. },
  286. /**
  287. * 初始化发送数据给游戏
  288. */
  289. sendGameInit() {
  290. console.log("this.avatarUrl:", this.avatarUrl);
  291. this.urlToBase64(this.avatarUrl, (toBase64Url) => {
  292. let device = null;
  293. /**
  294. * 卡路里消耗参数
  295. */
  296. let calorieParams = {
  297. hitUnit: 0,
  298. runUnit: puchConfig.getRunCalorie(1),
  299. jumpUnit: puchConfig.getJumpCalorie(1)
  300. };
  301. if (this.BLEConnectDevice) {
  302. // device = {
  303. // cname: this.BLEConnectDevice.cname,
  304. // ename: this.BLEConnectDevice.ename,
  305. // name: this.BLEConnectDevice.name
  306. // };
  307. // calorieParams = {
  308. // runUnit: 0.55, // 比跳的稍微大一点
  309. // jumpUnit: 0.5 // 跳的次数 * 0.5
  310. // };
  311. device = {
  312. cname: this.BLEConnectDevice.cname,
  313. ename: this.BLEConnectDevice.ename,
  314. name: this.BLEConnectDevice.name
  315. };
  316. calorieParams.hitUnit = puchConfig.getBoxingCalorie(1);
  317. } else if (this.ConnectBindingDevice) {
  318. device = {
  319. cname: this.ConnectBindingDevice.cname,
  320. ename: this.ConnectBindingDevice.ename,
  321. name: this.ConnectBindingDevice.name
  322. };
  323. calorieParams.hitUnit = puchConfig.getBoxingCalorie(1);
  324. }
  325. //到时候可能要区分是什么类型
  326. let item = {
  327. id: this.decodeItem.gameId,
  328. name: this.decodeItem.gameName
  329. };
  330. // console.log(this.BLEConnectDevice, device);
  331. let gameData = {
  332. avatarUrl: this.avatarUrl,
  333. avatarBase64Url: toBase64Url,
  334. userName: this.userName,
  335. gender: this.gender,
  336. caloriUnit: 10,//废弃字段
  337. calorieUnit: 10,
  338. calorieParams: calorieParams,
  339. //蓝牙连接的设备
  340. device: device,
  341. item: item
  342. }
  343. this.sendMessage("onGameInit", gameData);
  344. // console.log("onGameInit =", gameData);
  345. })
  346. },
  347. /**
  348. * 统一发送信息
  349. * @param {Object} gameData
  350. */
  351. sendMessage(functionName, gameData) {
  352. let data = {
  353. "funName": functionName,
  354. "gameData": gameData
  355. }
  356. if (!this.PageStart) {
  357. console.warn("页面未初始化不能传消息", data);
  358. return;
  359. }
  360. let initStr = JSON.stringify(data);
  361. // console.log(functionName);
  362. this.$refs.webview.evalJs("onWebViewMessage(" + initStr + ")");
  363. },
  364. sendMessageToWebview() {
  365. if (!this.PageStart) {
  366. uni.showModal({
  367. title: "暴躁的提示",
  368. content: "只有网页加载成功了才可以传参过去,不然无效哦。。"
  369. })
  370. return false;
  371. }
  372. /**
  373. * 下面的 jsfunction 代码你要自己在你的网页里面写一个方法 大致如下
  374. * 下面就是你基本的html知识了,我就不想说什么了,自己学。
  375. window.jsfunction = function(data){
  376. console.log('data', data);
  377. }
  378. */
  379. this.sendMessage("onDeviceUpdateData", {
  380. H: 1
  381. });
  382. },
  383. // 注册所有事件
  384. registerHandlers() {
  385. this.handlers.set("uploadInfo", (gameData) => this.handleUploadInfo(gameData)); //上传分数
  386. this.handlers.set("gameInit", () => this.sendGameInit()); //获取游戏信息
  387. this.handlers.set("aiRandomInfo", (gameData) => this.handleAiRandomInfo(gameData));
  388. this.handlers.set("fruitInfo", (gameData) => this.handleFruitInfo(gameData));
  389. this.handlers.set("urlToBase64", (gameData) => this.handleUrlToBase64(gameData));
  390. this.handlers.set("openAccelerometer", () => this.handleOpenAccelerometer());
  391. this.handlers.set("closeAccelerometer", () => this.handleCloseAccelerometer());
  392. this.handlers.set("openOrientation", () => this.handleOpenOrientation());
  393. this.handlers.set("closeOrientation", () => this.handleCloseOrientation());
  394. this.handlers.set("bindBoxingPost", () => this.handleBindBoxingPost());
  395. this.handlers.set("unbindBoxingPost", () => this.handleUnbindBoxingPost());
  396. this.handlers.set("setAngleRatio", (gameData) => this.handleSetAngleRatio(gameData));
  397. this.handlers.set("bindHitBoxingPost", () => this.handleBindHitBoxingPost());
  398. this.handlers.set("unbindHitBoxingPost", () => this.handleUnbindHitBoxingPost());
  399. this.handlers.set("closeGame", () => this.handleCloseGame());
  400. this.handlers.set("addQuitModal", () => this.handleAddQuitModal());
  401. this.handlers.set("removeQuitModal", () => this.handleRemoveQuitModal());
  402. this.handlers.set("writeBLEConnectionValue", (gameData) => this.handleWriteBLEConnectionValue(gameData));
  403. this.handlers.set("writeHexToBLEDevice", (gameData) => this.handleWriteHexToBLEDevice(gameData));
  404. this.handlers.set("log", (gameData) => console.log(gameData));
  405. this.handlers.set("addDeviceUpdateListener", () => this.handleAddDeviceUpdateListener());
  406. this.handlers.set("closeDeviceUpdateListener", () => this.handleCloseDeviceUpdateListener());
  407. this.handlers.set("addDeviceJsonUpdateListener", () => this.handleAddDeviceJsonUpdateListener());
  408. this.handlers.set("closeDeviceJsonUpdateListener", () => this.handleCloseDeviceJsonUpdateListener());
  409. //用手机的加速计和陀螺仪触发onBoxingPostHit?
  410. this.handlers.set("onStartAccAndGyro", () => this.handleStartAccAndGyro());
  411. this.handlers.set("onStopAccAndGyro", () => this.handleStopAccAndGyro());
  412. //检测脸部函数
  413. this.handlers.set("faceStartDetect", (gameData) => this.handleFaceStartDetect(gameData));
  414. this.handlers.set("faceStopDetect", () => this.handleFaceStopDetect());
  415. this.handlers.set("faceSetPreview", (gameData) => this.handleFaceSetPreview(gameData));
  416. },
  417. handleUploadInfo(gameData) {
  418. //TODO:写入排行榜分数,后面需要在游戏完结里面调用
  419. //TODO: 后面游戏时间,卡路里的需要写入数据库,目前只是处理了分数
  420. // let num = Math.round(Math.random() * 10000);
  421. //1. gameScore 处理上传的分数
  422. // let _temp = {
  423. // gameId: '1595755153789139696',
  424. // score: 1230,
  425. // cityCode: '110101',
  426. // };
  427. //2. calorieBurned 处理卡路里
  428. // 记录卡路里到本地
  429. this.addlocalCalorie(gameData.calorieBurned);
  430. console.log("gameData.calorieBurned", gameData.calorieBurned);
  431. //然后更新上服务器
  432. this.syncRequestEvent({
  433. success: () => {
  434. // uni.$emit('updateArcbarData', '');
  435. let _temp = {
  436. //假如排行id 为空,排行榜就是游戏自己的id
  437. gameId: this.decodeItem.gameRankingId == null ? this.decodeItem
  438. .gameId : this.decodeItem.gameRankingId,
  439. score: gameData.gameScore,
  440. cityCode: this.city.cityCode,
  441. bMaxLimit: true
  442. }
  443. console.log('_temp =====', _temp);
  444. reqUtil.requestData(config.URL.UPLOADRANKING, _temp, "POST").then(res => {
  445. console.log('UPLOADRANKING =====', res);
  446. if (res.code == 0) {
  447. //TODO 后续游戏数据处理
  448. this.sendMessage("onUploadInfo", {
  449. code: 0,
  450. msg: '上传成功'
  451. });
  452. } else {
  453. //TODO 后续游戏数据处理
  454. this.sendMessage("onUploadInfo", {
  455. code: 400,
  456. msg: '上传失败'
  457. });
  458. }
  459. },
  460. e => {
  461. console.log(e)
  462. });
  463. },
  464. fail: () => {
  465. this.sendMessage("onUploadInfo", {
  466. code: 400,
  467. msg: '上传失败'
  468. });
  469. }
  470. });
  471. //3. gameTime 游戏时间
  472. //TODO 后面处理游戏时长
  473. },
  474. handleAiRandomInfo(gameData) {
  475. // 获取aiRandomInfo
  476. reqUtil.requestData(config.URL.AIRANDOMINFO, {}).then(res => {
  477. console.log('AIRANDOMINFO =====', res);
  478. if (res.code == 0) {
  479. let data = res.data;
  480. this.urlToBase64(data.aiAvatar, (toBase64Url) => {
  481. let sendData = {
  482. aiId: data.aiId,
  483. aiName: data.aiName,
  484. aiGender: data.aiGender,
  485. aiType: data.aiType,
  486. aiAvatarBase64Url: toBase64Url
  487. }
  488. this.sendMessage("onAiRandomInfo", sendData);
  489. })
  490. }
  491. },
  492. e => {
  493. console.log(e)
  494. });
  495. },
  496. handleFruitInfo(gameData) {
  497. let fruitIndexArray = [0, 0, 0];
  498. if (gameData.hasOwnProperty("calorie")) {
  499. fruitIndexArray = fruit.getFruitIndex(gameData.calorie);
  500. }
  501. this.urlToBase64("https://bbeng-bucket.oss-cn-beijing.aliyuncs.com/cocos/fruitMachine.png", (
  502. toBase64Url) => {
  503. this.sendMessage("onFruitInfo", {
  504. // 水果雪碧图
  505. fruitBase64Url: toBase64Url,
  506. // 雪碧图 单张图片宽高
  507. unitWidth: 100,
  508. unitHeight: 100,
  509. unit: "px",
  510. imageStartPosY: 0,
  511. imageEndPosY: -1200,
  512. fruitIndexArray: fruitIndexArray
  513. });
  514. })
  515. },
  516. handleUrlToBase64(gameData) {
  517. if (gameData.url) {
  518. this.urlToBase64(gameData.url, (toBase64Url) => {
  519. this.sendMessage("onUrlToBase64", {
  520. base64: toBase64Url,
  521. });
  522. })
  523. } else {
  524. this.sendMessage("onUrlToBase64", {
  525. base64: {},
  526. });
  527. }
  528. },
  529. handleOpenAccelerometer() {
  530. if (this.globalAcc) {
  531. uni.$off('watchAcceleration', this.gWatchAcceleration);
  532. uni.$on('watchAcceleration', this.gWatchAcceleration);
  533. } else {
  534. uni.$emit("bindAcc", {
  535. callback: (accId) => {
  536. console.log("开启的:globalAcc=", accId);
  537. this.bGameOpenListen = true;
  538. this.$store.state.globalAcc = accId;
  539. uni.$off('watchAcceleration', this.gWatchAcceleration);
  540. uni.$on('watchAcceleration', this.gWatchAcceleration);
  541. }
  542. });
  543. }
  544. },
  545. handleCloseAccelerometer() {
  546. uni.$off('watchAcceleration', this.gWatchAcceleration);
  547. uni.$emit("unBindAcc", this.globalAcc);
  548. this.$store.state.globalAcc = null;
  549. },
  550. handleOpenOrientation() {
  551. //打开陀螺仪
  552. if (this.globalOri) {
  553. uni.$off('watchOrientation', this.gWatchOrientation);
  554. uni.$on('watchOrientation', this.gWatchOrientation);
  555. s } else {
  556. uni.$emit("bindOri", {
  557. callback: (oriId) => {
  558. console.log("开启的:globalOri=", oriId);
  559. this.bGameOpenListen = true;
  560. this.$store.state.globalOri = oriId;
  561. uni.$off('watchOrientation', this.gWatchOrientation);
  562. uni.$on('watchOrientation', this.gWatchOrientation);
  563. }
  564. });
  565. }
  566. },
  567. handleCloseOrientation() {
  568. uni.$off('watchOrientation', this.gWatchOrientation);
  569. uni.$emit("unBindOri", this.globalOri);
  570. this.$store.state.globalOri = null;
  571. },
  572. handleBindBoxingPost() {
  573. if (this.globalAcc) {
  574. uni.$off('watchAcceleration', this.gWatchBoxingAcc);
  575. uni.$on('watchAcceleration', this.gWatchBoxingAcc);
  576. } else {
  577. uni.$emit("bindAcc", {
  578. callback: (accId) => {
  579. console.log("bindBoxingPost开启的:globalAcc=", accId);
  580. this.bGameOpenListen = true;
  581. this.$store.state.globalAcc = accId;
  582. uni.$off('watchAcceleration', this.gWatchBoxingAcc);
  583. uni.$on('watchAcceleration', this.gWatchBoxingAcc);
  584. }
  585. });
  586. }
  587. },
  588. handleUnbindBoxingPost() {
  589. uni.$off('watchAcceleration', this.gWatchBoxingAcc);
  590. uni.$emit("unBindAcc", this.globalAcc);
  591. this.$store.state.globalAcc = null;
  592. },
  593. handleSetAngleRatio(gameData) {
  594. if (gameData) {
  595. this.angleRatio = Number(gameData.angleRatio);
  596. console.log("this.angleRatio:", this.angleRatio);
  597. this.sendMessage("onSetAngleRatio", {
  598. angleRatio: this.angleRatio
  599. });
  600. }
  601. },
  602. handleBindHitBoxingPost() {
  603. /**
  604. * 返回拳击柱的绑定状态
  605. */
  606. console.log("bindHitBoxingPost");
  607. if (this.ConnectBindingDevice) {
  608. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  609. uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
  610. //hotman 沙袋情景
  611. this.gCreateSandbagAlgorithm();
  612. this.gStartSimulateBLEUpdate();
  613. return;
  614. }
  615. if (!this.BLEConnectDevice) return;
  616. //用设备来区分,开启什么加速计;
  617. if (this.BLEConnectDevice.deviceType == "BLEHandle" || this.BLEConnectDevice.deviceType ==
  618. "BLEIntelligent") {
  619. //处理蓝牙设备情况下
  620. //开启设备回调 3/4关闭
  621. this.onWriteBLEConnectionValue({
  622. value: "3"
  623. });
  624. // setTimeout(() => {
  625. // //设置加速计b:20ms a:10ms
  626. // this.onWriteBLEConnectionValue({
  627. // value: config.refreshRate
  628. // });
  629. // }, 2000)
  630. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  631. uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
  632. if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice.usageMode ==
  633. "general") {
  634. //手机情景或者自由模式
  635. this._createEquipmentBasedOnBoxingPostHit();
  636. } else if (this.BLEConnectDevice.usageMode == "hotman") {
  637. //hotman 沙袋情景
  638. // this.gCreateSandbagAlgorithm();
  639. if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
  640. this.gIntelligentCreateSandbagAlgorithm();
  641. } else {
  642. this.gCreateSandbagAlgorithm();
  643. }
  644. }
  645. } else if (this.BLEConnectDevice.deviceType == "mySelf") {
  646. //处理手机本身情况下
  647. if (this.globalAcc) {
  648. uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
  649. uni.$on('watchAcceleration', this.gWatchHitBoxingAcc);
  650. } else {
  651. //开启手机加速计
  652. uni.$emit("bindAcc", {
  653. callback: (accId) => {
  654. console.log("bindHitBoxingPost开启的:globalAcc=", accId);
  655. this.bGameOpenListen = true;
  656. this.$store.state.globalAcc = accId;
  657. uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
  658. uni.$on('watchAcceleration', this.gWatchHitBoxingAcc);
  659. if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice
  660. .usageMode == "general") {
  661. //手机情景或者自由模式
  662. this._createEquipmentBasedOnBoxingPostHit();
  663. } else if (this.BLEConnectDevice.usageMode == "hotman") {
  664. //hotman 沙袋情景 todo
  665. console.warn("没有处理手机加速计的 gCreateFilterObj");
  666. // this.gCreateFilterObj();
  667. }
  668. }
  669. });
  670. }
  671. } else if (this.BLEConnectDevice.deviceType == "BLERope") {
  672. //todo 开启跳绳模式
  673. this.B_OpenRopeSkipping();
  674. // this._createActionJumpOnBoxingPostHit();
  675. //监听蓝牙回调
  676. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  677. uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
  678. }
  679. },
  680. handleUnbindHitBoxingPost() {
  681. /**
  682. * 解绑拳击柱的绑定状态
  683. */
  684. if (this.ConnectBindingDevice) {
  685. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  686. this.gStopSimulateBLEUpdate();
  687. return;
  688. }
  689. if (this.BLEConnectDevice && (this.BLEConnectDevice.deviceType == "BLEHandle" || this
  690. .BLEConnectDevice.deviceType == "BLEIntelligent")) {
  691. //开启设备回调 3/4关闭
  692. this.onWriteBLEConnectionValue({
  693. value: "4"
  694. });
  695. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  696. } else if (this.BLEConnectDevice && this.BLEConnectDevice.deviceType == "BLERope") {
  697. console.warn("unbindHitBoxingPost 还没设置关闭跳绳模式")
  698. this.onClearData();
  699. this.B_CloseRopeSkipping();
  700. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  701. } else {
  702. uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
  703. uni.$emit("unBindAcc", this.globalAcc);
  704. this.$store.state.globalAcc = null;
  705. }
  706. },
  707. handleCloseGame() {
  708. uni.getCurrentSubNVue().hide('auto');
  709. },
  710. handleAddQuitModal() {
  711. this.gameQuitListener = true;
  712. this.sendMessage("onQuitModalListener", {
  713. bListener: this.gameQuitListener
  714. });
  715. },
  716. handleRemoveQuitModal() {
  717. this.gameQuitListener = false;
  718. this.sendMessage("onQuitModalListener", {
  719. bListener: this.gameQuitListener
  720. });
  721. },
  722. handleWriteBLEConnectionValue(gameData) {
  723. if (!gameData.value || gameData.value == "") return;
  724. if (!this.BLEConnectDevice) return;
  725. //蓝牙写入数据
  726. this.onWriteBLEConnectionValue(gameData);
  727. },
  728. handleWriteHexToBLEDevice(gameData) {
  729. if (!gameData.value || gameData.value == "") return;
  730. if (!this.BLEConnectDevice) return;
  731. //蓝牙写入数据
  732. this.B_WriteHexToBLECharacteristic(gameData);
  733. },
  734. handleAddDeviceUpdateListener() {
  735. uni.$off('updateBLEDeviceData', this.BLECallback);
  736. uni.$on('updateBLEDeviceData', this.BLECallback);
  737. },
  738. handleCloseDeviceUpdateListener() {
  739. uni.$off('updateBLEDeviceData', this.BLECallback);
  740. },
  741. handleAddDeviceJsonUpdateListener() {
  742. uni.$off('updateBLEDeviceJson', this.BLEJsonCallback);
  743. uni.$on('updateBLEDeviceJson', this.BLEJsonCallback);
  744. },
  745. handleCloseDeviceJsonUpdateListener() {
  746. uni.$off('updateBLEDeviceJson', this.BLEJsonCallback);
  747. },
  748. //获取手机原始陀螺仪和加速计数据
  749. handleStartAccAndGyro() {
  750. this.bMyAttitudeListen = true;
  751. this.gStartSimulateBLEUpdate();
  752. //监听蓝牙回调
  753. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  754. uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
  755. },
  756. handleStopAccAndGyro() {
  757. this.bMyAttitudeListen = false;
  758. this.gStopSimulateBLEUpdate();
  759. //监听蓝牙回调
  760. uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
  761. },
  762. handleFaceStartDetect(gameData) {
  763. this.faceModule_startDetect({
  764. options: gameData,
  765. callback: (data) => {
  766. //回调识别数据
  767. this.sendMessage("onFaceDetectUpdate", data);
  768. }
  769. });
  770. },
  771. handleFaceStopDetect() {
  772. this.faceModule_stopDetect();
  773. },
  774. handleFaceSetPreview(gameData) {
  775. // 提取配置,提供默认值
  776. const {
  777. preview = true,
  778. overlay = true,
  779. closeButton = true
  780. } = gameData;
  781. this.faceModule_setPreview({
  782. preview,
  783. overlay,
  784. closeButton
  785. })
  786. },
  787. handlePostMessage: function(postData) {
  788. console.log("handlePostMessage得到参数", postData.detail);
  789. let temp = postData.detail.data[0];
  790. let gameData = temp.gameData;
  791. let handler = this.handlers.get(temp.funName);
  792. if (handler) {
  793. handler(gameData);
  794. } else {
  795. console.warn("未知的 funName:", temp.funName);
  796. }
  797. // if (temp.funName == "uploadInfo") {}
  798. // else if (temp.funName == "gameInit") {}
  799. // else if (temp.funName == "aiRandomInfo") {}
  800. // else if (temp.funName == "fruitInfo") {}
  801. // else if (temp.funName == "urlToBase64") {}
  802. // else if (temp.funName == "openAccelerometer") {}
  803. // else if (temp.funName == "closeAccelerometer") {}
  804. // else if (temp.funName == "openOrientation") {}
  805. // else if (temp.funName == "closeOrientation") {}
  806. // else if (temp.funName == "bindBoxingPost") {}
  807. // else if (temp.funName == "unbindBoxingPost") {}
  808. // else if (temp.funName == "setAngleRatio") {}
  809. // else if (temp.funName == "bindHitBoxingPost") {}
  810. // else if (temp.funName == "unbindHitBoxingPost") {}
  811. // else if (temp.funName == "closeGame") {}
  812. // else if (temp.funName == "addQuitModal") {}
  813. // else if (temp.funName == "removeQuitModal") {}
  814. // else if (temp.funName == "writeBLEConnectionValue") {}
  815. // else if (temp.funName == "writeHexToBLEDevice") {}
  816. // else if (temp.funName == "log") {}
  817. // else if (temp.funName == "addDeviceUpdateListener") {}
  818. // else if (temp.funName == "closeDeviceUpdateListener") {}
  819. // else if (temp.funName == "addDeviceJsonUpdateListener") {}
  820. // else if (temp.funName == "closeDeviceJsonUpdateListener") {}
  821. // else if (temp.funName == "onStartAccAndGyro") {}
  822. // else if (temp.funName == "onStopAccAndGyro") {}
  823. },
  824. onPageStart: function(e) {
  825. // 监听页面加载成功
  826. this.PageStart = true;
  827. console.log("onPageStart==", e);
  828. setTimeout(() => {
  829. //加载成功后,显示
  830. uni.getCurrentSubNVue().show('fade-in', 250, () => {});
  831. }, 100)
  832. },
  833. onPageFinish: function(e) {
  834. console.log("onPageFinish==", e);
  835. },
  836. onError: function(e) {
  837. // 监听页面加载错误
  838. // this.error = this.url;
  839. console.error(e);
  840. },
  841. gWatchAcceleration: function(a) {
  842. this.sendMessage("onWatchAccelerometer", a);
  843. return;
  844. if (this.ConnectBindingDevice && this.ConnectBindingDevice.deviceType == 1) {
  845. this.sendMessage("onWatchAccelerometer", a);
  846. } else if (this.BLEConnectDevice && this.cIndex != -1) {
  847. this.sendMessage("onWatchAccelerometer", a);
  848. }
  849. },
  850. gWatchOrientation: function(o) {
  851. this.sendMessage("onWatchOrientation", o);
  852. return;
  853. if (this.ConnectBindingDevice && this.ConnectBindingDevice.deviceType == 1) {
  854. this.sendMessage("onWatchOrientation", o);
  855. } else if (this.BLEConnectDevice && this.cIndex != -1) {
  856. this.sendMessage("onWatchOrientation", o);
  857. }
  858. },
  859. //监听返回计算好的puch
  860. gWatchBoxingAcc: function(a) {
  861. if (this.ConnectBindingDevice && this.ConnectBindingDevice.deviceType == 1) {
  862. //计算返回 puch leftPunch rightPunch
  863. this.updateHitData(a);
  864. } else if (this.BLEConnectDevice && this.cIndex != -1) {
  865. this.updateHitData(a);
  866. }
  867. },
  868. //只返回一个hit状态
  869. gWatchHitBoxingAcc: function(a) {
  870. if (this.ConnectBindingDevice && this.ConnectBindingDevice.deviceType == 1) {
  871. //计算返回 puch leftPunch rightPunch
  872. this.EquipmentActionObj.updateAcc({
  873. xA: a.xAxis,
  874. zA: a.yAxis,
  875. yA: a.zAxis
  876. })
  877. } else if (this.cIndex != -1 && this.BLEConnectDevice != null) {
  878. if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice.usageMode == "general") {
  879. this.EquipmentActionObj.updateAcc({
  880. xA: a.xAxis,
  881. zA: a.yAxis,
  882. yA: a.zAxis,
  883. bLimitRebound: false
  884. })
  885. } else if (this.BLEConnectDevice.usageMode == "hotman") {
  886. //hotman 沙袋情景 todo
  887. //后面处理手机加速计的数据
  888. }
  889. }
  890. },
  891. gWatchBLEUpdate: function(data) {
  892. //如果是模块外面触发,需要离线打包
  893. if (this.bMyAttitudeListen) {
  894. this.sendMessage("updateAccAndGyro", data);
  895. return;
  896. }
  897. if (this.ConnectBindingDevice) {
  898. //hotman 沙袋情景 todo
  899. this.gUpdateSandbagAlgorithm({
  900. data: data,
  901. callback: (res) => {
  902. // console.log(res);
  903. if (res.type == 'hit') {
  904. // console.log('gUpdateFilter callback:',res)
  905. //记录打击次数
  906. this.addSandbagHitCount({
  907. count: 1
  908. });
  909. let temp = {
  910. direction: res.direction,
  911. angle: res.angle,
  912. name: res.name,
  913. ename: res.ename,
  914. value: res.hit,
  915. mass: 10, //质量
  916. hitPower: res.hit, //计算的力
  917. //新增类型
  918. sendType: "ConnectBindingDevice",
  919. type: "none"
  920. }
  921. this.sendMessage("onBoxingPostHit", temp);
  922. }
  923. }
  924. });
  925. return;
  926. }
  927. if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice.usageMode == "general") {
  928. //手机情景或者自由模式
  929. let {
  930. ax,
  931. ay,
  932. az
  933. } = data.acc;
  934. //this.BLEConnectDevice.limitType == "rebound"
  935. //这里是监听 _createEquipmentBasedOnBoxingPostHit 回调
  936. this.EquipmentActionObj.updateTriaxialAcc({
  937. xA: ax * 9.80665,
  938. zA: ay * 9.80665,
  939. yA: az * 9.80665,
  940. bLimitRebound: false
  941. })
  942. } else if (this.BLEConnectDevice.usageMode == "hotman") {
  943. if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
  944. //智能hotman 沙袋情景
  945. this.gIntelligentUpdateSandbagAlgorithm({
  946. data: data,
  947. callback: (res) => {
  948. // console.log(res);
  949. if (res.type == 'hit') {
  950. // console.log('gUpdateFilter callback:',res)
  951. //记录打击次数
  952. this.addSandbagHitCount({
  953. count: 1
  954. });
  955. let temp = {
  956. direction: res.direction,
  957. angle: res.angle,
  958. name: res.name,
  959. ename: res.ename,
  960. value: res.hit,
  961. mass: 10, //质量
  962. hitPower: res.hit, //计算的力
  963. //新增类型
  964. sendType: "hotman",
  965. type: "none"
  966. }
  967. this.sendMessage("onBoxingPostHit", temp);
  968. }
  969. }
  970. });
  971. } else {
  972. //hotman 沙袋情景 todo
  973. this.gUpdateSandbagAlgorithm({
  974. data: data,
  975. callback: (res) => {
  976. // console.log(res);
  977. if (res.type == 'hit') {
  978. // console.log('gUpdateFilter callback:',res)
  979. //记录打击次数
  980. this.addSandbagHitCount({
  981. count: 1
  982. });
  983. let temp = {
  984. direction: res.direction,
  985. angle: res.angle,
  986. name: res.name,
  987. ename: res.ename,
  988. value: res.hit,
  989. mass: 10, //质量
  990. hitPower: res.hit, //计算的力
  991. //新增类型
  992. sendType: "hotman",
  993. type: "none"
  994. }
  995. this.sendMessage("onBoxingPostHit", temp);
  996. }
  997. }
  998. });
  999. }
  1000. } else if (this.BLEConnectDevice.usageMode == "ropeSkipping") {
  1001. //跳绳蓝牙反馈
  1002. this.onBLERopeUpdate(data);
  1003. }
  1004. },
  1005. updateHitData(a) {
  1006. this.xA = a.xAxis;
  1007. this.yA = a.yAxis;
  1008. this.zA = a.zAxis;
  1009. if (Math.abs(this.xA) > 8 && this.oldxA != this.xA && !this.bCalculation) {
  1010. this.xAccArray.push(this.xA);
  1011. this.oldxA = this.xA;
  1012. if (this.calTimeout == null) {
  1013. this.calTimeout = setTimeout(() => {
  1014. this.bCalculation = true;
  1015. for (let i = 0; i < this.xAccArray.length; i++) {
  1016. if (this.xAccArray[i] < 0 && this.xAccArray[i] < this.xAccArray[this.xMin]) {
  1017. this.xMin = i;
  1018. } else if (this.xAccArray[i] > 0 && this.xAccArray[i] > this.xAccArray[this
  1019. .xMax]) {
  1020. this.xMax = i;
  1021. }
  1022. }
  1023. console.log(this.xAccArray, "==", this.xMin, "==", this.xMax);
  1024. if (this.xAccArray[this.xMin] < 0 && this.xAccArray[this.xMax] > 0) {
  1025. if (this.xMin > this.xMax)
  1026. this.onHit("xRCount", "左勾拳", "leftPunch", this.xAccArray[this.xMin], Math.ceil(
  1027. Math.abs(this.xAccArray[this.xMin]) *
  1028. puchConfig.BOXING_MASS));
  1029. else if (this.xMin < this.xMax)
  1030. this.onHit("xLCount", "右勾拳", "rightPunch", this.xAccArray[this.xMax], Math
  1031. .ceil(Math.abs(this.xAccArray[this
  1032. .xMax]) * puchConfig.BOXING_MASS));
  1033. } else if (this.xAccArray[this.xMin] < 0) {
  1034. this.onHit("xLCount", "右勾拳", "rightPunch", this.xAccArray[this.xMin], Math.ceil(
  1035. Math.abs(this.xAccArray[this.xMin]) *
  1036. puchConfig.BOXING_MASS));
  1037. } else if (this.xAccArray[this.xMax] > 0) {
  1038. this.onHit("xRCount", "左勾拳", "leftPunch", this.xAccArray[this.xMax], Math.ceil(Math
  1039. .abs(this.xAccArray[this.xMax]) *
  1040. puchConfig.BOXING_MASS));
  1041. }
  1042. setTimeout(() => {
  1043. this.onResetCal();
  1044. }, 100);
  1045. this.calTimeout = null;
  1046. }, 200);
  1047. }
  1048. } else if (this.zA < -10 && this.oldzA != this.zA && this.xAccArray.length == 0) {
  1049. console.log("this.zA:", this.zA);
  1050. this.oldzA = this.zA;
  1051. setTimeout(() => {
  1052. this.onResetCal();
  1053. }, 200);
  1054. this.onHit("zLCount", "直拳", "punch", this.zA, Math.ceil(Math.abs(this.zA) * puchConfig.BOXING_MASS));
  1055. }
  1056. },
  1057. onHit(direction, name, ename, direValue, power) {
  1058. // console.log(direction, direValue, power);
  1059. let temp = {
  1060. direction: direction,
  1061. angle: 0,
  1062. name: name,
  1063. ename: ename,
  1064. value: direValue,
  1065. mass: this.mass, //质量
  1066. hitPower: power, //计算的力
  1067. //新增类型
  1068. sendType: "BindBoxingPost",
  1069. type: "none"
  1070. }
  1071. this.sendMessage("onBoxingPostHit", temp);
  1072. },
  1073. onResetCal() {
  1074. this.xAccArray = [];
  1075. this.xMax = 0;
  1076. this.xMin = 0;
  1077. this.bCalculation = false;
  1078. this.oldxA = 0;
  1079. this.oldzA = 0;
  1080. this.calTimeout = null;
  1081. },
  1082. //创建一个 打击对象
  1083. _createEquipmentBasedOnBoxingPostHit() {
  1084. this.EquipmentActionObj = new EquipmentAction();
  1085. this.EquipmentActionObj.addEventListener("resultantHit", (e) => {
  1086. console.log(e);
  1087. let temp = {
  1088. direction: "allCount",
  1089. angle: 0,
  1090. name: "击中",
  1091. ename: "hit",
  1092. value: e.acc,
  1093. mass: e.mass, //质量
  1094. hitPower: e.power, //计算的力
  1095. //新增类型
  1096. sendType: "EquipmentActionObj",
  1097. type: "none"
  1098. }
  1099. this.sendMessage("onBoxingPostHit", temp);
  1100. })
  1101. },
  1102. /**
  1103. * 创建一个 跳识别对象
  1104. * @deprecated 此方法废弃,将使用c语音识别算法。
  1105. */
  1106. _createActionJumpOnBoxingPostHit() {
  1107. this.actionJumpObj = new ActionJump();
  1108. this.actionJumpObj.addEventListener('resultant', (e) => {
  1109. let temp = {
  1110. direction: "all",
  1111. angle: 0,
  1112. name: "击中", // this.BLEConnectDevice.name,
  1113. ename: "hit", //this.BLEConnectDevice.ename,
  1114. value: 10,
  1115. mass: 10, //质量
  1116. hitPower: 10, //计算的力
  1117. //新增类型
  1118. sendType: "ActionJumpObj",
  1119. type: "none"
  1120. }
  1121. if (e.type == 'stateDataOfJump') {
  1122. // console.log("game stateDataOfJump");
  1123. this.sendMessage("onBoxingPostHit", temp);
  1124. } else if (e.type == 'stop') {
  1125. // console.log("game stop");
  1126. this.onClearData();
  1127. }
  1128. })
  1129. },
  1130. /**
  1131. * @param {Object} gameData
  1132. * 识别跳部分数据处理
  1133. */
  1134. onBLERopeUpdate(gameData) {
  1135. //调用识别算法
  1136. this.jumpIdenModule_onJump6AxisDataUpdate({
  1137. data: {
  1138. hex: gameData.hex
  1139. },
  1140. callback: (res) => {
  1141. if (res.code == 0) {
  1142. if (res.tag != -1) {
  1143. // this.jumpIdenModule_listenStateDataOfJump(res);
  1144. /**
  1145. * @deprecated
  1146. */
  1147. let temp = {
  1148. direction: "all",
  1149. angle: 0,
  1150. name: "跳", // this.BLEConnectDevice.name,
  1151. ename: "hit", //this.BLEConnectDevice.ename,
  1152. value: 0, //
  1153. mass: 0, //质量
  1154. hitPower: 0, //计算的力
  1155. //新增类型
  1156. sendType: "RopeSkipping",
  1157. type: "none",
  1158. angle: res.tag, //返回一个 tag方向
  1159. }
  1160. switch (res.tag) {
  1161. case 0:
  1162. //JumpType.NORMAL = 0
  1163. temp.type = "normal";
  1164. break;
  1165. case 1:
  1166. //right jump
  1167. temp.type = "right";
  1168. break;
  1169. case 2:
  1170. //left jump
  1171. temp.type = "left";
  1172. break;
  1173. case 3:
  1174. //right rotate jump
  1175. temp.type = "right_rotate";
  1176. break;
  1177. case 4:
  1178. //left rotate jump
  1179. temp.type = "left_rotate";
  1180. break;
  1181. default:
  1182. break;
  1183. }
  1184. this.sendMessage("onBoxingPostHit", temp);
  1185. // uni.showToast({
  1186. // title: res.tag + ',' + res.msg,
  1187. // icon: 'none',
  1188. // duration: 1000,
  1189. // mask: true
  1190. // })
  1191. }
  1192. }
  1193. }
  1194. });
  1195. //********陀螺仪角速度********
  1196. let {
  1197. gx,
  1198. gy,
  1199. gz
  1200. } = gameData.gyro;
  1201. let {
  1202. min,
  1203. s,
  1204. ms
  1205. } = gameData;
  1206. //-gameData.acc.ax * 10;
  1207. let _ax = gameData.acc.ax * 10;
  1208. let _ay = gameData.acc.ay * 10;
  1209. let _az = gameData.acc.az * 10;
  1210. //低通滤波分离重力
  1211. let alpha = 0.8;
  1212. this.xA = alpha * this.xA + (1 - alpha) * _ax;
  1213. this.yA = alpha * this.yA + (1 - alpha) * _ay;
  1214. this.zA = alpha * this.zA + (1 - alpha) * _az;
  1215. //高通滤波获取线性速度
  1216. let linear_acceleration_x = _ax - this.xA;
  1217. let linear_acceleration_y = _az - this.zA;
  1218. let linear_acceleration_z = _ay - this.yA;
  1219. // let _temp = {
  1220. // linearAcc: {
  1221. // lAccX: linear_acceleration_x,
  1222. // lAccY: linear_acceleration_y,
  1223. // lAccZ: linear_acceleration_z
  1224. // }, //gameData.acc,
  1225. // oriAcc: {
  1226. // oAccX: _ax,
  1227. // oAccY: _ay,
  1228. // oAccZ: _az
  1229. // },
  1230. // gravityAcc: {
  1231. // gravityX: this.xA,
  1232. // gravityY: this.yA,
  1233. // gravityZ: this.zA
  1234. // },
  1235. // bLimitRebound: false,
  1236. // resultant: Math.sqrt(_ax * _ax +
  1237. // _ay * _ay + _az * _az),
  1238. // runIndex: this.BLEAccIndex,
  1239. // //陀螺仪
  1240. // oriGyro: {
  1241. // oGyroX: gx,
  1242. // oGyroY: gy,
  1243. // oGyroZ: gz
  1244. // },
  1245. // //输入当前轴,旧设备使用Y轴,即为true
  1246. // bYAxis: this.bOldDeviceType ? true : false,
  1247. // };
  1248. // this.actionJumpObj.updateJump(_temp);
  1249. this.BLEAccIndex++;
  1250. },
  1251. onClearData() {
  1252. this.BLEAccIndex = 0;
  1253. },
  1254. }
  1255. }
  1256. </script>
  1257. <style>
  1258. /* #ifdef APP-PLUS */
  1259. .web-view {
  1260. flex: 1;
  1261. flex-direction: column;
  1262. /* background-color: #007AFF; */
  1263. }
  1264. .web-view-child {
  1265. width: 750rpx;
  1266. flex: 1;
  1267. }
  1268. /* #endif */
  1269. /* #ifdef H5 */
  1270. .web-view {
  1271. display: flex;
  1272. flex-direction: column;
  1273. position: absolute;
  1274. bottom: 0;
  1275. top: 0;
  1276. left: 0;
  1277. right: 0;
  1278. }
  1279. .web-view-child {
  1280. position: relative;
  1281. width: 100%;
  1282. height: 100%;
  1283. }
  1284. /* #endif */
  1285. .sendMessage {
  1286. width: 300rpx;
  1287. position: fixed;
  1288. bottom: 100rpx;
  1289. left: 50rpx;
  1290. }
  1291. .web-back {
  1292. position: fixed;
  1293. top: 40px;
  1294. right: 20px;
  1295. width: 160rpx;
  1296. height: 80rpx;
  1297. border-radius: 45px;
  1298. /* border: 1px solid #FFFFFF; */
  1299. /* box-shadow: 0px 0px 1px #FFFFFF; */
  1300. background-color: rgba(0, 0, 0, 1);
  1301. opacity: 0.5;
  1302. /* #ifndef APP-PLUS-NVUE */
  1303. /* z-Index: 999; */
  1304. display: flex;
  1305. /* #endif */
  1306. justify-content: center;
  1307. align-items: center;
  1308. }
  1309. </style>