import { Label, ShapeCircle, ShapeRect } from "./Unit";

export class Letter{
    data;

    images;

    bgColor;

    scaleX = 1;

    scaleY = 1;

    bg : ShapeRect;

    init(images, data, bgColor, scaleX = 1, scaleY = 1) {

        this.images = images;

        this.data = data;

        this.bgColor = bgColor;

        this.scaleX = scaleX;

        this.scaleY = scaleY;

        this.initBg();

        let letter = this.initView();

        let w = letter.getBoundingBox().width;
        let h = letter.getBoundingBox().height;

        this.bg.setSize(w, h);
        letter.x = w / 2;
        letter.y = h / 2;
    }

    initBg(){

        let bg = new ShapeRect();
        bg.alpha = 0;
        bg.fillColor = this.bgColor;

        this.bg = bg;

    }

    initView(){
        const letter = new Label();
        letter.text = this.data.val;
        letter.textAlign = 'center';
        letter.fontSize = 36;
        letter.fontName = "GOTHICB";
        letter.fontColor = "#fdcf00";
        letter.setScaleXY(this.scaleX);
        letter.refreshSize();
        this.bg.addChild(letter);
        return letter;
    }
}