import { Vec3, Node, MeshRenderer, RenderableComponent, Color } from "cc";
import { ViewUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/ViewUtil";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { VehicleModelComp } from "./model/VehicleModelComp";
import { VehicleViewComp } from "./view/VehicleViewComp";
import { VehicleSitSystem } from "./bll/VehicleCheck";
import { VehicleType } from "./model/VehicleEnum";

/**
 * 车辆实体
 * 1、生成车辆关卡初始数据
 */
@ecs.register('Vehicle')
export class Vehicle extends ecs.Entity {


    VehicleModel!: VehicleModelComp;

    VehicleView!: VehicleViewComp;

    protected init() {
        // 添加关卡数据组件
        this.addComponents<ecs.Comp>(VehicleModelComp);
    }

    destroy(): void {
        // 如果该组件对象是由ecs系统外部创建的，则不可回收，需要用户自己手动进行回收。
        this.remove(VehicleViewComp);
        super.destroy();
    }

    /** 加载车辆显示对象（cc.Component在创建后，添加到ECS框架中，使实体上任何一个ECS组件都可以通过 ECS API 获取到视图层对象 */
    load(parent: Node, color: string, pos: Vec3 = Vec3.ZERO,type=VehicleType.BUS) {
        const node = ViewUtil.createPrefabNode(this.getVehicleModelPath(type));
        var mv = node.getComponent(VehicleViewComp)!;
        this.add(mv);
        this.VehicleView.changeColor(color)
        node.parent = parent;
        node.setPosition(pos);
    }

    getVehicleModelPath(type:VehicleType){
        switch (type) {
            case VehicleType.CAR:
                return 'game/prefab/car2'
            case VehicleType.BUS:
                return 'game/prefab/car1'
            case VehicleType.AIRPLANT:
                return 'game/prefab/airplane'
            default:
                return 'game/prefab/car1'
        }
    }
}

export class EcsVehicleSystem extends ecs.System {
    constructor() {
        super();

        // this.add(new VehicleSitSystem());

    }
}