/******************************************************************************
*	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 <vector>
#include <map>
#include <core/types.h>
#include <utils/opRes.h>
#include <utils/grid.h>

namespace lunarium
{
    class Graphics;
    class Image;
    class Script;
}

namespace lunarium { namespace game 
{
    class Camera;
    class GameObject;

    class World
    {
    public:
        struct Region
        {
            lunarium::Script* mRegionScript;
            Vec2i mCoords;
            std::vector<GameObject*> mObjects;
            std::vector<lunarium::Image*> mLayers;
        };

    public:     // INTERFACE

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

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

        // Game objects should probably be added/removed from the regions directly
        // No World-wide game objects
        // Unless I can think of a good reason why they would be useful
        // void AddGameObject(GameObject* pObj);
        // bool RemoveGameObject(GameObject* pObj);

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

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


    private:
        Camera* mpCamera;
        std::vector<GameObject*> mWorldObjects;
        lunarium::Script* mpWorldScript; 
        Sizei mRegionSize;      // in pixels
        Sizei mWorldSize;       // num regions ex. 10x10
        Grid<Region*> mRegions;
        Vec2i mActiveRegion;
        

    };
}}

#endif  // WORLD_H_