import Sprite3D = Laya.Sprite3D;
export default class ConstructManager {
    // private static instance: ConstructManager;
    // public static get Instance(): ConstructManager {
    //     return this.instance || (this.instance = new ConstructManager());
    // }
    // private tarDis = 30;
    // private buildArr = [];
    // public Init(builds: Sprite3D) {
    //     this.buildArr.push(builds.getChildAt(2));
    //     this.buildArr.push(builds.getChildAt(1));
    //     this.buildArr.push(builds.getChildAt(0));
    // }

    // public SetBuild() {
    //     for (let index = this.buildArr.length - 1; index >= 0; index--) {
    //         const element = this.buildArr[index] as Sprite3D;
    //         element.transform.localPositionZ = (2 - index) * 30;
    //     }
    //     this.tarDis = 30;
    // }

    // public CheckPlayerRoadPos(_zp: number) {
    //     let d = this.tarDis - _zp;
    //     if (d > 0) return;
    //     this.SwitchRoad();
    // }
    // private SwitchRoad() {
    //     let rs = this.buildArr.pop();
    //     rs.transform.localPositionZ = this.tarDis + 60;
    //     this.buildArr.unshift(rs);
    //     this.tarDis = this.tarDis + 30;
    // }
    private static instance: ConstructManager;
    public static get Instance(): ConstructManager {
        return this.instance || (this.instance = new ConstructManager());
    }
    private tarDis = 100;
    private buildArr = [];
    public Init(builds: Sprite3D) {
        this.buildArr.push(builds.getChildAt(1));
        this.buildArr.push(builds.getChildAt(0));
        //this.buildArr.push(builds.getChildAt(0));
    }

    public SetBuild() {
        // this.tarDis = 100;
        // for (let index = 0; index < this.buildArr.length; index++) {
        //     const element = this.buildArr[index] as Sprite3D;
        //     element.transform.localPositionZ = index * 100;
        // }

        for (let index = this.buildArr.length - 1; index >= 0; index--) {
            const element = this.buildArr[index] as Sprite3D;
            element.transform.localPositionZ = (1-index) * 100;
        }
        this.tarDis = 70;
    }

    public CheckPlayerRoadPos(_zp: number) {
        let d = this.tarDis - _zp;
        if (d > 0) return;
        this.SwitchRoad();
    }
    private SwitchRoad() {
        let rs = this.buildArr.pop();
        rs.transform.localPositionZ = this.tarDis+30 + 100;
        this.buildArr.unshift(rs);
        this.tarDis = this.tarDis + 100;
    }
}