|
@@ -10,6 +10,7 @@ import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatche
|
|
|
import { GameEvent } from './Enum/GameEvent';
|
|
|
import { TempCup } from './Component/TempCup';
|
|
|
import { TempCups } from './Component/TempCups';
|
|
|
+import { tgxUITips } from '../../core_tgx/tgx';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('LevelAction')
|
|
@@ -28,6 +29,13 @@ export class LevelAction extends Component {
|
|
|
goblets: Node = null!; //原浆区
|
|
|
|
|
|
private originCupPositions = new Map<string, Vec3>(); // 改用唯一ID记录
|
|
|
+ private isProcessing = false;
|
|
|
+ private isPouring = false; // 添加状态锁
|
|
|
+ static instance: LevelAction; // 添加静态实例
|
|
|
+
|
|
|
+ onLoad() {
|
|
|
+ LevelAction.instance = this;
|
|
|
+ }
|
|
|
|
|
|
start() {
|
|
|
this.originCupPositions.clear();
|
|
@@ -150,107 +158,124 @@ export class LevelAction extends Component {
|
|
|
}
|
|
|
|
|
|
public async handlePourOriginCup(originCup: OriginCup) {
|
|
|
- // 如果子节点0是底层,需要反转顺序
|
|
|
- const colors: WaterColors[] = [];
|
|
|
- for (let i = originCup.waters.children.length - 1; i >= 0; i--) {
|
|
|
- const waterNode = originCup.waters.children[i];
|
|
|
- if (waterNode.active) {
|
|
|
- const water = waterNode.getComponent(Water);
|
|
|
- colors.push(water.color);
|
|
|
- }
|
|
|
+ if (this.isPouring) {
|
|
|
+ tgxUITips.show('忙碌中...');
|
|
|
+ return;
|
|
|
}
|
|
|
+ this.isPouring = true;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 如果子节点0是底层,需要反转顺序
|
|
|
+ const colors: WaterColors[] = [];
|
|
|
+ for (let i = originCup.waters.children.length - 1; i >= 0; i--) {
|
|
|
+ const waterNode = originCup.waters.children[i];
|
|
|
+ if (waterNode.active) {
|
|
|
+ const water = waterNode.getComponent(Water);
|
|
|
+ colors.push(water.color);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- let hasUnprocessed = false; // 标记是否有未处理的水层
|
|
|
+ let hasUnprocessed = false; // 标记是否有未处理的水层
|
|
|
|
|
|
- for (const color of colors) {
|
|
|
- let targetNode: Node | null = this.findTargetCupInOutArea(color)?.node || null;
|
|
|
- let targetIsTemp = false;
|
|
|
+ for (const color of colors) {
|
|
|
+ let targetNode: Node | null = this.findTargetCupInOutArea(color)?.node || null;
|
|
|
+ let targetIsTemp = false;
|
|
|
+
|
|
|
+ // 调酒区未找到,查找暂存区
|
|
|
+ if (!targetNode) {
|
|
|
+ const tempCupsComp = this.tempCups.getComponent(TempCups);
|
|
|
+ if (!tempCupsComp) {
|
|
|
+ console.error('TempCups component not found!');
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const tempCup = tempCupsComp.findAvailableTempCup();
|
|
|
+ if (tempCup) {
|
|
|
+ targetNode = tempCup.node;
|
|
|
+ targetIsTemp = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 调酒区未找到,查找暂存区
|
|
|
- if (!targetNode) {
|
|
|
- const tempCupsComp = this.tempCups.getComponent(TempCups);
|
|
|
- if (!tempCupsComp) {
|
|
|
- console.error('TempCups component not found!');
|
|
|
- continue;
|
|
|
+ if (!targetNode) {
|
|
|
+ hasUnprocessed = true;
|
|
|
+ console.log(`颜色${WaterColors[color]}未找到可用杯子`);
|
|
|
+ continue; // 继续尝试处理后续颜色
|
|
|
}
|
|
|
- const tempCup = tempCupsComp.findAvailableTempCup();
|
|
|
- if (tempCup) {
|
|
|
- targetNode = tempCup.node;
|
|
|
- targetIsTemp = true;
|
|
|
+
|
|
|
+ await this.pourAnimation(
|
|
|
+ originCup.node,
|
|
|
+ targetNode,
|
|
|
+ color,
|
|
|
+ undefined,
|
|
|
+ targetIsTemp
|
|
|
+ );
|
|
|
+
|
|
|
+ // 更新目标杯
|
|
|
+ if (targetIsTemp) {
|
|
|
+ const tempCupComp = targetNode.getComponent(TempCup)!;
|
|
|
+ tempCupComp.fill(color);
|
|
|
+ } else {
|
|
|
+ const cocktailCup = targetNode.getComponent(CocktailCup)!;
|
|
|
+ await cocktailCup.addLayer(color); // 等待添加水层流程完成
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (!targetNode) {
|
|
|
- hasUnprocessed = true;
|
|
|
- console.log(`颜色${WaterColors[color]}未找到可用杯子`);
|
|
|
- continue; // 继续尝试处理后续颜色
|
|
|
+ this.hideCurrentWaterLayer(originCup);
|
|
|
}
|
|
|
|
|
|
- await this.pourAnimation(
|
|
|
- originCup.node,
|
|
|
- targetNode,
|
|
|
- color,
|
|
|
- undefined,
|
|
|
- targetIsTemp
|
|
|
- );
|
|
|
-
|
|
|
- // 更新目标杯
|
|
|
- if (targetIsTemp) {
|
|
|
- const tempCupComp = targetNode.getComponent(TempCup)!;
|
|
|
- tempCupComp.fill(color);
|
|
|
+ // 处理完所有颜色后检查剩余水层
|
|
|
+ const remaining = originCup.waters.children.filter(n => n.active).length;
|
|
|
+ if (hasUnprocessed || remaining > 0) {
|
|
|
+ console.log("游戏结束:仍有未处理的水层");
|
|
|
+ // 触发游戏结束逻辑
|
|
|
} else {
|
|
|
- const cocktailCup = targetNode.getComponent(CocktailCup)!;
|
|
|
- await cocktailCup.addLayer(color); // 等待添加水层流程完成
|
|
|
+ // 所有水层处理完毕,销毁原浆杯
|
|
|
+ originCup.destroyOriginCup();
|
|
|
+ this.addWaitCupToOutArea();
|
|
|
}
|
|
|
-
|
|
|
- this.hideCurrentWaterLayer(originCup);
|
|
|
- }
|
|
|
-
|
|
|
- // 处理完所有颜色后检查剩余水层
|
|
|
- const remaining = originCup.waters.children.filter(n => n.active).length;
|
|
|
- if (hasUnprocessed || remaining > 0) {
|
|
|
- console.log("游戏结束:仍有未处理的水层");
|
|
|
- // 触发游戏结束逻辑
|
|
|
- } else {
|
|
|
- // 所有水层处理完毕,销毁原浆杯
|
|
|
- originCup.destroyOriginCup();
|
|
|
- this.addWaitCupToOutArea();
|
|
|
+ } finally {
|
|
|
+ this.isPouring = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 新增方法:处理暂存区倒水到调酒区
|
|
|
private async handlePourTempCupToOutArea() {
|
|
|
- const tempCupsComp = this.tempCups.getComponent(TempCups)!;
|
|
|
- const filledCups = tempCupsComp.getFilledCups();
|
|
|
-
|
|
|
- for (const tempCup of filledCups) {
|
|
|
- const originalPos = tempCup.node.position.clone();
|
|
|
- const colors = tempCup.getColors();
|
|
|
- let hasProcessed = false; // 标记是否有处理过颜色
|
|
|
-
|
|
|
- for (const color of colors) {
|
|
|
- const targetCup = this.findTargetCupInOutArea(color);
|
|
|
- if (!targetCup) {
|
|
|
- console.log(`颜色${WaterColors[color]}未找到可用调酒杯`);
|
|
|
- continue;
|
|
|
+ if (this.isPouring) return;
|
|
|
+ this.isPouring = true;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const tempCupsComp = this.tempCups.getComponent(TempCups)!;
|
|
|
+ const filledCups = tempCupsComp.getFilledCups();
|
|
|
+
|
|
|
+ for (const tempCup of filledCups) {
|
|
|
+ const originalPos = tempCup.node.position.clone();
|
|
|
+ const colors = tempCup.getColors();
|
|
|
+ let hasProcessed = false; // 标记是否有处理过颜色
|
|
|
+
|
|
|
+ for (const color of colors) {
|
|
|
+ const targetCup = this.findTargetCupInOutArea(color);
|
|
|
+ if (!targetCup) {
|
|
|
+ console.log(`颜色${WaterColors[color]}未找到可用调酒杯`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ await this.pourAnimation(
|
|
|
+ tempCup.node,
|
|
|
+ targetCup.node,
|
|
|
+ color,
|
|
|
+ originalPos,
|
|
|
+ true
|
|
|
+ );
|
|
|
+
|
|
|
+ const cocktailCup = targetCup.comp;
|
|
|
+ await cocktailCup.addLayer(color);
|
|
|
+ hasProcessed = true; // 标记已处理
|
|
|
+ }
|
|
|
+ // 仅当有处理过颜色时才重置暂存杯
|
|
|
+ if (hasProcessed) {
|
|
|
+ tempCup.reset();
|
|
|
}
|
|
|
-
|
|
|
- await this.pourAnimation(
|
|
|
- tempCup.node,
|
|
|
- targetCup.node,
|
|
|
- color,
|
|
|
- originalPos,
|
|
|
- true
|
|
|
- );
|
|
|
-
|
|
|
- const cocktailCup = targetCup.comp;
|
|
|
- await cocktailCup.addLayer(color);
|
|
|
- hasProcessed = true; // 标记已处理
|
|
|
- }
|
|
|
- // 仅当有处理过颜色时才重置暂存杯
|
|
|
- if (hasProcessed) {
|
|
|
- tempCup.reset();
|
|
|
}
|
|
|
+ } finally {
|
|
|
+ this.isPouring = false;
|
|
|
}
|
|
|
}
|
|
|
|