LayerCatAction.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { _decorator, Component, Node } from 'cc';
  2. import { CatAction } from './CatAction';
  3. import { PinAction } from './PinAction';
  4. import { ColorDate } from './ColorDate';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('LayerCatAction')
  7. export class LayerCatAction extends Component {
  8. onLoad(): void {
  9. }
  10. start() {
  11. }
  12. update(deltaTime: number) {
  13. }
  14. //put a pin to slot by pin_color
  15. public put_pin(pin:PinAction):boolean{
  16. let can_move_arr:CatAction[] = [];
  17. this.node.children.forEach(slot => {
  18. if(slot.getComponent(CatAction).check_able_put(pin)){
  19. can_move_arr.push(slot.getComponent(CatAction));
  20. }
  21. });
  22. let target:CatAction = null;
  23. can_move_arr.forEach(element => {
  24. if(!target){
  25. target = element;
  26. }else{
  27. if(element.get_temp_hole_num()<target.get_temp_hole_num()){
  28. target = element;
  29. }
  30. }
  31. });
  32. if(target){
  33. return target.put_pin(pin,"LayerSolot");
  34. }
  35. return false;
  36. }
  37. public init_cat(){
  38. this.node.children.forEach(slot => {
  39. slot.getComponent(CatAction)?.init_cat();
  40. // slot.getComponent(CatAction)?.into_scence();
  41. });
  42. }
  43. public get_cat_color_arr(){
  44. let arr:ColorDate[] = [];
  45. this.node.children.forEach(slot => {
  46. if(slot.getComponent(CatAction)){
  47. let color = slot.getComponent(CatAction).get_cat_color();
  48. if(color){
  49. arr.push(color);
  50. }
  51. }
  52. });
  53. return arr;
  54. }
  55. }