// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#include <IAEngine/Engine.hpp>
#include <WorldManager.hpp>

namespace ia::iae
{
    RefPtr<Scene> WorldManager::s_activeScene{};

    VOID WorldManager::Initialize()
    {
        s_activeScene = Scene::Create();
    }

    VOID WorldManager::Terminate()
    {
        s_activeScene.reset();
    }

    VOID WorldManager::Draw()
    {
        s_activeScene->Draw();
    }

    VOID WorldManager::DebugDraw()
    {
        s_activeScene->DebugDraw();
    }

    VOID WorldManager::Update()
    {
        s_activeScene->Update();
    }

    VOID WorldManager::FixedUpdate()
    {
        s_activeScene->FixedUpdate();
    }

    VOID WorldManager::ChangeActiveScene(IN RefPtr<Scene> scene)
    {
        s_activeScene = scene;
    }

    VOID WorldManager::AddNodeToActiveScene(IN RefPtr<INode> node)
    {
        s_activeScene->AddNode(node);
    }

    INode *WorldManager::GetNodeFromActiveScene(IN CONST String &name)
    {
        return s_activeScene->GetNode(name);
    }

    VOID WorldManager::RemoveNodeFromActiveScene(IN CONST String &name)
    {
        s_activeScene->RemoveNode(name);
    }

    Scene *WorldManager::GetActiveScene()
    {
        return s_activeScene.get();
    }
} // namespace ia::iae

namespace ia::iae
{
    Scene *Engine::GetActiveScene()
    {
        return WorldManager::GetActiveScene();
    }
    
    VOID Engine::ChangeActiveScene(IN RefPtr<Scene> scene)
    {
        WorldManager::ChangeActiveScene(scene);
    }

    VOID Engine::AddNodeToActiveScene(IN RefPtr<INode> node)
    {
        WorldManager::AddNodeToActiveScene(node);
    }

    INode *Engine::GetNodeFromActiveScene(IN CONST String &name)
    {
        return WorldManager::GetNodeFromActiveScene(name);
    }

    VOID Engine::RemoveNodeFromActiveScene(IN CONST String &name)
    {
        WorldManager::RemoveNodeFromActiveScene(name);
    }
} // namespace ia::iae