#include "Generated.h"

namespace Generated
{
    bool Save(const PuzzleElementType::Enum* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            auto val = (int32_t)obj[i];
            isOk = Save(&val, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const PuzPos* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(&obj[i].X, 1, serializer) && isOk;
            isOk = Save(&obj[i].Y, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const ElemPos* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(&obj[i].Position, 1, serializer) && isOk;
            isOk = Save(&obj[i].ElemIdx, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const PuzzleNode* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(obj[i].PlacedTypes, 4, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const StaticPuzzleCard* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(obj[i].Nodes, 4, serializer) && isOk;
            isOk = Save(&obj[i].ModelHandle, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const StaticPuzzleCardHandle* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(&obj[i].Idx, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const StaticPuzzleData* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(obj[i].Cards, 64, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const PuzzleCardStack* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(&obj[i].RefCard, 1, serializer) && isOk;
            isOk = Save(&obj[i].MaxAvailableCount, 1, serializer) && isOk;
            isOk = Save(&obj[i].UsedCount, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const PlacedPuzzleCard* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(&obj[i].RefCard, 1, serializer) && isOk;
            isOk = Save(&obj[i].Position, 1, serializer) && isOk;
            isOk = Save(&obj[i].Rotation, 1, serializer) && isOk;
            isOk = Save(&obj[i].IsLocked, 1, serializer) && isOk;
        }
        return isOk;
    }
    bool Save(const PuzzleData* obj, uint32_t count, Serializer& serializer)
    {
        bool isOk = true;
        for (uint32_t i = 0; i < count; ++i)
        {
            isOk = Save(&obj[i].WidthTiles, 1, serializer) && isOk;
            isOk = Save(&obj[i].HeightTiles, 1, serializer) && isOk;
            isOk = Save(&obj[i].AvailableCardCount, 1, serializer) && isOk;
            isOk = Save(obj[i].AvailableCards, 16, serializer) && isOk;
            isOk = Save(&obj[i].PlacedCardCount, 1, serializer) && isOk;
            isOk = Save(obj[i].PlacedCards, 256, serializer) && isOk;
            isOk = Save(obj[i].PlacedNodes, 1024, serializer) && isOk;
            isOk = Save(&obj[i].GoalPositionCount, 1, serializer) && isOk;
            isOk = Save(obj[i].GoalPositions, 16, serializer) && isOk;
            isOk = Save(obj[i].PuzzleName, 64, serializer) && isOk;
        }
        return isOk;
    }
}
