//
// Created by sasha on 28.11.2025.
//

#include "cube.h"

#include "engine/engine.h"

Cube::Cube(IWidget *parent,float x, float y, const std::string &type,int number) : IWidget (parent,x,y,92,92){
    this->cube_number=number;

    size_cube = 92;
    filename = "cube_green.png";
    text_size = 40;
    text_left = 36.5;
    text_top = 22;


    if (type=="normal"){
        size_cube = 67;
        filename = "cube_blue.png";
        text_size = 33;
        text_left = 26;
        text_top = 14;
    }
    if (type=="hard"){
        size_cube = 52;
        filename = "cube_red.png";
        text_size = 22;
        text_left = 20.5;
        text_top = 12.5;
    }

    setSize(size_cube,size_cube);

    image = new Image(this,x,y,size_cube,size_cube,filename);
    text_number = new Text(this,image->getFRect().x+text_left,image->getFRect().y+text_top);
    text_number->setText(std::to_string(number),"inter.ttf",text_size,{255,255,255});
}

Cube::~Cube() {
    delete image;
    delete text_number;
}

void Cube::setBoardPosition(int x, int y) {
    boardPosition = {x,y};
}

SDL_Point Cube::getBoardPosition() {
    return boardPosition;
}

int Cube::getNumber() {
    return cube_number;
}

void Cube::move(float x, float y){
    this->x=x;
    this->y=y;

    image->move(x,y);
    text_number->move(image->getFRect().x+(image->getFRect().w-text_number->getFRect().w)/2,image->getFRect().y+text_top);
}
