#include <Block/SpriteBlock/BasicBlock/BasicBlock.hpp>
#include <TextureVoxelizer/TextureVoxelizer.hpp>

BasicBlock::BasicBlock(
    std::string name,
    std::string displayName,
    float hardness,
    std::string textureName,
    BoundingBox<int> bounds
) :
    SpriteBlock(
        name,
        displayName,
        hardness,
        textureName,
        {
            {
                {textureName, textureName, textureName, textureName, textureName, textureName},
                {bounds},
                "default"
            },
        }
    ),
    allowManualDigging(false)
{
    withBreakingSound(Sound::rockBreak);
}

BasicBlock::BasicBlock(
    std::string name,
    std::string displayName,
    float hardness,
    std::array<std::string, 6> sideTextureNames,
    BoundingBox<int> bounds,
    std::string iconName
) :
    SpriteBlock(
        name,
        displayName,
        hardness,
        iconName.empty() ? sideTextureNames[2] : iconName,
        {
            {
                sideTextureNames,
                {bounds},
                "default"
            },
        }
    ),
    allowManualDigging(false)
{
    withBreakingSound(Sound::rockBreak);
}

BasicBlock& BasicBlock::digManually(Sound &sound)
{
    allowManualDigging = true;
    manualDigSound = &sound;
    return *this;
}

BasicBlock& BasicBlock::withFallbackScript(std::string name)
{
    fallbackScriptName = name;
    return *this;
}

bool BasicBlock::canManuallyDig()
{
    return allowManualDigging;
}

Sound& BasicBlock::getManualDiggingSound()
{
    if (!allowManualDigging)
    {
        return Sound::NONE;
    }

    return *manualDigSound;
}

void BasicBlock::onDesignerInitializing(BlockSpriteDesigner &designer, ScriptEngine &engine)
{
    if (!fallbackScriptName.empty())
    {
        designer.useFallbackScript(fallbackScriptName);
    }
}