import pg from "../../scene/tool/pg";
import BezierRender from "./bezier-render";
import VerletRender from "./verlet-render";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Page extends cc.Component {
    @property({ type: cc.Node, displayName: "图片节点" })
    public page: cc.Node = null

    @property({ type: BezierRender, displayName: "贝塞尔曲线" })
    public bezierRender: BezierRender = null

    // @property({ type: VerletRender, displayName: "Verlet积分算法" })
    // public verletRender: VerletRender = null

    onLoad() {
        pg.event.on("page_to_left", (page) => {
            (this.node.data.page == page) && this.pageToLeft();
        })
        pg.event.on("page_to_right", (page) => {
            (this.node.data.page == page) && this.pageToRight();
        })
    }
    pageToLeft() {
        let angle = 0;
        let inter = setInterval(() => {
            angle += 15;
            if (angle > 180) {
                angle = 180;
                clearInterval(inter);
            }
            this.bezierRender.updateAngle(angle)
        }, 30)
    }
    pageToRight() {
        let angle = 180;
        let inter = setInterval(() => {
            angle -= 15;
            if (angle < 0) {
                angle = 0;
                clearInterval(inter);
            }
            this.bezierRender.updateAngle(angle)
        }, 30)
    }
}
