You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb sebatian.nordgren #ROBOMERGE-OWNER: jason.stasik #ROBOMERGE-AUTHOR: jason.stasik #ROBOMERGE-SOURCE: CL 18795736 via CL 18797126 via CL 18803326 via CL 18803348 via CL 18803356 via CL 18804424 via CL 18821688 #ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v908-18788545) [CL 18822076 by jason stasik in ue5-main branch]
127 lines
4.4 KiB
C++
127 lines
4.4 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "Editor.h"
|
|
#include "EditorConfig.h"
|
|
#include "EditorSubsystem.h"
|
|
#include "TickableEditorObject.h"
|
|
|
|
#include "EditorConfigSubsystem.generated.h"
|
|
|
|
UCLASS()
|
|
class EDITORCONFIG_API UEditorConfigSubsystem :
|
|
public UEditorSubsystem,
|
|
public FTickableEditorObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UEditorConfigSubsystem();
|
|
|
|
/**
|
|
* Load a config from the root of the JSON file into a given UObject.
|
|
* This loads the config from the UCLASS's EditorConfig="ConfigName" metadata.
|
|
* @param Object The object to load into.
|
|
* @param Filter Whether to load all properties, or only ones marked with the EditorConfig metadata.
|
|
*/
|
|
template <typename TObject>
|
|
bool LoadConfigObject(TObject* Object, FEditorConfig::EPropertyFilter Filter = FEditorConfig::EPropertyFilter::MetadataOnly);
|
|
|
|
/**
|
|
* Save the given UObject to the root of the JSON config.
|
|
* This saves the config to the UCLASS's EditorConfig="ConfigName" metadata.
|
|
* @param Object The object to save.
|
|
* @param Filter Whether to save all properties, or only ones marked with the EditorConfig metadata.
|
|
*/
|
|
template <typename TObject>
|
|
bool SaveConfigObject(const TObject* Object, FEditorConfig::EPropertyFilter Filter = FEditorConfig::EPropertyFilter::MetadataOnly);
|
|
|
|
/**
|
|
* Load a config from the root of the JSON file into a given UObject.
|
|
* This loads the config from the UCLASS's EditorConfig="ConfigName" metadata.
|
|
* @param Class The UClass of the object.
|
|
* @param Object The UObject instance to load into.
|
|
* @param Filter Whether to load all properties, or only ones marked with the EditorConfig metadata.
|
|
*/
|
|
bool LoadConfigObject(const UClass* Class, UObject* Object, FEditorConfig::EPropertyFilter = FEditorConfig::EPropertyFilter::MetadataOnly);
|
|
|
|
/**
|
|
* Save the given UObject of the given class to the root of the JSON config.
|
|
* This saves the config to the UCLASS's EditorConfig="ConfigName" metadata.
|
|
* @param Class The UClass of the object.
|
|
* @param Object The UObject instance to save.
|
|
* @param Filter Whether to save all properties, or only ones marked with the EditorConfig metadata.
|
|
*/
|
|
bool SaveConfigObject(const UClass* Class, const UObject* Object, FEditorConfig::EPropertyFilter = FEditorConfig::EPropertyFilter::MetadataOnly);
|
|
|
|
/**
|
|
* Find a config with the given name that has already been loaded, load it if it hasn't been, or create one with the given name.
|
|
*/
|
|
TSharedRef<FEditorConfig> FindOrLoadConfig(FStringView ConfigName);
|
|
|
|
/*
|
|
* Save the given config to the location it was loaded.
|
|
*/
|
|
void SaveConfig(TSharedRef<FEditorConfig> Config);
|
|
|
|
/** Force reload the given config and all its (current and potential) parents from disk. */
|
|
bool ReloadConfig(TSharedRef<FEditorConfig> Config);
|
|
|
|
enum class ESearchDirectoryType : uint8
|
|
{
|
|
Engine,
|
|
Project,
|
|
User
|
|
};
|
|
|
|
/**
|
|
* Append a new config search directory to the given type.
|
|
* Engine directories are searched first, then Project, then User.
|
|
*/
|
|
void AddSearchDirectory(ESearchDirectoryType Type, FStringView SearchDir);
|
|
|
|
private:
|
|
void Initialize(FSubsystemCollectionBase& Collection) override;
|
|
void Deinitialize() override;
|
|
void OnSaveCompleted(TSharedPtr<FEditorConfig> Config);
|
|
void OnEditorConfigDirtied(const FEditorConfig& Config);
|
|
|
|
/** FTickableEditorObject interface */
|
|
void Tick(float DeltaTime) override;
|
|
TStatId GetStatId() const override;
|
|
|
|
private:
|
|
struct FPendingSave
|
|
{
|
|
FString FileName;
|
|
TSharedPtr<FEditorConfig> Config;
|
|
TFuture<bool> WasSuccess;
|
|
float TimeSinceQueued { 0 };
|
|
};
|
|
|
|
FCriticalSection SaveLock;
|
|
TArray<FPendingSave> PendingSaves;
|
|
TArray<TPair<ESearchDirectoryType, FString>> SearchDirectories;
|
|
TMap<FString, TSharedPtr<FEditorConfig>> LoadedConfigs;
|
|
};
|
|
|
|
template <typename TObject>
|
|
bool UEditorConfigSubsystem::LoadConfigObject(TObject* Object, FEditorConfig::EPropertyFilter Filter)
|
|
{
|
|
static_assert(TIsDerivedFrom<TObject, UObject>::Value, "Type is not derived from UObject.");
|
|
check(Object != nullptr);
|
|
|
|
const UClass* Class = TObject::StaticClass();
|
|
return LoadConfigObject(Class, Object, Filter);
|
|
}
|
|
|
|
template <typename TObject>
|
|
bool UEditorConfigSubsystem::SaveConfigObject(const TObject* Object, FEditorConfig::EPropertyFilter Filter)
|
|
{
|
|
static_assert(TIsDerivedFrom<TObject, UObject>::Value, "Type is not derived from UObject.");
|
|
check(Object != nullptr);
|
|
|
|
const UClass* Class = TObject::StaticClass();
|
|
return SaveConfigObject(Class, Object);
|
|
} |