| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import { Vec3 } from "cc";
- import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
- import { ECSEntity } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECSEntity";
- import { VM } from "../../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
- import { Grid } from "../../grid/Grid";
- import { Obstacle } from "../../obstacle/Obstacle";
- import { Puppet } from "../../puppet/puppet";
- import { Station } from "../../station/Station";
- import { Vehicle } from "../../vehicle/Vehicle";
- import { Subway } from "../../subway/Subway";
- type Cell = Puppet | Obstacle | Subway
- export interface MapInfo {
- x: number,
- y: number,
- fill?: string | number
- pos: Vec3
- }
- @ecs.register('CheckpointModel')
- export class CheckpointModelComp extends ecs.Comp {
- private vm: any = {};
- private _grid: Grid[][] = []
- private _path_grid: MapInfo[][] = []
- private _cells: Cell[][] = []
- private _station: Station[] = []
- private _vehicles: Vehicle[] = []
- private _curVehicle: Vehicle = null
- private _nextVehicle: Vehicle = null
- private _peopleCount:number = 0
- get peopleCount(): number {
- return this._peopleCount
- }
- set peopleCount(_v: number) {
- this.vm.peopleCount = _v
- this._peopleCount = _v
- }
- get curVehicle(): Vehicle {
- return this._curVehicle
- }
- set curVehicle(_v: Vehicle) {
- this._curVehicle = _v
- }
- get nextVehicle(): Vehicle {
- return this._nextVehicle
- }
- set nextVehicle(_v: Vehicle) {
- this._nextVehicle = _v
- }
- /** 格子 */
- get grids(): Grid[][] {
- return this._grid;
- }
- set grids(value: Grid[][]) {
- this._grid = value;
- }
- /** 寻路数据 */
- get path_grid(): MapInfo[][] {
- return this._path_grid;
- }
- set path_grid(value: MapInfo[][]) {
- this._path_grid = value;
- }
- /** 站台 */
- get stations(): Station[] {
- return this._station;
- }
- set stations(value: Station[]) {
- this._station = value;
- }
- /** 车辆 */
- get vehicles(): Vehicle[] {
- return this._vehicles;
- }
- set vehicles(value: Vehicle[]) {
- this._vehicles = value;
- }
- /** 棋盘格中物体 */
- get cells(): Cell[][] {
- return this._cells;
- }
- set cells(value: Cell[][]) {
- this._cells = value;
- }
- get emptyStation(): Station {
- return this._station.find(val => val.StationModel.isEmpty && !val.StationModel.isLock)
- }
- get emptyStationCount(): number {
- return this._station.filter(val => val.StationModel.isEmpty && !val.StationModel.isLock).length
- }
- get puppets(): Puppet[] {
- const flatArr = this.flattenArray(this.cells)
- return flatArr.filter(val => val instanceof Puppet && val.PuppetModel)
- }
- // get canReachPuppets(): Puppet[] {
- // return this.puppets.filter(val => val.PathFind?.canReach===true)
- // }
- get subways(): Subway[] {
- const flatArr = this.flattenArray(this.cells)
- return flatArr.filter(val => val instanceof Subway && val.SubwayModel)
- }
- flattenArray(arr) {
- const result = [];
- arr.forEach((item) => {
- if (Array.isArray(item)) {
- result.push(...this.flattenArray(item)); // 如果是数组,则递归调用
- } else {
- result.push(item); // 否则直接加入到结果数组中
- }
- });
- return result;
- }
- vmAdd() {
- VM.add(this.vm, "Checkpoint");
- }
- vmRemove() {
- VM.remove("Checkpoint");
- }
- reset() {
- this.grids = []
- this.path_grid = []
- this.cells = []
- this.stations = []
- this.vehicles = []
- this.curVehicle = null
- this.peopleCount = 0
- this.vmRemove();
- }
- }
|