/******************************************************************************
*	File		-	world.h
*	Author		-	Joey Pollack
*	Date		-	2022/01/12 (y/m/d)
*	Mod Date	-	2022/01/20 (y/m/d)
*	Description	-	Manages a game "world". A world is made up of regions which
*                   are subdivisions of the world. Each region contains: a set 
*                   of images for the maps layers, a list of objects that spawn
*                   in this region and static collision data.
******************************************************************************/

#ifndef WORLD_H_
#define WORLD_H_

#include <core/common_defs.h>
#include <core/types.h>
#include <utils/op_res.h>
#include <entt/entt.hpp>

#include <vector>
#include <map>

namespace lunarium
{
    class Graphics;
    class Image;
    class Script;
    //class Camera;
    //class GameObject;
    class Entity;
}

namespace lunarium 
{
    class World
    {
    public:
        struct Region
        {
            bool IsActive;
            lunarium::Script* RegionScript;
            Vec2i Coords;
            std::vector<Entity*> Entities;
            std::vector<lunarium::Image*> mLayers;
        };

    public:     // INTERFACE

        //World(Camera* pCam, Sizei region_size, Sizei world_size);
        World();

        void OnLoad();
        void OnUnload();
        void Update(float dt);
        void Render(Graphics* pGraphics) const;
        void RenderToTexture(Graphics* pGraphics, Image* pTexture) const;

        OpRes SetRegion(Region* region, Vec2i at);
        Region* GetRegion(Vec2i at);
        bool RemoveRegion(Vec2i at);

        void SetWorldScript(Script* pScript);
        lunarium::Script* GetWorldScript();

        entt::registry* GetEntityRegistry();
        LUUID CreateEntity();
        Entity* GetEntity(LUUID id);


    private:
        entt::registry mECSRegistry;
        //Camera* mpCamera;
        //std::vector<GameObject*> mWorldObjects;
        lunarium::Script* mpWorldScript; 
        Sizei mRegionSize;      // in tiles
        Sizei mWorldSize;       // num regions ex. 10x10
        Vec2i mActiveRegion;


        // TEST STUFF
        std::map<LUUID, Entity*> mEntities;
        

    };
}

#endif  // WORLD_H_