Container.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { _decorator, v3, Vec3, Node, Label } from 'cc';
  2. import { PInfo } from '../../util/JsonModel/StageModel';
  3. import { BoardState, ContainerState, EventType } from '../../util/Enum';
  4. import { ContainerView } from './ContainerView';
  5. const { ccclass, property } = _decorator;
  6. export interface evt {
  7. 'reflashView': () => void;
  8. 'stateChange': () => void;
  9. 'colorEliminated': (color: number) => void;
  10. }
  11. export interface KnittPathGroup {
  12. path: number[];
  13. groupIndex: number;
  14. }
  15. export class Container {
  16. pos: Vec3; // 位置
  17. o_pos: Vec3; // 初始位置
  18. view: Node;
  19. pathGroups: KnittPathGroup[] = [];
  20. private _evt = chsdk.get_new_event<evt>();
  21. get evt() {
  22. return this._evt;
  23. }
  24. init() {}
  25. /**
  26. * 设置路径配置
  27. * @param config 路径配置字符串,格式如 "0,1,2;3,4,5" 表示两个路径组
  28. */
  29. setPathConfig(config: string) {
  30. // 解析配置字符串
  31. const pathGroups = config.split(';').filter(group => group.length > 0);
  32. this.pathGroups = pathGroups.map((pathGroup, groupIndex) => {
  33. const cellIndices = pathGroup.split(',').map(index => parseInt(index.trim()));
  34. return {
  35. path: cellIndices,
  36. groupIndex: groupIndex
  37. };
  38. });
  39. }
  40. private _state: ContainerState;
  41. set state(state: ContainerState) {
  42. // 完结之后不能赋值
  43. if (this._state == ContainerState.finish) {
  44. return;
  45. }
  46. this._state = state;
  47. this.evt.emit('stateChange');
  48. }
  49. get state() {
  50. return this._state;
  51. }
  52. }