const { ccclass, property } = cc._decorator;

/**
 * 图片限制尺寸
 * @author chenkai 2021.6.24
 */
@ccclass
export default class OPW_BoardGame_L5R4_ImgFixedSize extends cc.Component {

    @property({ type: cc.Integer, tooltip: "固定尺寸" })
    fixedSize: number = 0;

    onLoad() {
        this.node.on(cc.Node.EventType.SIZE_CHANGED, this.onSizeChanged, this);
        this.onSizeChanged();
    }

    /**当尺寸变化时，重置node节点大小 */
    onSizeChanged() {
        var width = this.node.width;
        var height = this.node.height;
        var max = Math.max(width, height);
        this.node.scale = this.fixedSize / max;
    }
}