|
3 | 3 | #include "VaRest.h" |
4 | 4 |
|
5 | 5 | #include "VaRestDefines.h" |
6 | | -#include "VaRestJsonObject.h" |
7 | | -#include "VaRestJsonValue.h" |
8 | | -#include "VaRestRequestController.h" |
9 | | -#include "VaRestRequestJSON.h" |
10 | | -#include "VaRestSettings.h" |
11 | | - |
12 | | -#include "Developer/Settings/Public/ISettingsModule.h" |
13 | | - |
14 | | -#define LOCTEXT_NAMESPACE "FVaRestModule" |
15 | | - |
16 | | -void FVaRestModule::StartupModule() |
17 | | -{ |
18 | | - // @HACK Force classes to be compiled on shipping build |
19 | | - UVaRestJsonObject::StaticClass(); |
20 | | - UVaRestJsonValue::StaticClass(); |
21 | | - UVaRestRequestJSON::StaticClass(); |
22 | | - |
23 | | - VaRestSettings = NewObject<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone); |
24 | | - VaRestSettings->AddToRoot(); |
25 | | - |
26 | | - // Register settings |
27 | | - if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) |
28 | | - { |
29 | | - SettingsModule->RegisterSettings("Project", "Plugins", "VaRest", |
30 | | - LOCTEXT("RuntimeSettingsName", "VaRest"), |
31 | | - LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"), |
32 | | - VaRestSettings); |
33 | | - } |
34 | | - |
35 | | - FWorldDelegates::OnWorldCleanup.AddLambda([this](UWorld* World, bool bSessionEnded, bool bCleanupResources) { |
36 | | - RequestControllers.Remove(World); |
37 | | - |
38 | | - UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is removed for: %s"), *VA_FUNC_LINE, *World->GetName()); |
39 | | - }); |
40 | | - |
41 | | - FWorldDelegates::OnPostWorldInitialization.AddLambda([this](UWorld* World, const UWorld::InitializationValues IVS) { |
42 | | - auto Controller = NewObject<UVaRestRequestController>(GetTransientPackage()); |
43 | | - Controller->SetFlags(RF_Standalone); |
44 | | - Controller->AddToRoot(); |
45 | | - |
46 | | - Controller->Initialize(); |
47 | | - |
48 | | - RequestControllers.Add(World, Controller); |
49 | | - |
50 | | - UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is created for: %s"), *VA_FUNC_LINE, *World->GetName()); |
51 | | - }); |
52 | | - |
53 | | - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE); |
54 | | -} |
55 | | - |
56 | | -void FVaRestModule::ShutdownModule() |
57 | | -{ |
58 | | - if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) |
59 | | - { |
60 | | - SettingsModule->UnregisterSettings("Project", "Plugins", "VaRest"); |
61 | | - } |
62 | | - |
63 | | - if (!GExitPurge) |
64 | | - { |
65 | | - VaRestSettings->RemoveFromRoot(); |
66 | | - |
67 | | - // If we're in exit purge, this object has already been destroyed |
68 | | - for (auto Controller : RequestControllers) |
69 | | - { |
70 | | - Controller.Value->RemoveFromRoot(); |
71 | | - } |
72 | | - } |
73 | | - else |
74 | | - { |
75 | | - VaRestSettings = nullptr; |
76 | | - } |
77 | | - |
78 | | - RequestControllers.Empty(); |
79 | | -} |
80 | | - |
81 | | -UVaRestSettings* FVaRestModule::GetSettings() const |
82 | | -{ |
83 | | - check(VaRestSettings); |
84 | | - return VaRestSettings; |
85 | | -} |
86 | | - |
87 | | -UVaRestRequestController* FVaRestModule::GetRequestController(UWorld* World) const |
88 | | -{ |
89 | | - return RequestControllers.FindChecked(World); |
90 | | -} |
91 | 6 |
|
92 | 7 | IMPLEMENT_MODULE(FVaRestModule, VaRest) |
93 | 8 |
|
94 | 9 | DEFINE_LOG_CATEGORY(LogVaRest); |
95 | | - |
96 | | -#undef LOCTEXT_NAMESPACE |
0 commit comments