LayerCatAction.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  15. * put a pin to slot by pin_color
  16. * @param pin
  17. * @returns
  18. */
  19. public put_pin(pin: PinAction): boolean {
  20. let can_move_arr: CatAction[] = [];
  21. this.node.children.forEach(slot => {
  22. if (slot.getComponent(CatAction).check_able_put(pin)) {
  23. can_move_arr.push(slot.getComponent(CatAction));
  24. }
  25. });
  26. let target: CatAction = null;
  27. can_move_arr.forEach(element => {
  28. if (!target) {
  29. target = element;
  30. } else {
  31. if (element.get_temp_hole_num() < target.get_temp_hole_num()) {
  32. target = element;
  33. }
  34. }
  35. });
  36. if (target) {
  37. return target.put_pin(pin, "LayerSolot");
  38. }
  39. return false;
  40. }
  41. /**
  42. *
  43. */
  44. public init_cat() {
  45. this.node.children.forEach(slot => {
  46. slot.getComponent(CatAction)?.init_cat();
  47. // slot.getComponent(CatAction)?.into_scence();
  48. });
  49. }
  50. /**
  51. *
  52. * @returns
  53. */
  54. public get_cat_color_arr() {
  55. let arr: ColorDate[] = [];
  56. this.node.children.forEach(slot => {
  57. if (slot.getComponent(CatAction)) {
  58. let color = slot.getComponent(CatAction).get_cat_color();
  59. if (color) {
  60. arr.push(color);
  61. }
  62. }
  63. });
  64. return arr;
  65. }
  66. }