flockbay 0.10.20 → 0.10.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,8 @@
27
27
  #include "Components/StaticMeshComponent.h"
28
28
  #include "Materials/MaterialInterface.h"
29
29
  #include "Sound/SoundWave.h"
30
+ #include "IImageWrapper.h"
31
+ #include "IImageWrapperModule.h"
30
32
  #include "EditorSubsystem.h"
31
33
  #include "Subsystems/EditorActorSubsystem.h"
32
34
  #include "Engine/Blueprint.h"
@@ -54,6 +56,31 @@
54
56
  #include "Components/SceneCaptureComponent2D.h"
55
57
  #include "Engine/TextureRenderTarget2D.h"
56
58
 
59
+ static bool SavePngToFile(const FString& FilePath, int32 Width, int32 Height, const TArray<FColor>& Bitmap)
60
+ {
61
+ IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
62
+ TSharedPtr<IImageWrapper> Wrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
63
+ if (!Wrapper.IsValid())
64
+ {
65
+ return false;
66
+ }
67
+
68
+ if (!Wrapper->SetRaw(Bitmap.GetData(), Bitmap.Num() * sizeof(FColor), Width, Height, ERGBFormat::BGRA, 8))
69
+ {
70
+ return false;
71
+ }
72
+
73
+ const TArray64<uint8>& Compressed = Wrapper->GetCompressed(100);
74
+ if (Compressed.Num() <= 0 || Compressed.Num() > MAX_int32)
75
+ {
76
+ return false;
77
+ }
78
+
79
+ TArray<uint8> Out;
80
+ Out.Append(Compressed.GetData(), static_cast<int32>(Compressed.Num()));
81
+ return FFileHelper::SaveArrayToFile(Out, *FilePath);
82
+ }
83
+
57
84
  FUnrealMCPEditorCommands::FUnrealMCPEditorCommands()
58
85
  {
59
86
  }
@@ -219,7 +246,7 @@ TSharedPtr<FJsonObject> FUnrealMCPEditorCommands::HandleSaveAll(const TSharedPtr
219
246
  }
220
247
 
221
248
  TArray<UPackage*> DirtyBefore;
222
- FEditorFileUtils::GetDirtyPackages(DirtyBefore, /*bIncludeMapPackages=*/true, /*bIncludeContentPackages=*/true);
249
+ FEditorFileUtils::GetDirtyPackages(DirtyBefore);
223
250
 
224
251
  TSet<FString> DirtyBeforeNames;
225
252
  for (UPackage* Pkg : DirtyBefore)
@@ -239,7 +266,7 @@ TSharedPtr<FJsonObject> FUnrealMCPEditorCommands::HandleSaveAll(const TSharedPtr
239
266
  );
240
267
 
241
268
  TArray<UPackage*> DirtyAfter;
242
- FEditorFileUtils::GetDirtyPackages(DirtyAfter, /*bIncludeMapPackages=*/true, /*bIncludeContentPackages=*/true);
269
+ FEditorFileUtils::GetDirtyPackages(DirtyAfter);
243
270
 
244
271
  TSet<FString> DirtyAfterNames;
245
272
  for (UPackage* Pkg : DirtyAfter)
@@ -293,8 +320,7 @@ TSharedPtr<FJsonObject> FUnrealMCPEditorCommands::HandleSaveAll(const TSharedPtr
293
320
  Details->SetArrayField(TEXT("stillDirtyPackages"), StillDirty);
294
321
 
295
322
  TSharedPtr<FJsonObject> ErrObj = FUnrealMCPCommonUtils::CreateErrorResponse(
296
- TEXT("Some packages are still dirty after save_all. They may require manual Save As, source control checkout, or have save errors. Resolve in-editor and retry save_all."),
297
- );
323
+ TEXT("Some packages are still dirty after save_all. They may require manual Save As, source control checkout, or have save errors. Resolve in-editor and retry save_all."));
298
324
  ErrObj->SetObjectField(TEXT("details"), Details);
299
325
  return ErrObj;
300
326
  }
@@ -2445,9 +2471,7 @@ TSharedPtr<FJsonObject> FUnrealMCPEditorCommands::HandleTakeScreenshot(const TSh
2445
2471
 
2446
2472
  CaptureActor->Destroy();
2447
2473
 
2448
- TArray<uint8> CompressedBitmap;
2449
- FImageUtils::CompressImageArray(Width, Height, Bitmap, CompressedBitmap);
2450
- if (!FFileHelper::SaveArrayToFile(CompressedBitmap, *FilePath))
2474
+ if (!SavePngToFile(FilePath, Width, Height, Bitmap))
2451
2475
  {
2452
2476
  return FUnrealMCPCommonUtils::CreateErrorResponse(TEXT("Failed to save screenshot PNG to disk."));
2453
2477
  }
@@ -2472,10 +2496,7 @@ TSharedPtr<FJsonObject> FUnrealMCPEditorCommands::HandleTakeScreenshot(const TSh
2472
2496
 
2473
2497
  if (Viewport->ReadPixels(Bitmap, FReadSurfaceDataFlags(), ViewportRect))
2474
2498
  {
2475
- TArray<uint8> CompressedBitmap;
2476
- FImageUtils::CompressImageArray(ViewSize.X, ViewSize.Y, Bitmap, CompressedBitmap);
2477
-
2478
- if (FFileHelper::SaveArrayToFile(CompressedBitmap, *FilePath))
2499
+ if (SavePngToFile(FilePath, ViewSize.X, ViewSize.Y, Bitmap))
2479
2500
  {
2480
2501
  TSharedPtr<FJsonObject> ResultObj = MakeShared<FJsonObject>();
2481
2502
  ResultObj->SetStringField(TEXT("filepath"), FilePath);
@@ -45,6 +45,7 @@ public class UnrealMCP : ModuleRules
45
45
  "EditorScriptingUtilities",
46
46
  "EditorSubsystem",
47
47
  "Landscape",
48
+ "ImageWrapper",
48
49
  "Slate",
49
50
  "SlateCore",
50
51
  "MessageLog",