LifePlay-Revival/Source/LifePlay/LPVictoryCompat.cpp
edujiro5972 1122e17fa6 L0 : etat initial du projet 5.5 avant toute correction
Instantane de reference de la reprise de migration (2026-09-29).
Contient GI.uasset tel que trouve (copie UE4 identique a 4.27,
MD5 F4550DA5DC05FC005400CDCA2FC123C9). Ajouts de ce commit :
.gitattributes (aucune conversion de fin de ligne), regles .gitignore
CHG-001, Tools/ (Snapshot, Restore, AssetHeaders), empreintes L0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 00:56:10 +02:00

80 lines
2.8 KiB
C++

// Portage UE 5.5 - voir LPVictoryCompat.h
#include "LPVictoryCompat.h"
#include "Engine/Texture2D.h"
#include "HAL/PlatformApplicationMisc.h"
#include "IImageWrapper.h"
#include "IImageWrapperModule.h"
#include "Misc/FileHelper.h"
#include "Modules/ModuleManager.h"
namespace
{
EImageFormat GetJoyImageFormat(EJoyImageFormats JoyFormat)
{
switch (JoyFormat)
{
case EJoyImageFormats::JPG: return EImageFormat::JPEG;
case EJoyImageFormats::PNG: return EImageFormat::PNG;
case EJoyImageFormats::BMP: return EImageFormat::BMP;
case EJoyImageFormats::ICO: return EImageFormat::ICO;
case EJoyImageFormats::EXR: return EImageFormat::EXR;
case EJoyImageFormats::ICNS: return EImageFormat::ICNS;
}
return EImageFormat::JPEG;
}
}
UTexture2D* ULPVictoryCompat::Victory_LoadTexture2D_FromFile(const FString& FullFilePath, EJoyImageFormats ImageFormat, bool& IsValid, int32& Width, int32& Height)
{
IsValid = false;
UTexture2D* LoadedT2D = nullptr;
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(GetJoyImageFormat(ImageFormat));
// Load From File
TArray<uint8> RawFileData;
if (!FFileHelper::LoadFileToArray(RawFileData, *FullFilePath)) return nullptr;
// Create T2D!
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
{
TArray<uint8> UncompressedBGRA;
if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
{
LoadedT2D = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
// Valid?
if (!LoadedT2D) return nullptr;
// Out!
Width = ImageWrapper->GetWidth();
Height = ImageWrapper->GetHeight();
// Copy!
// 5.1+ : UTexture2D::PlatformData est prive, on passe par GetPlatformData()
void* TextureData = LoadedT2D->GetPlatformData()->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, UncompressedBGRA.GetData(), UncompressedBGRA.Num());
LoadedT2D->GetPlatformData()->Mips[0].BulkData.Unlock();
// Update!
LoadedT2D->UpdateResource();
}
}
// Success!
// NOTE : comportement repris tel quel du plugin d'origine. IsValid ne distingue que
// le fichier introuvable (false, sortie anticipee ci-dessus) du reste (true), y compris
// quand l'image est illisible et que le retour est nul. Volontairement non corrige :
// les Blueprints existants branchent sur ce flag, changer sa semantique changerait
// leur comportement. Voir Docs/Architecture/VictoryPlugin_Architecture.md (R-14).
IsValid = true;
return LoadedT2D;
}
void ULPVictoryCompat::Victory_SaveStringToOSClipboard(const FString& ToClipboard)
{
FPlatformApplicationMisc::ClipboardCopy(*ToClipboard);
}