// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.

#include "LODRecipeEditorModule.h"
#include "LODRecipeAssetActions.h"
#include "LODRecipeExtensions.h"

#include "AssetToolsModule.h"

DEFINE_LOG_CATEGORY_STATIC( LogLODRecipeModule, VeryVerbose, All );

#define LOCTEXT_NAMESPACE "LODRecipeModule"

class FLODRecipeEditorModule : public ILODRecipeEditorModule
{
public:
	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;

private:
	FDelegateHandle ExtensionsModuleLoaded;
};

IMPLEMENT_MODULE( FLODRecipeEditorModule, LODRecipeEditor )

void FLODRecipeEditorModule::StartupModule()
{
	// Register LODRecipe asset types
	IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
	EAssetTypeCategories::Type SimplygonCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("Simplygon")), LOCTEXT("SimplygonLODSettingsAssetCategory", "Simplygon"));
	AssetTools.RegisterAssetTypeActions(MakeShareable(new FLODRecipeAssetActions(SimplygonCategory)));

	// Add extensions:
	//   - Static mesh editor
	//   - Skeletal mesh editor
	ExtensionsModuleLoaded = FModuleManager::Get().OnModulesChanged().AddStatic(&FLODRecipeExtensions::OnModulesChanged);
	//   - Content browser
	FLODRecipeExtensions::AddContentBrowserExtensions();
}

void FLODRecipeEditorModule::ShutdownModule()
{
	FModuleManager::Get().OnModulesChanged().Remove(ExtensionsModuleLoaded);
	FLODRecipeExtensions::RemoveExtensions();
	FLODRecipeExtensions::RemoveContentBrowserExtensions();
}
#undef LOCTEXT_NAMESPACE
