project(editScene)
set(CMAKE_CXX_STANDARD 17)

find_package(OGRE REQUIRED COMPONENTS Bites Overlay MeshLodGenerator CONFIG)
find_package(flecs REQUIRED CONFIG)
find_package(nlohmann_json REQUIRED)
find_package(SDL2 REQUIRED)
find_package(Jolt REQUIRED)
find_package(OgreProcedural REQUIRED CONFIG)

# Build RecastNavigation from copied source (RTTI-compatible)
add_subdirectory(recastnavigation)

# Collect all source files
set(EDITSCENE_SOURCES
	main.cpp
	EditorApp.cpp
	systems/EditorUISystem.cpp
	systems/SceneSerializer.cpp
	systems/PhysicsSystem.cpp
	systems/BuoyancySystem.cpp
	systems/EditorSunSystem.cpp
	systems/EditorSkyboxSystem.cpp
	systems/EditorWaterPlaneSystem.cpp
	systems/LightSystem.cpp
	systems/CameraSystem.cpp
	systems/LodSystem.cpp
	systems/StaticGeometrySystem.cpp
	systems/ProceduralTextureSystem.cpp
	systems/ProceduralMaterialSystem.cpp
	systems/ProceduralMeshSystem.cpp
	systems/CellGridSystem.cpp
	systems/NormalDebugSystem.cpp
	systems/RoomLayoutSystem.cpp
	systems/FurnitureLibrary.cpp
	systems/StartupMenuSystem.cpp
	systems/PlayerControllerSystem.cpp
	systems/CharacterSlotSystem.cpp
	systems/AnimationTreeSystem.cpp
	systems/BehaviorTreeSystem.cpp
	systems/NavMeshSystem.cpp
	recast/TileCacheNavMesh.cpp
	recast/PartitionedMesh.cpp
	recast/fastlz.c
	systems/CharacterSystem.cpp
	systems/SmartObjectSystem.cpp
	components/SmartObjectModule.cpp
	ui/SmartObjectEditor.cpp

	ui/TransformEditor.cpp
	ui/RenderableEditor.cpp
	ui/PhysicsColliderEditor.cpp
	ui/RigidBodyEditor.cpp
	ui/LightEditor.cpp
	ui/CameraEditor.cpp
	ui/LodEditor.cpp
	ui/LodSettingsEditor.cpp
	ui/StaticGeometryEditor.cpp
	ui/StaticGeometryMemberEditor.cpp
	ui/ProceduralTextureEditor.cpp
	ui/ProceduralMaterialEditor.cpp
	ui/PrimitiveEditor.cpp
	ui/TriangleBufferEditor.cpp
	ui/CharacterSlotsEditor.cpp
	ui/AnimationTreeEditor.cpp
	ui/AnimationTreeTemplateEditor.cpp
	ui/CharacterEditor.cpp
	ui/CellGridEditor.cpp
	ui/LotEditor.cpp
	ui/DistrictEditor.cpp
	ui/TownEditor.cpp
	ui/RoofEditor.cpp
	ui/RoomEditor.cpp


	ui/ClearAreaEditor.cpp
	ui/FurnitureTemplateEditor.cpp
	ui/StartupMenuEditor.cpp
	ui/PlayerControllerEditor.cpp
	ui/BuoyancyInfoEditor.cpp
	ui/GoapBlackboardEditor.cpp
	ui/BehaviorTreeEditor.cpp
	ui/InlineBehaviorTreeEditor.cpp
	ui/NavMeshEditor.cpp
	ui/ActionDatabaseEditor.cpp
	ui/ActionDebugEditor.cpp
	ui/ComponentRegistration.cpp
	components/GoapBlackboard.cpp
	components/GoapExpression.cpp
	components/GoapGoal.cpp
	components/ActionDatabase.cpp
	components/ActionDatabaseModule.cpp
	components/ActionDebugModule.cpp
	components/GoapBlackboardModule.cpp
	components/NavMeshModule.cpp
	components/LightModule.cpp
	components/CameraModule.cpp
	components/LodModule.cpp
	components/StaticGeometryModule.cpp
	components/ProceduralTextureModule.cpp
	components/ProceduralMaterialModule.cpp
	components/PrimitiveModule.cpp
	components/TriangleBufferModule.cpp
	components/CharacterSlotsModule.cpp
	components/AnimationTreeModule.cpp
	components/AnimationTreeTemplateModule.cpp
	components/AnimationTree.cpp
	components/CharacterModule.cpp
	components/CellGridModule.cpp
	components/CellGridEditorsModule.cpp
	components/CellGrid.cpp
	components/StartupMenuModule.cpp
	components/PlayerControllerModule.cpp
	components/BuoyancyInfoModule.cpp
	components/WaterPhysicsModule.cpp
	components/WaterPlaneModule.cpp
	components/SunModule.cpp
	components/SkyboxModule.cpp
	camera/EditorCamera.cpp
	gizmo/Gizmo.cpp
	physics/physics.cpp
)

set(EDITSCENE_HEADERS
	EditorApp.hpp
	components/Transform.hpp
	components/Renderable.hpp
	components/EntityName.hpp
	components/Relationship.hpp
	components/PhysicsCollider.hpp
	components/RigidBody.hpp
	components/BuoyancyInfo.hpp
	components/WaterPhysics.hpp
	components/WaterPlane.hpp
	components/Sun.hpp
	components/Skybox.hpp
	components/Light.hpp
	components/Camera.hpp
	components/Lod.hpp
	components/LodSettings.hpp
	components/StaticGeometry.hpp
	components/StaticGeometryMember.hpp
	components/ProceduralTexture.hpp
	components/ProceduralMaterial.hpp
	components/Primitive.hpp
	components/TriangleBuffer.hpp
	components/CharacterSlots.hpp
	components/AnimationTree.hpp
	components/Character.hpp
	components/CellGrid.hpp
	components/StartupMenu.hpp
	components/PlayerController.hpp
	systems/StartupMenuSystem.hpp
	systems/PlayerControllerSystem.hpp
	systems/EditorUISystem.hpp
	systems/CellGridSystem.hpp
	systems/NormalDebugSystem.hpp
	systems/RoomLayoutSystem.hpp
	systems/FurnitureLibrary.hpp
	systems/ProceduralMaterialSystem.hpp
	systems/ProceduralMeshSystem.hpp
	systems/CharacterSlotSystem.hpp
	systems/AnimationTreeSystem.hpp
	systems/BehaviorTreeSystem.hpp
	systems/NavMeshSystem.hpp
	recast/TileCacheNavMesh.hpp
	recast/PartitionedMesh.hpp
	recast/fastlz.h
	systems/CharacterSystem.hpp
	systems/SmartObjectSystem.hpp
	components/SmartObject.hpp
	ui/SmartObjectEditor.hpp

	systems/ProceduralTextureSystem.hpp
	systems/StaticGeometrySystem.hpp
	systems/SceneSerializer.hpp
	systems/PhysicsSystem.hpp
	systems/BuoyancySystem.hpp
	systems/EditorSunSystem.hpp
	systems/EditorSkyboxSystem.hpp
	systems/EditorWaterPlaneSystem.hpp
	systems/LightSystem.hpp
	systems/CameraSystem.hpp
	systems/LodSystem.hpp
	ui/ComponentEditor.hpp
	ui/ComponentRegistry.hpp
	ui/ComponentRegistration.hpp
	ui/TransformEditor.hpp
	ui/RenderableEditor.hpp
	ui/PhysicsColliderEditor.hpp
	ui/RigidBodyEditor.hpp
	ui/LightEditor.hpp
	ui/CameraEditor.hpp
	ui/LodEditor.hpp
	ui/LodSettingsEditor.hpp
	ui/StaticGeometryEditor.hpp
	ui/StaticGeometryMemberEditor.hpp
	ui/ProceduralTextureEditor.hpp
	ui/ProceduralMaterialEditor.hpp
	ui/PrimitiveEditor.hpp
	ui/TriangleBufferEditor.hpp
	ui/CharacterSlotsEditor.hpp
	ui/AnimationTreeEditor.hpp
	ui/AnimationTreeTemplateEditor.hpp
	ui/CharacterEditor.hpp
	ui/CellGridEditor.hpp
	ui/LotEditor.hpp
	ui/DistrictEditor.hpp
	ui/TownEditor.hpp
	ui/RoofEditor.hpp
	ui/RoomEditor.hpp


	ui/ClearAreaEditor.hpp
	ui/FurnitureTemplateEditor.hpp
	ui/StartupMenuEditor.hpp
	ui/PlayerControllerEditor.hpp
	ui/BuoyancyInfoEditor.hpp
	ui/GoapBlackboardEditor.hpp
	ui/GoapBlackboardComponentEditor.hpp
	ui/BehaviorTreeEditor.hpp
	ui/InlineBehaviorTreeEditor.hpp
	ui/NavMeshEditor.hpp
	ui/NavMeshGeometrySourceEditor.hpp
	ui/ActionDatabaseEditor.hpp
	ui/ActionDebugEditor.hpp
	components/GoapBlackboard.hpp
	components/GoapExpression.hpp
	components/NavMesh.hpp
	components/BehaviorTree.hpp
	components/GoapAction.hpp
	components/GoapGoal.hpp
	components/ActionDatabase.hpp
	components/ActionDebug.hpp
	camera/EditorCamera.hpp
	gizmo/Gizmo.hpp
	physics/physics.h
)

add_executable(editSceneEditor ${EDITSCENE_SOURCES} ${EDITSCENE_HEADERS})

# Define JPH_DEBUG_RENDERER for physics debug drawing
target_compile_definitions(editSceneEditor PRIVATE JPH_DEBUG_RENDERER)

target_link_libraries(editSceneEditor
	OgreMain
	OgreBites
	OgreOverlay
	OgreMeshLodGenerator
	flecs::flecs_static
	nlohmann_json::nlohmann_json
	Jolt::Jolt
	OgreProcedural::OgreProcedural
	RecastNavigation::Recast
	RecastNavigation::Detour
	RecastNavigation::DetourTileCache
	RecastNavigation::DetourCrowd
	RecastNavigation::DebugUtils
)

target_include_directories(editSceneEditor PRIVATE
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Recast/Include
	${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Detour/Include
	${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/DetourTileCache/Include
	${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/DetourCrowd/Include
	${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/DebugUtils/Include
)

# Copy local resources (materials, etc.)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/resources")
	file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/resources"
		DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
endif()

# Copy resources from main build
add_custom_command(TARGET editSceneEditor POST_BUILD
	COMMAND ${CMAKE_COMMAND} -E copy_directory
	"${CMAKE_BINARY_DIR}/resources"
	"${CMAKE_CURRENT_BINARY_DIR}/resources"
	COMMAND ${CMAKE_COMMAND} -E copy_directory
	"${CMAKE_BINARY_DIR}/characters"
	"${CMAKE_CURRENT_BINARY_DIR}/characters"
	COMMAND ${CMAKE_COMMAND} -E copy_directory
	"${CMAKE_BINARY_DIR}/lua-scripts"
	"${CMAKE_CURRENT_BINARY_DIR}/lua-scripts"
	COMMAND ${CMAKE_COMMAND} -E copy
	"${CMAKE_CURRENT_SOURCE_DIR}/resources.cfg"
	"${CMAKE_CURRENT_BINARY_DIR}/resources.cfg"
	# Re-copy editScene-specific resources so they aren't overwritten
	COMMAND ${CMAKE_COMMAND} -E copy_directory
	"${CMAKE_CURRENT_SOURCE_DIR}/resources"
	"${CMAKE_CURRENT_BINARY_DIR}/resources"
	COMMENT "Copying resources to editSceneEditor build directory"
)
