/*
文件名:BaseObject.nut
路径:User/Object/Object/BaseObject.nut
创建日期:2024-11-29	10:32
文件用途:
*/
class BaseObject extends Actor {

    //方向
    Direction = 1;

    //坐标
    X = 0;
    Y = 0;
    Z = 0;

    constructor(...) {
        local C_Object;
        if (vargv.len() == 0) {
            C_Object = BaseObject_Create();
        } else {
            C_Object = vargv[0];
        }
        base.constructor(C_Object);
        //锚点居中
        SetAnchor(0.5, 0.5);
    }


    function SetPositionNoLayer(Value, ...) {
        if (vargv.len() == 0) {
            X = Value.x;
            Y = Value.y;
            Z = Value.z;
            Value.y = Value.y - Value.z;
            base.SetPosition(Value);
        } else if (vargv.len() == 2) {
            X = Value;
            Y = vargv[0];
            Z = vargv[1];
            base.SetPosition(Value, vargv[0] - vargv[1]);
        }
    }

    //override
    function SetPosition(Value, ...) {
        if (vargv.len() == 0) {
            X = Value.x;
            Y = Value.y;
            Z = Value.z;
            Value.y = Value.y - Value.z;
            base.SetPosition(Value);
        } else if (vargv.len() == 2) {
            X = Value;
            Y = vargv[0];
            Z = vargv[1];
            base.SetPosition(Value, vargv[0] - vargv[1]);
        }
        SetZOrder(Y);
    }

    //传入坐标 xyz 的table  或者 单独传 xyz
    function MoveTo(Value, ...) {
        if (vargv.len() == 0) {
            X = Value.x;
            Y = Value.y;
            Z = Value.z;
            Value.y = Value.y - Value.z;
            base.MoveTo(Value);
        } else if (vargv.len() == 2) {
            X = Value;
            Y = vargv[0];
            Z = vargv[1];
            base.MoveTo(Value, vargv[0] - vargv[1]);
        }


    }

    //传入坐标 xyz 的table  或者 单独传 xyz
    function MoveBy(Value, ...) {
        if (vargv.len() == 0) {
            X += Value.x;
            Y += Value.y;
            Z += Value.z;
            Value.y = Value.y - Value.z;
            base.MoveBy(Value);
        } else if (vargv.len() == 2) {
            X += Value;
            Y += vargv[0];
            Z += vargv[1];
            base.MoveBy(Value, vargv[0] - vargv[1]);
        }
    }

    //设置方向
    function SetDirection(D) {
        if (D == DIRECTION.RIGHT) {
            SetScale(fabs(GetScale().x), GetScale().y);
        } else if (D == DIRECTION.LEFT) {
            SetScale(-fabs(GetScale().x), GetScale().y);
        }
        Direction = D;
    }

    //销毁自身
    function DestroySelf() {
        RemoveSelf();
    }
}