|
@@ -63,10 +63,9 @@
|
|
|
import Phaser from 'phaser';
|
|
|
import { onMounted, ref, reactive, onBeforeUnmount, watch } from 'vue';
|
|
|
import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech';
|
|
|
-import { useWebSocket } from '@/utils/bodyposeWs';
|
|
|
const { proxy } = getCurrentInstance() as any;
|
|
|
const router = useRouter();
|
|
|
-const { bodyposeWs, startDevice, checkBodypose, openBodypose, terminateBodypose, suspendBodypose, resumeBodypose, getBodyposeState, closeWS } = useWebSocket();
|
|
|
+const emit = defineEmits(['confirmExit']);
|
|
|
const canvasRef = ref(null);
|
|
|
|
|
|
|
|
@@ -664,210 +663,210 @@ class GameScene extends Phaser.Scene {
|
|
|
console.error('updateScore 错误:', error);
|
|
|
}
|
|
|
}
|
|
|
-enterShootingMode() {
|
|
|
- this.gameActive = false;
|
|
|
- this.isShooting = true;
|
|
|
- this.shootTimeLeft = 15; // 重置剩余时间
|
|
|
-
|
|
|
- // 暂停计分定时器
|
|
|
- if (this.timer) {
|
|
|
- this.timer.paused = true;
|
|
|
- }
|
|
|
-
|
|
|
- // 重置键盘状态
|
|
|
- this.input.keyboard.resetKeys();
|
|
|
- this.cursors.left.isDown = false;
|
|
|
- this.cursors.right.isDown = false;
|
|
|
- this.cursors.up.isDown = false;
|
|
|
- this.cursors.down.isDown = false;
|
|
|
-
|
|
|
- // 停止所有生成事件
|
|
|
- if (this.obstacleEvent) this.obstacleEvent.remove();
|
|
|
- if (this.jerseyEvent) this.jerseyEvent.remove();
|
|
|
- // if (this.broomEvent) this.broomEvent.remove();
|
|
|
-
|
|
|
- // 清除现有障碍物和道具
|
|
|
- this.obstacles.forEach(obs => obs.destroy());
|
|
|
- this.obstacles = [];
|
|
|
- this.powerUps.forEach(p => p.destroy());
|
|
|
- this.powerUps = [];
|
|
|
-
|
|
|
- // 创建射门场景背景
|
|
|
- this.background.setTexture('goalBackground');
|
|
|
-
|
|
|
- // 创建球门
|
|
|
- this.goal = this.physics.add.sprite(GAME_WIDTH / 2, 100, 'goal');
|
|
|
- this.goal.setScale(0.8);
|
|
|
- this.goal.setImmovable(true);
|
|
|
- this.goal.setDepth(5);
|
|
|
-
|
|
|
- // 创建守门员
|
|
|
- this.goalkeeper = this.physics.add.sprite(GAME_WIDTH / 2, 150, 'goalkeeperAnim');
|
|
|
- this.goalkeeper.setScale(0.9);
|
|
|
- this.goalkeeper.setImmovable(true);
|
|
|
- this.goalkeeper.anims.play('goalkeeperAnim', true);
|
|
|
- this.goalkeeper.setDepth(7);
|
|
|
-
|
|
|
- // 让守门员左右移动
|
|
|
- this.tweens.add({
|
|
|
- targets: this.goalkeeper,
|
|
|
- x: [GAME_WIDTH / 2 - 50, GAME_WIDTH / 2 + 50],
|
|
|
- duration: 4000,
|
|
|
- ease: 'Sine.inOut',
|
|
|
- repeat: -1,
|
|
|
- yoyo: true
|
|
|
- });
|
|
|
+ enterShootingMode() {
|
|
|
+ this.gameActive = false;
|
|
|
+ this.isShooting = true;
|
|
|
+ this.shootTimeLeft = 15; // 重置剩余时间
|
|
|
|
|
|
- // 调整球员位置(准备射门)
|
|
|
- this.player.setPosition(GAME_WIDTH / 2, GAME_HEIGHT - 100);
|
|
|
- this.player.setTexture('playerShoot');
|
|
|
- this.player.setVelocity(0);
|
|
|
-
|
|
|
- // 创建足球
|
|
|
- this.ball = this.physics.add.sprite(this.player.x, this.player.y - 50, 'ballAnim');
|
|
|
- this.ball.setScale(0.8);
|
|
|
- this.ball.anims.play('ballAnim', true);
|
|
|
- this.ball.setDepth(8);
|
|
|
-
|
|
|
- // 显示射门提示和倒计时
|
|
|
- // this.shootHint = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT - 80, '点击或按空格键射门', {
|
|
|
- // fontSize: '16px',
|
|
|
- // fill: '#ffffff',
|
|
|
- // backgroundColor: 'rgba(0,0,0,0.5)',
|
|
|
- // padding: { x: 5, y: 2 }
|
|
|
- // }).setOrigin(0.5);
|
|
|
- // this.shootHint.setDepth(10);
|
|
|
-
|
|
|
- // 添加射门倒计时显示
|
|
|
- this.shootTimerText = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT - 50, `剩余时间: ${this.shootTimeLeft}秒`, {
|
|
|
- fontSize: '16px',
|
|
|
- fill: '#ffffff',
|
|
|
- backgroundColor: 'rgba(0,0,0,0.5)',
|
|
|
- padding: { x: 5, y: 2 }
|
|
|
- }).setOrigin(0.5);
|
|
|
- this.shootTimerText.setDepth(10);
|
|
|
-
|
|
|
- // 设置射门超时计时器
|
|
|
- this.shootTimeout = this.time.addEvent({
|
|
|
- delay: 1000, // 每秒触发一次
|
|
|
- callback: () => {
|
|
|
- this.shootTimeLeft--;
|
|
|
- this.shootTimerText.setText(`剩余时间: ${this.shootTimeLeft}秒`);
|
|
|
-
|
|
|
- // 时间到未射门,判定失败
|
|
|
- if (this.shootTimeLeft <= 0) {
|
|
|
- this.handleShootTimeout();
|
|
|
- }
|
|
|
- },
|
|
|
- loop: true
|
|
|
- });
|
|
|
+ // 暂停计分定时器
|
|
|
+ if (this.timer) {
|
|
|
+ this.timer.paused = true;
|
|
|
+ }
|
|
|
|
|
|
- // 射门控制
|
|
|
- this.input.keyboard.on('keydown-SPACE', this.shootBall, this);
|
|
|
- this.input.on('pointerdown', this.shootBall, this);
|
|
|
-}
|
|
|
+ // 重置键盘状态
|
|
|
+ this.input.keyboard.resetKeys();
|
|
|
+ this.cursors.left.isDown = false;
|
|
|
+ this.cursors.right.isDown = false;
|
|
|
+ this.cursors.up.isDown = false;
|
|
|
+ this.cursors.down.isDown = false;
|
|
|
|
|
|
-handleShootTimeout() {
|
|
|
- // 清除超时计时器
|
|
|
- if (this.shootTimeout) {
|
|
|
- this.shootTimeout.remove();
|
|
|
- this.shootTimeout = null;
|
|
|
- }
|
|
|
+ // 停止所有生成事件
|
|
|
+ if (this.obstacleEvent) this.obstacleEvent.remove();
|
|
|
+ if (this.jerseyEvent) this.jerseyEvent.remove();
|
|
|
+ // if (this.broomEvent) this.broomEvent.remove();
|
|
|
+
|
|
|
+ // 清除现有障碍物和道具
|
|
|
+ this.obstacles.forEach(obs => obs.destroy());
|
|
|
+ this.obstacles = [];
|
|
|
+ this.powerUps.forEach(p => p.destroy());
|
|
|
+ this.powerUps = [];
|
|
|
|
|
|
- // 禁用输入
|
|
|
- this.input.keyboard.off('keydown-SPACE', this.shootBall, this);
|
|
|
- this.input.off('pointerdown', this.shootBall, this);
|
|
|
+ // 创建射门场景背景
|
|
|
+ this.background.setTexture('goalBackground');
|
|
|
+
|
|
|
+ // 创建球门
|
|
|
+ this.goal = this.physics.add.sprite(GAME_WIDTH / 2, 100, 'goal');
|
|
|
+ this.goal.setScale(0.8);
|
|
|
+ this.goal.setImmovable(true);
|
|
|
+ this.goal.setDepth(5);
|
|
|
+
|
|
|
+ // 创建守门员
|
|
|
+ this.goalkeeper = this.physics.add.sprite(GAME_WIDTH / 2, 150, 'goalkeeperAnim');
|
|
|
+ this.goalkeeper.setScale(0.9);
|
|
|
+ this.goalkeeper.setImmovable(true);
|
|
|
+ this.goalkeeper.anims.play('goalkeeperAnim', true);
|
|
|
+ this.goalkeeper.setDepth(7);
|
|
|
+
|
|
|
+ // 让守门员左右移动
|
|
|
+ this.tweens.add({
|
|
|
+ targets: this.goalkeeper,
|
|
|
+ x: [GAME_WIDTH / 2 - 50, GAME_WIDTH / 2 + 50],
|
|
|
+ duration: 4000,
|
|
|
+ ease: 'Sine.inOut',
|
|
|
+ repeat: -1,
|
|
|
+ yoyo: true
|
|
|
+ });
|
|
|
|
|
|
- // 移除提示文本
|
|
|
- if (this.shootHint) {
|
|
|
- this.shootHint.destroy();
|
|
|
- this.shootHint = null;
|
|
|
- }
|
|
|
- if (this.shootTimerText) {
|
|
|
- this.shootTimerText.destroy();
|
|
|
- this.shootTimerText = null;
|
|
|
- }
|
|
|
+ // 调整球员位置(准备射门)
|
|
|
+ this.player.setPosition(GAME_WIDTH / 2, GAME_HEIGHT - 100);
|
|
|
+ this.player.setTexture('playerShoot');
|
|
|
+ this.player.setVelocity(0);
|
|
|
|
|
|
- // 显示超时提示
|
|
|
- const timeoutText = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT / 2, '射门超时!', {
|
|
|
- fontSize: '24px',
|
|
|
- fill: '#f00',
|
|
|
- stroke: '#000000',
|
|
|
- strokeThickness: 2
|
|
|
- }).setOrigin(0.5);
|
|
|
- timeoutText.setDepth(10);
|
|
|
-
|
|
|
- // 2秒后返回奔跑场景
|
|
|
- this.time.addEvent({
|
|
|
- delay: 2000,
|
|
|
- callback: () => {
|
|
|
- timeoutText.destroy();
|
|
|
- this.ball.destroy();
|
|
|
- this.resetToRunningScene();
|
|
|
- // 恢复计分定时器
|
|
|
- if (this.timer) {
|
|
|
- this.timer.paused = false;
|
|
|
- }
|
|
|
- },
|
|
|
- callbackScope: this
|
|
|
- });
|
|
|
-}
|
|
|
+ // 创建足球
|
|
|
+ this.ball = this.physics.add.sprite(this.player.x, this.player.y - 50, 'ballAnim');
|
|
|
+ this.ball.setScale(0.8);
|
|
|
+ this.ball.anims.play('ballAnim', true);
|
|
|
+ this.ball.setDepth(8);
|
|
|
+
|
|
|
+ // 显示射门提示和倒计时
|
|
|
+ // this.shootHint = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT - 80, '点击或按空格键射门', {
|
|
|
+ // fontSize: '16px',
|
|
|
+ // fill: '#ffffff',
|
|
|
+ // backgroundColor: 'rgba(0,0,0,0.5)',
|
|
|
+ // padding: { x: 5, y: 2 }
|
|
|
+ // }).setOrigin(0.5);
|
|
|
+ // this.shootHint.setDepth(10);
|
|
|
+
|
|
|
+ // 添加射门倒计时显示
|
|
|
+ this.shootTimerText = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT - 50, `剩余时间: ${this.shootTimeLeft}秒`, {
|
|
|
+ fontSize: '16px',
|
|
|
+ fill: '#ffffff',
|
|
|
+ backgroundColor: 'rgba(0,0,0,0.5)',
|
|
|
+ padding: { x: 5, y: 2 }
|
|
|
+ }).setOrigin(0.5);
|
|
|
+ this.shootTimerText.setDepth(10);
|
|
|
|
|
|
-shootBall() {
|
|
|
- if (!this.isShooting) return;
|
|
|
+ // 设置射门超时计时器
|
|
|
+ this.shootTimeout = this.time.addEvent({
|
|
|
+ delay: 1000, // 每秒触发一次
|
|
|
+ callback: () => {
|
|
|
+ this.shootTimeLeft--;
|
|
|
+ this.shootTimerText.setText(`剩余时间: ${this.shootTimeLeft}秒`);
|
|
|
|
|
|
- // 清除超时计时器
|
|
|
- if (this.shootTimeout) {
|
|
|
- this.shootTimeout.remove();
|
|
|
- this.shootTimeout = null;
|
|
|
- }
|
|
|
+ // 时间到未射门,判定失败
|
|
|
+ if (this.shootTimeLeft <= 0) {
|
|
|
+ this.handleShootTimeout();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ loop: true
|
|
|
+ });
|
|
|
|
|
|
- // 移除时间显示文本
|
|
|
- if (this.shootTimerText) {
|
|
|
- this.shootTimerText.destroy();
|
|
|
- this.shootTimerText = null;
|
|
|
+ // 射门控制
|
|
|
+ this.input.keyboard.on('keydown-SPACE', this.shootBall, this);
|
|
|
+ this.input.on('pointerdown', this.shootBall, this);
|
|
|
}
|
|
|
|
|
|
- // 禁用输入
|
|
|
- this.input.keyboard.off('keydown-SPACE', this.shootBall, this);
|
|
|
- this.input.off('pointerdown', this.shootBall, this);
|
|
|
- this.input.keyboard.off('keydown-LEFT');
|
|
|
- this.input.keyboard.off('keydown-RIGHT');
|
|
|
+ handleShootTimeout() {
|
|
|
+ // 清除超时计时器
|
|
|
+ if (this.shootTimeout) {
|
|
|
+ this.shootTimeout.remove();
|
|
|
+ this.shootTimeout = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 禁用输入
|
|
|
+ this.input.keyboard.off('keydown-SPACE', this.shootBall, this);
|
|
|
+ this.input.off('pointerdown', this.shootBall, this);
|
|
|
+
|
|
|
+ // 移除提示文本
|
|
|
+ if (this.shootHint) {
|
|
|
+ this.shootHint.destroy();
|
|
|
+ this.shootHint = null;
|
|
|
+ }
|
|
|
+ if (this.shootTimerText) {
|
|
|
+ this.shootTimerText.destroy();
|
|
|
+ this.shootTimerText = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示超时提示
|
|
|
+ const timeoutText = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT / 2, '射门超时!', {
|
|
|
+ fontSize: '24px',
|
|
|
+ fill: '#f00',
|
|
|
+ stroke: '#000000',
|
|
|
+ strokeThickness: 2
|
|
|
+ }).setOrigin(0.5);
|
|
|
+ timeoutText.setDepth(10);
|
|
|
|
|
|
- if (this.shootHint) {
|
|
|
- this.shootHint.destroy();
|
|
|
- this.shootHint = null;
|
|
|
+ // 2秒后返回奔跑场景
|
|
|
+ this.time.addEvent({
|
|
|
+ delay: 2000,
|
|
|
+ callback: () => {
|
|
|
+ timeoutText.destroy();
|
|
|
+ this.ball.destroy();
|
|
|
+ this.resetToRunningScene();
|
|
|
+ // 恢复计分定时器
|
|
|
+ if (this.timer) {
|
|
|
+ this.timer.paused = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ callbackScope: this
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- // 计算龙门网内的目标位置
|
|
|
- const goalNetY = this.goal.y + 30;
|
|
|
- const goalNetX = this.player.x;
|
|
|
-
|
|
|
- // 创建射门动画
|
|
|
- const ballTween = this.tweens.add({
|
|
|
- targets: this.ball,
|
|
|
- x: goalNetX,
|
|
|
- y: goalNetY,
|
|
|
- duration: 1000,
|
|
|
- ease: 'Power1',
|
|
|
- onComplete: () => {
|
|
|
- if (!this.ball || !this.ball.active) return;
|
|
|
-
|
|
|
- // 判断是否成功
|
|
|
- const isSuccess = Phaser.Math.Between(0, 1) === 1;
|
|
|
- if (isSuccess) {
|
|
|
- this.score += 3;
|
|
|
- this.updateScore();
|
|
|
- this.ball.setDepth(6.5); // 成功:足球在守门员后方(网内)
|
|
|
- this.successShoot();
|
|
|
- } else {
|
|
|
- this.ball.setDepth(7.5); // 失败:足球在守门员前方
|
|
|
- this.failShoot();
|
|
|
- }
|
|
|
- ballTween.remove();
|
|
|
+ shootBall() {
|
|
|
+ if (!this.isShooting) return;
|
|
|
+
|
|
|
+ // 清除超时计时器
|
|
|
+ if (this.shootTimeout) {
|
|
|
+ this.shootTimeout.remove();
|
|
|
+ this.shootTimeout = null;
|
|
|
}
|
|
|
- });
|
|
|
-}
|
|
|
+
|
|
|
+ // 移除时间显示文本
|
|
|
+ if (this.shootTimerText) {
|
|
|
+ this.shootTimerText.destroy();
|
|
|
+ this.shootTimerText = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 禁用输入
|
|
|
+ this.input.keyboard.off('keydown-SPACE', this.shootBall, this);
|
|
|
+ this.input.off('pointerdown', this.shootBall, this);
|
|
|
+ this.input.keyboard.off('keydown-LEFT');
|
|
|
+ this.input.keyboard.off('keydown-RIGHT');
|
|
|
+
|
|
|
+ if (this.shootHint) {
|
|
|
+ this.shootHint.destroy();
|
|
|
+ this.shootHint = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算龙门网内的目标位置
|
|
|
+ const goalNetY = this.goal.y + 30;
|
|
|
+ const goalNetX = this.player.x;
|
|
|
+
|
|
|
+ // 创建射门动画
|
|
|
+ const ballTween = this.tweens.add({
|
|
|
+ targets: this.ball,
|
|
|
+ x: goalNetX,
|
|
|
+ y: goalNetY,
|
|
|
+ duration: 1000,
|
|
|
+ ease: 'Power1',
|
|
|
+ onComplete: () => {
|
|
|
+ if (!this.ball || !this.ball.active) return;
|
|
|
+
|
|
|
+ // 判断是否成功
|
|
|
+ const isSuccess = Phaser.Math.Between(0, 1) === 1;
|
|
|
+ if (isSuccess) {
|
|
|
+ this.score += 3;
|
|
|
+ this.updateScore();
|
|
|
+ this.ball.setDepth(6.5); // 成功:足球在守门员后方(网内)
|
|
|
+ this.successShoot();
|
|
|
+ } else {
|
|
|
+ this.ball.setDepth(7.5); // 失败:足球在守门员前方
|
|
|
+ this.failShoot();
|
|
|
+ }
|
|
|
+ ballTween.remove();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
// 射门成功处理
|
|
|
successShoot() {
|
|
|
this.isShooting = false;
|
|
@@ -942,42 +941,42 @@ shootBall() {
|
|
|
}
|
|
|
|
|
|
// 重置为奔跑场景
|
|
|
-resetToRunningScene() {
|
|
|
- // 确保清除超时计时器
|
|
|
- if (this.shootTimeout) {
|
|
|
- this.shootTimeout.remove();
|
|
|
- this.shootTimeout = null;
|
|
|
- }
|
|
|
-
|
|
|
- // 清除时间显示文本
|
|
|
- if (this.shootTimerText) {
|
|
|
- this.shootTimerText.destroy();
|
|
|
- this.shootTimerText = null;
|
|
|
- }
|
|
|
+ resetToRunningScene() {
|
|
|
+ // 确保清除超时计时器
|
|
|
+ if (this.shootTimeout) {
|
|
|
+ this.shootTimeout.remove();
|
|
|
+ this.shootTimeout = null;
|
|
|
+ }
|
|
|
|
|
|
- this.clearScene();
|
|
|
+ // 清除时间显示文本
|
|
|
+ if (this.shootTimerText) {
|
|
|
+ this.shootTimerText.destroy();
|
|
|
+ this.shootTimerText = null;
|
|
|
+ }
|
|
|
|
|
|
- // 重置玩家状态
|
|
|
- if (this.player) {
|
|
|
- this.player.setTexture('playerAnim');
|
|
|
- this.player.setPosition(GAME_WIDTH / 2, GAME_HEIGHT - 100);
|
|
|
- this.player.setVelocity(0);
|
|
|
- }
|
|
|
+ this.clearScene();
|
|
|
|
|
|
- // 恢复背景和游戏状态
|
|
|
- if (this.background) this.background.setTexture('grass');
|
|
|
- this.gameActive = true;
|
|
|
- this.isShooting = false;
|
|
|
+ // 重置玩家状态
|
|
|
+ if (this.player) {
|
|
|
+ this.player.setTexture('playerAnim');
|
|
|
+ this.player.setPosition(GAME_WIDTH / 2, GAME_HEIGHT - 100);
|
|
|
+ this.player.setVelocity(0);
|
|
|
+ }
|
|
|
|
|
|
- // 确保足球被销毁
|
|
|
- if (this.ball) {
|
|
|
- this.ball.destroy();
|
|
|
- this.ball = null;
|
|
|
- }
|
|
|
+ // 恢复背景和游戏状态
|
|
|
+ if (this.background) this.background.setTexture('grass');
|
|
|
+ this.gameActive = true;
|
|
|
+ this.isShooting = false;
|
|
|
|
|
|
- // 重新开始生成障碍物
|
|
|
- this.startSpawning();
|
|
|
-}
|
|
|
+ // 确保足球被销毁
|
|
|
+ if (this.ball) {
|
|
|
+ this.ball.destroy();
|
|
|
+ this.ball = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重新开始生成障碍物
|
|
|
+ this.startSpawning();
|
|
|
+ }
|
|
|
|
|
|
gameOver() {
|
|
|
this.gameActive = false;
|
|
@@ -1253,110 +1252,22 @@ watch(
|
|
|
/**
|
|
|
* 初始化
|
|
|
*/
|
|
|
-const getInit = async () => {
|
|
|
- console.log("触发姿态识别")
|
|
|
- let deviceid = localStorage.getItem('deviceid') || '';
|
|
|
- if (!deviceid) {
|
|
|
- proxy?.$modal.msgError(`请重新登录绑定设备号后使用`);
|
|
|
- return false;
|
|
|
+const getInit = (e: any) => {
|
|
|
+ let arr = e.data.result.keypoints;
|
|
|
+ let result = [];
|
|
|
+ for (let i = 0; i < arr.length; i += 3) {
|
|
|
+ result.push(arr.slice(i, i + 2));
|
|
|
}
|
|
|
- bodyposeState.value = true;
|
|
|
- if (wsState.value) {
|
|
|
- proxy?.$modal.msgWarning(`操作过快,请稍后重试`);
|
|
|
- setTimeout(() => {
|
|
|
- bodyposeState.value = false;
|
|
|
- }, 1000)
|
|
|
- return false;
|
|
|
+ //console.log("result", result)
|
|
|
+ bodyposeData.value = result;
|
|
|
+ if (boxes.value.length == 0) {
|
|
|
+ speckText("识别成功");
|
|
|
+ proxy?.$modal.msgWarning(`识别成功`);
|
|
|
+ let arr = e.data.result.boxes;
|
|
|
+ boxes.value = [{ x: arr[0], y: arr[3] }, { x: arr[0], y: arr[1] }, { x: arr[2], y: arr[1] }, { x: arr[2], y: arr[3] }]
|
|
|
+ proportion.value = (clientObj.value.height / (arr[3] - arr[1])).toFixed(2);
|
|
|
}
|
|
|
- speckText("正在姿态识别");
|
|
|
- proxy?.$modal.msgWarning(`正在姿态识别`);
|
|
|
- bodyposeWs((e: any) => {
|
|
|
- //console.log("bodyposeWS", e)
|
|
|
- if (e?.wksid) {
|
|
|
- wsState.value = true;
|
|
|
- //获取设备信息
|
|
|
- startDevice({ deviceid: deviceid });
|
|
|
- console.log("获取设备信息")
|
|
|
- }
|
|
|
- if (e?.type == 'fe_device_init_result') {
|
|
|
- //接收设备信息并发送请求
|
|
|
- if (e?.device_info) {
|
|
|
- deviceInfo.value = e.device_info;
|
|
|
- getCheckBodypose();
|
|
|
- console.log("返回设备信息,检查是否支持姿态识别")
|
|
|
- } else {
|
|
|
- proxy?.$modal.msgError(`设备信息缺失,请重新登录绑定设备号后使用`);
|
|
|
- }
|
|
|
- }
|
|
|
- if (e?.cmd == 'check_bodyposecontroller_available') {
|
|
|
- let handcontroller_id = deviceInfo.value.handcontroller_id;
|
|
|
- if (e?.code == 0) {
|
|
|
- //查看姿态识别状态,如果不处于关闭就先关闭再重新启动(可能会APP退出然后工作站还在运行的可能性)
|
|
|
- getBodyposeState(handcontroller_id);
|
|
|
- againNum.value = 0;
|
|
|
- againTimer.value = null;
|
|
|
- clearTimeout(againTimer.value);
|
|
|
- console.log("查看姿态识别状态")
|
|
|
- } else {
|
|
|
- //尝试多次查询姿态识别状态
|
|
|
- if (againNum.value <= 2) {
|
|
|
- againTimer.value = setTimeout(() => {
|
|
|
- getCheckBodypose();
|
|
|
- }, 500)
|
|
|
- againNum.value++;
|
|
|
- } else {
|
|
|
- let msg = "";
|
|
|
- if (e.code == 102402) {
|
|
|
- msg = `多次连接失败请重试,姿态识别模块被占用`;
|
|
|
- } else {
|
|
|
- msg = `多次连接失败请重试,姿态识别模块不可用,code:${e.code}`;
|
|
|
- }
|
|
|
- proxy?.$modal.msgWarning(msg);
|
|
|
- againNum.value = 0;
|
|
|
- againTimer.value = null;
|
|
|
- clearTimeout(againTimer.value);
|
|
|
- getCloseBodypose();//直接关闭
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- if (e?.cmd == 'get_bodyposecontroller_state') {
|
|
|
- let handcontroller_id = deviceInfo.value.handcontroller_id;
|
|
|
- //state说明: 0:关闭,3:空闲,36:工作中
|
|
|
- if ([3, 36].includes(e.state)) {
|
|
|
- getCloseBodypose();
|
|
|
- proxy?.$modal.msgWarning(`请重新姿态识别`);
|
|
|
- } else {
|
|
|
- openBodypose(handcontroller_id);
|
|
|
- }
|
|
|
- }
|
|
|
- if (e?.type == 'bodyposecontroller_result') {
|
|
|
- let arr = e.data.result.keypoints;
|
|
|
- let result = [];
|
|
|
- for (let i = 0; i < arr.length; i += 3) {
|
|
|
- result.push(arr.slice(i, i + 2));
|
|
|
- }
|
|
|
- //console.log("result", result)
|
|
|
- bodyposeData.value = result;
|
|
|
- if (boxes.value.length == 0) {
|
|
|
- speckText("识别成功");
|
|
|
- proxy?.$modal.msgWarning(`识别成功`);
|
|
|
- let arr = e.data.result.boxes;
|
|
|
- boxes.value = [{ x: arr[0], y: arr[3] }, { x: arr[0], y: arr[1] }, { x: arr[2], y: arr[1] }, { x: arr[2], y: arr[3] }]
|
|
|
- proportion.value = (clientObj.value.height / (arr[3] - arr[1])).toFixed(2);
|
|
|
- }
|
|
|
- getCanvas();
|
|
|
- }
|
|
|
- if (e?.cmd == 'terminate_bodyposecontroller') {
|
|
|
- if (e?.code == 0) {
|
|
|
- closeWS();
|
|
|
- bodyposeState.value = false;
|
|
|
- }
|
|
|
- }
|
|
|
- if (e?.type == 'disconnect') {
|
|
|
- wsState.value = false;
|
|
|
- }
|
|
|
- });
|
|
|
+ getCanvas();
|
|
|
};
|
|
|
|
|
|
|
|
@@ -1567,6 +1478,14 @@ onUnmounted(() => {
|
|
|
game.value.events.off('scoreChanged', scoreListener);
|
|
|
}
|
|
|
});
|
|
|
+onBeforeUnmount(() => {
|
|
|
+
|
|
|
+});
|
|
|
+
|
|
|
+//暴露给父组件用
|
|
|
+defineExpose({
|
|
|
+ getInit
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|