/******************************************************************************
*	File		-	tile_set.h
*	Author		-	Joey Pollack
*	Date		-	2022/02/16 (y/m/d)
*	Mod Date	-	2022/02/16 (y/m/d)
*	Description	-	Manage a tile set for map making
******************************************************************************/

#ifndef TILE_SET_H_
#define TILE_SET_H_

#include "editor_asset.h"
#include <core/types.h>
#include <filesystem>

namespace lunarium { class Image; class IGraphics; }

namespace lunarium { namespace editor
{
    class TileSet : public EditorAsset
    {
    public:
        TileSet();

        // Load the raw asset file from the internal location
        OpRes LoadRawFile();
        OpRes LoadFromJSON(nlohmann::json& node);
        OpRes SaveToJSON(nlohmann::json& node);

        void SetTileSetID(int id);
        int GetTileSetID() const;
        
        void SetImage(Image* image);
        void SetTileSize(Sizei size);

        Image* GetImage();
        Sizei GetTileSize();
        Rectangle GetTileRect(Vec2i index);

        void Render(lunarium::IGraphics* g);

    private:
        Image* mSetImage;
        Sizei mTileSize;         // in pixels, must be a square power of 2
        Sizei mNumTiles;
        int mTileSetID;


    private:
        [[nodiscord]] virtual bool IsValidNode(nlohmann::json& node);

    };
}}

#endif  // TILE_SET_H_