| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { _decorator, v3, Vec3, Node, Label } from 'cc';
- import { PInfo } from '../../util/JsonModel/StageModel';
- import { BoardState, ContainerState, EventType } from '../../util/Enum';
- import { ContainerView } from './ContainerView';
- const { ccclass, property } = _decorator;
- export interface evt {
- 'reflashView': () => void;
- 'stateChange': () => void;
- 'colorEliminated': (color: number) => void;
- }
- export interface KnittPathGroup {
- path: number[];
- groupIndex: number;
- }
- export class Container {
- pos: Vec3; // 位置
- o_pos: Vec3; // 初始位置
- view: Node;
- pathGroups: KnittPathGroup[] = [];
- private _evt = chsdk.get_new_event<evt>();
- get evt() {
- return this._evt;
- }
- init() {}
- /**
- * 设置路径配置
- * @param config 路径配置字符串,格式如 "0,1,2;3,4,5" 表示两个路径组
- */
- setPathConfig(config: string) {
- // 解析配置字符串
- const pathGroups = config.split(';').filter(group => group.length > 0);
- this.pathGroups = pathGroups.map((pathGroup, groupIndex) => {
- const cellIndices = pathGroup.split(',').map(index => parseInt(index.trim()));
- return {
- path: cellIndices,
- groupIndex: groupIndex
- };
- });
- }
- private _state: ContainerState;
- set state(state: ContainerState) {
- // 完结之后不能赋值
- if (this._state == ContainerState.finish) {
- return;
- }
- this._state = state;
- this.evt.emit('stateChange');
- }
- get state() {
- return this._state;
- }
- }
|