#include "EditorSubsystem.hpp"

#include "BehaviourScriptRegistry.hpp"
#include "BehaviourScripts/AudioListener.hpp"
#include "BehaviourScripts/AudioSource.hpp"
#include "BehaviourScripts/basicEditorCamera.hpp"

TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("")
{
    rt = IRenderTexture::factory->CreateTextureHeap({100,100}, 5);
    sv = SceneView(rt);

    controller.AddGuiElement("Scene", &sv);
    controller.AddGuiElement("Consol", &cv);
    controller.AddGuiElement("Hirearchie", &hv);
    controller.AddGuiElement("Properties", &pv);
    controller.AddGuiElement("Debug", &dv);
    controller.AddGuiElement("Camera", &camv);

    BehaviourScriptRegistry::RegisterBehaviourScript("Image", []() -> BehaviourScript* {return new Image();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Image Animation", []() -> BehaviourScript* {return new ImageAnimation();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Mesh Container", []() -> BehaviourScript* {return new MeshContainer();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Rect Base", []() -> BehaviourScript* {return new RectBase();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Renderable", []() -> BehaviourScript* {return new Renderable();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Particle System", []() -> BehaviourScript* {return new ParticleSystem();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Camera", []() -> BehaviourScript* {return new Camera();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Audio Listener", []() -> BehaviourScript* {return new AudioListener();});
    BehaviourScriptRegistry::RegisterBehaviourScript("Audio Source", []() -> BehaviourScript* {return new AudioSource();});

    #pragma region camerastuff

    Transformable* editorCamera = new Transformable(".EditorCamera");

    Camera* editorCam = new Camera();
    editorCam->SetRenderTarget(rt);
    editorCamera->AddBehaviourScript(editorCam);

    basicEditorCamera* controls = new basicEditorCamera();
    editorCamera->AddBehaviourScript(controls);

    editorLayer = Layer(".editor");
    editorLayer.AddTransformable(editorCamera);
    editorLayer.SetNonVisual(true);

    #pragma endregion
}