#include <Block/SpriteBlock/BlockBreaker/BlockBreaker.hpp>
#include <Block/SpriteBlock/SpriteBlock.hpp>
#include <BoundingBox/BoundingBox.hpp>
#include <Side/Side.hpp>
#include <Utilities/Utilities.hpp>
#include <Entity/PhysicsEntity/CameraEntity/Player/Player.hpp>
#include <World/LocalWorld/LocalWorld.hpp>

const std::vector<std::string>& BlockBreaker::getStateNames()
{
    static std::vector<std::string> stateNames;

    if (stateNames.empty())
    {
        for (uint8_t meta = 0; meta < numStates; meta++)
        {
            const char *activeFlag = (meta & metaActive) ? "active" : "inactive";
            Side orientation = getMetaOrientation(meta);
            int frameOffset = getMetaFrameOffset(meta);

            stateNames.push_back(formatString("$+$+$+", activeFlag, orientation.name(), frameOffset));
        }
    }

    return stateNames;
}

BlockBreaker::BlockBreaker(std::string name) : SpriteBlock(
    name,
    "Block Breaker",
    60.0f,
    getStateNames()
)
{
    withMetalSounds();
}

bool BlockBreaker::canManuallyDig()
{
    return true;
}

void BlockBreaker::onInteract(LocalWorld &world, Player &player, glm::ivec3 pos, Side side, const RGBABytes &collisionKey)
{
    // TODO
}

bool BlockBreaker::canPlace(LocalWorld &world, IWorldActor &actor, glm::ivec3 pos, Side side, uint8_t &meta)
{
    meta = actor.getSideFacing2D().asNumber();
    return true;
}
