“初始化俯视角工程,带puerts,未编过”

This commit is contained in:
2024-12-01 02:11:25 +08:00
parent 04698dd585
commit 850d76173c
1491 changed files with 271579 additions and 0 deletions
@@ -0,0 +1,10 @@
/*
* Tencent is pleased to support the open source community by making Puerts available.
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
* Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may
* be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE',
* which is part of this source code package.
*/
#include "CodeGenerator.h"
// Add default functionality here for any ICodeGenerator functions that are not pure virtual.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,8 @@
// gen by puerts gen tools
auto SName = Struct -> GetName();
if (SName == "IntVector" || SName == "Color" || SName == "Quat" || SName == "Vector2D" || SName == "Vector4" ||
SName == "Transform" || SName == "LinearColor" || SName == "Box2D" || SName == "Vector" || SName == "IntPoint" ||
SName == "Rotator" || SName == "Guid")
{
return;
}
@@ -0,0 +1,19 @@
/*
* Tencent is pleased to support the open source community by making Puerts available.
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
* Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may
* be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE',
* which is part of this source code package.
*/
#include "GenDTSCommands.h"
#define LOCTEXT_NAMESPACE "FGenDTSModule"
void FGenDTSCommands::RegisterCommands()
{
UI_COMMAND(
PluginAction, "puerts", "Generate *.d.ts and copy some js builtin libs", EUserInterfaceActionType::Button, FInputChord());
}
#undef LOCTEXT_NAMESPACE
@@ -0,0 +1,76 @@
/*
* Tencent is pleased to support the open source community by making Puerts available.
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
* Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may
* be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE',
* which is part of this source code package.
*/
#include "GenDTSStyle.h"
#include "Framework/Application/SlateApplication.h"
#include "Styling/SlateStyleRegistry.h"
#include "Slate/SlateGameResources.h"
#include "Interfaces/IPluginManager.h"
TSharedPtr<FSlateStyleSet> FGenDTSStyle::StyleInstance = NULL;
void FGenDTSStyle::Initialize()
{
if (!StyleInstance.IsValid())
{
StyleInstance = Create();
FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
}
}
void FGenDTSStyle::Shutdown()
{
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
ensure(StyleInstance.IsUnique());
StyleInstance.Reset();
}
FName FGenDTSStyle::GetStyleSetName()
{
static FName StyleSetName(TEXT("GenDTSStyle"));
return StyleSetName;
}
#define IMAGE_BRUSH(RelativePath, ...) FSlateImageBrush(Style->RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__)
#define BOX_BRUSH(RelativePath, ...) FSlateBoxBrush(Style->RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__)
#define BORDER_BRUSH(RelativePath, ...) FSlateBorderBrush(Style->RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__)
#define TTF_FONT(RelativePath, ...) FSlateFontInfo(Style->RootToContentDir(RelativePath, TEXT(".ttf")), __VA_ARGS__)
#define OTF_FONT(RelativePath, ...) FSlateFontInfo(Style->RootToContentDir(RelativePath, TEXT(".otf")), __VA_ARGS__)
const FVector2D Icon16x16(16.0f, 16.0f);
const FVector2D Icon20x20(20.0f, 20.0f);
const FVector2D Icon40x40(40.0f, 40.0f);
TSharedRef<FSlateStyleSet> FGenDTSStyle::Create()
{
TSharedRef<FSlateStyleSet> Style = MakeShareable(new FSlateStyleSet("GenDTSStyle"));
Style->SetContentRoot(IPluginManager::Get().FindPlugin("Puerts")->GetBaseDir() / TEXT("Resources"));
Style->Set("GenDTS.PluginAction", new IMAGE_BRUSH(TEXT("ButtonIcon_40x"), Icon40x40));
return Style;
}
#undef IMAGE_BRUSH
#undef BOX_BRUSH
#undef BORDER_BRUSH
#undef TTF_FONT
#undef OTF_FONT
void FGenDTSStyle::ReloadTextures()
{
if (FSlateApplication::IsInitialized())
{
FSlateApplication::Get().GetRenderer()->ReloadTextureResources();
}
}
const ISlateStyle& FGenDTSStyle::Get()
{
return *StyleInstance;
}
@@ -0,0 +1,208 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "TemplateBindingGenerator.h"
#include "JSClassRegister.h"
#include "Interfaces/IPluginManager.h"
#include "CoreUObject.h"
#ifdef PUERTS_WITH_SOURCE_CONTROL
#include "FileSystemOperation.h"
#endif
struct FGenImp
{
FStringBuffer Output{"", ""};
FString GetNamePrefix(const PUERTS_NAMESPACE::CTypeInfo* TypeInfo)
{
return TypeInfo->IsUEType() && !HadNamespace(TypeInfo->Name()) ? "UE." : "";
}
FString GetName(const PUERTS_NAMESPACE::CTypeInfo* TypeInfo)
{
return UTF8_TO_TCHAR(TypeInfo->Name());
}
void Begin()
{
Output << "declare module \"cpp\" {\n";
Output << " import * as UE from \"ue\"\n";
Output << " import * as cpp from \"cpp\"\n";
Output << " import {$Ref, $Nullable, cstring} from \"puerts\"\n\n";
}
void GenArguments(const PUERTS_NAMESPACE::CFunctionInfo* Type, FStringBuffer& Buff)
{
for (unsigned int i = 0; i < Type->ArgumentCount(); i++)
{
if (i != 0)
Buff << ", ";
auto argInfo = Type->Argument(i);
Buff << FString::Printf(TEXT("p%d"), i);
if (i >= Type->ArgumentCount() - Type->DefaultCount())
{
Buff << "?";
}
Buff << ": ";
if (strcmp(argInfo->Name(), "cstring") != 0 && !argInfo->IsUEType() && !argInfo->IsObjectType() && argInfo->IsPointer())
{
Buff << "ArrayBuffer";
}
else
{
bool IsReference = argInfo->IsRef();
bool IsNullable = !IsReference && argInfo->IsPointer();
if (IsNullable)
{
Buff << "$Nullable<";
}
if (IsReference)
{
Buff << "$Ref<";
}
const PUERTS_NAMESPACE::CTypeInfo* TypeInfo = Type->Argument(i);
Buff << GetNamePrefix(TypeInfo) << GetName(TypeInfo);
if (IsNullable)
{
Buff << ">";
}
if (IsReference)
{
Buff << ">";
}
}
}
}
void GenClass(const PUERTS_NAMESPACE::JSClassDefinition* ClassDefinition)
{
if (HasUENamespace(ClassDefinition->ScriptName))
return;
Output << " class " << ClassDefinition->ScriptName;
if (ClassDefinition->SuperTypeId)
{
Output << " extends " << PUERTS_NAMESPACE::FindClassByID(ClassDefinition->SuperTypeId)->ScriptName;
}
Output << " {\n";
TSet<FString> AddedFunctions;
PUERTS_NAMESPACE::NamedFunctionInfo* ConstructorInfo = ClassDefinition->ConstructorInfos;
while (ConstructorInfo && ConstructorInfo->Name && ConstructorInfo->Type)
{
FStringBuffer Tmp;
Tmp << " constructor(";
GenArguments(ConstructorInfo->Type, Tmp);
Tmp << ");\n";
if (!AddedFunctions.Contains(Tmp.Buffer))
{
AddedFunctions.Add(Tmp.Buffer);
Output << Tmp;
}
++ConstructorInfo;
}
PUERTS_NAMESPACE::NamedPropertyInfo* PropertyInfo = ClassDefinition->PropertyInfos;
while (PropertyInfo && PropertyInfo->Name && PropertyInfo->Type)
{
Output << " " << PropertyInfo->Name << ": " << GetNamePrefix(PropertyInfo->Type) << PropertyInfo->Type->Name()
<< ";\n";
++PropertyInfo;
}
PUERTS_NAMESPACE::NamedPropertyInfo* VariableInfo = ClassDefinition->VariableInfos;
while (VariableInfo && VariableInfo->Name && VariableInfo->Type)
{
int Pos = VariableInfo - ClassDefinition->VariableInfos;
Output << " static " << (ClassDefinition->Variables[Pos].Setter ? "" : "readonly ") << VariableInfo->Name << ": "
<< GetNamePrefix(VariableInfo->Type) << VariableInfo->Type->Name() << ";\n";
++VariableInfo;
}
PUERTS_NAMESPACE::NamedFunctionInfo* FunctionInfo = ClassDefinition->FunctionInfos;
while (FunctionInfo && FunctionInfo->Name && FunctionInfo->Type)
{
FStringBuffer Tmp;
Tmp << " static " << FunctionInfo->Name;
if (FunctionInfo->Type->Return())
{
Tmp << "(";
GenArguments(FunctionInfo->Type, Tmp);
const PUERTS_NAMESPACE::CTypeInfo* ReturnType = FunctionInfo->Type->Return();
Tmp << ") :" << GetNamePrefix(ReturnType) << GetName(ReturnType) << ";\n";
}
else
{
Tmp << FunctionInfo->Type->CustomSignature() << ";\n";
}
if (!AddedFunctions.Contains(Tmp.Buffer))
{
AddedFunctions.Add(Tmp.Buffer);
Output << Tmp;
}
++FunctionInfo;
}
PUERTS_NAMESPACE::NamedFunctionInfo* MethodInfo = ClassDefinition->MethodInfos;
while (MethodInfo && MethodInfo->Name && MethodInfo->Type)
{
FStringBuffer Tmp;
Tmp << " " << MethodInfo->Name;
if (MethodInfo->Type->Return())
{
Tmp << "(";
GenArguments(MethodInfo->Type, Tmp);
const PUERTS_NAMESPACE::CTypeInfo* ReturnType = MethodInfo->Type->Return();
Tmp << ") :" << GetNamePrefix(ReturnType) << GetName(ReturnType) << ";\n";
}
else
{
Tmp << MethodInfo->Type->CustomSignature() << ";\n";
}
if (!AddedFunctions.Contains(Tmp.Buffer))
{
AddedFunctions.Add(Tmp.Buffer);
Output << Tmp;
}
++MethodInfo;
}
Output << " }\n\n";
}
void End()
{
Output << "}\n";
}
};
void UTemplateBindingGenerator::Gen_Implementation() const
{
FGenImp Gen;
Gen.Begin();
PUERTS_NAMESPACE::ForeachRegisterClass(
[&](const PUERTS_NAMESPACE::JSClassDefinition* ClassDefinition)
{
if (ClassDefinition->TypeId && ClassDefinition->ScriptName)
{
Gen.GenClass(ClassDefinition);
}
});
Gen.End();
const FString FilePath = FPaths::ProjectDir() / TEXT("Typing/cpp/index.d.ts");
#ifdef PUERTS_WITH_SOURCE_CONTROL
PuertsSourceControlUtils::MakeSourceControlFileWritable(FilePath);
#endif
FFileHelper::SaveStringToFile(Gen.Output.Buffer, *FilePath, FFileHelper::EEncodingOptions::ForceUTF8WithoutBOM);
}