Skip to content

Commit 096f509

Browse files
author
Nako Sung
committed
Merge from dev
1 parent 343e66f commit 096f509

File tree

7 files changed

+109
-15
lines changed

7 files changed

+109
-15
lines changed

Plugins/UnrealJS/Source/JavascriptEditor/JavascriptEditorGlobalDelegates.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "JavascriptEditor.h"
22
#include "AssetRegistryModule.h"
3+
#include "EditorSupportDelegates.h"
34
#include "JavascriptEditorGlobalDelegates.h"
45

56
void UJavascriptEditorGlobalDelegates::BeginDestroy()
@@ -70,7 +71,12 @@ OP_REFLECT_EDITORENGINE(OnBlueprintPreCompile)\
7071
OP_REFLECT_EDITORENGINE(OnBlueprintCompiled)\
7172
OP_REFLECT_EDITORENGINE(OnBlueprintReinstanced)\
7273
OP_REFLECT_EDITORENGINE(OnClassPackageLoadedOrUnloaded)\
73-
OP_REFLECT_EDITORENGINE(OnObjectReimported);
74+
OP_REFLECT_EDITORENGINE(OnObjectReimported)
75+
76+
#define DO_REFLECT_SUPPORT() \
77+
OP_REFLECT_SUPPORT(RedrawAllViewports)\
78+
OP_REFLECT_SUPPORT(CleanseEditor)\
79+
OP_REFLECT_SUPPORT(WorldChange)
7480

7581
#if WITH_EDITOR
7682
FJavascriptAssetData::FJavascriptAssetData(const FAssetData& Source)
@@ -88,10 +94,13 @@ void UJavascriptEditorGlobalDelegates::Bind(FString Key)
8894
#define OP_REFLECT(x) else if (Key == #x) { Handle = FEditorDelegates::x.AddUObject(this, &UJavascriptEditorGlobalDelegates::x); }
8995
#define OP_REFLECT_ASSETREGISTRY(x) else if (Key == #x) { Handle = AssetRegistry.x().AddUObject(this, &UJavascriptEditorGlobalDelegates::x); }
9096
#define OP_REFLECT_EDITORENGINE(x) else if (Key == #x) { Handle = Cast<UEditorEngine>(GEngine)->x().AddUObject(this, &UJavascriptEditorGlobalDelegates::x); }
97+
#define OP_REFLECT_SUPPORT(x) else if (Key == #x) { Handle = FEditorSupportDelegates::x.AddUObject(this, &UJavascriptEditorGlobalDelegates::x); }
9198
if (false) {}
92-
DO_REFLECT()
93-
DO_REFLECT_ASSETREGISTRY()
94-
DO_REFLECT_EDITORENGINE()
99+
DO_REFLECT()
100+
DO_REFLECT_ASSETREGISTRY()
101+
DO_REFLECT_EDITORENGINE()
102+
DO_REFLECT_SUPPORT()
103+
;
95104
#endif
96105

97106
if (Handle.IsValid())
@@ -117,10 +126,13 @@ void UJavascriptEditorGlobalDelegates::Unbind(FString Key)
117126
#define OP_REFLECT(x) else if (Key == #x) { FEditorDelegates::x.Remove(Handle); }
118127
#define OP_REFLECT_ASSETREGISTRY(x) else if (Key == #x) { AssetRegistry.x().Remove(Handle); }
119128
#define OP_REFLECT_EDITORENGINE(x) else if (Key == #x) { Cast<UEditorEngine>(GEngine)->x().Remove(Handle); }
129+
#define OP_REFLECT_SUPPORT(x) else if (Key == #x) { FEditorSupportDelegates::x.Remove(Handle); }
120130
if (false) {}
121-
DO_REFLECT()
122-
DO_REFLECT_ASSETREGISTRY()
123-
DO_REFLECT_EDITORENGINE()
131+
DO_REFLECT()
132+
DO_REFLECT_ASSETREGISTRY()
133+
DO_REFLECT_EDITORENGINE()
134+
DO_REFLECT_SUPPORT()
135+
;
124136
#endif
125137

126138
Handles.Remove(Key);

Plugins/UnrealJS/Source/JavascriptEditor/JavascriptEditorGlobalDelegates.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ class JAVASCRIPTEDITOR_API UJavascriptEditorGlobalDelegates : public UObject
267267
void OnObjectReimported(UObject* Object);
268268

269269
//GetActorRecordingState
270+
271+
// FEditorSupportDelegates
272+
273+
UFUNCTION(BlueprintImplementableEvent, Category = "Scripting | Javascript")
274+
void RedrawAllViewports();
275+
276+
UFUNCTION(BlueprintImplementableEvent, Category = "Scripting | Javascript")
277+
void CleanseEditor();
278+
279+
UFUNCTION(BlueprintImplementableEvent, Category = "Scripting | Javascript")
280+
void WorldChange();
270281

271282
#endif
272283

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "JavascriptUMG.h"
2+
#include "JavascriptRichTextBlockHyperlinkDecorator.h"
3+
4+
TSharedRef<ITextDecorator> UJavascriptRichTextBlockHyperlinkDecorator::CreateDecorator(const FSlateFontInfo& DefaultFont, const FLinearColor& DefaultColor)
5+
{
6+
return SRichTextBlock::HyperlinkDecorator(HyperlinkId, FSlateHyperlinkRun::FOnClick::CreateLambda([this](const FSlateHyperlinkRun::FMetadata& metadata) {
7+
Current = &metadata;
8+
this->OnClick.Broadcast(this);
9+
Current = nullptr;
10+
}));
11+
}
12+
13+
FString UJavascriptRichTextBlockHyperlinkDecorator::GetMetadata(const FString& Key)
14+
{
15+
if (Current)
16+
{
17+
auto Value = Current->Find(Key);
18+
if (Value)
19+
{
20+
return *Value;
21+
}
22+
}
23+
24+
return TEXT("");
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include "RichTextBlockDecorator.h"
4+
#include "JavascriptRichTextBlockHyperlinkDecorator.generated.h"
5+
6+
class UJavascriptContext;
7+
8+
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FJavascriptHyperlinkSignature, UJavascriptRichTextBlockHyperlinkDecorator*, Self);
9+
10+
/**
11+
* Allows thousands of items to be displayed in a Tile. Generates widgets dynamically for each item.
12+
*/
13+
UCLASS(Experimental)
14+
class JAVASCRIPTUMG_API UJavascriptRichTextBlockHyperlinkDecorator : public URichTextBlockDecorator
15+
{
16+
GENERATED_BODY()
17+
18+
public:
19+
UPROPERTY(EditAnywhere, Category = "Scripting | Javascript")
20+
FString HyperlinkId;
21+
22+
UPROPERTY(BlueprintAssignable, Category = "Scripting | Javascript")
23+
FJavascriptHyperlinkSignature OnClick;
24+
25+
virtual TSharedRef<ITextDecorator> CreateDecorator(const FSlateFontInfo& DefaultFont, const FLinearColor& DefaultColor) override;
26+
27+
void HandleClick(const FSlateHyperlinkRun::FMetadata& Metadata);
28+
29+
UFUNCTION(BlueprintCallable, Category = "Scripting | Javascript")
30+
FString GetMetadata(const FString& Key);
31+
32+
const FSlateHyperlinkRun::FMetadata* Current{ nullptr };
33+
};

Plugins/UnrealJS/Source/JavascriptWebSocket/JSWebSocketServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int unreal_networking_server(
4242
);
4343

4444
#if !UE_BUILD_SHIPPING
45-
void libwebsocket_debugLog(int level, const char *line)
45+
void libwebsocket_debugLog_JS(int level, const char *line)
4646
{
4747
UE_LOG(LogWebsocket, Log, TEXT("websocket server: %s"), ANSI_TO_TCHAR(line));
4848
}
@@ -54,7 +54,7 @@ bool FJavascriptWebSocketServer::Init(uint32 Port, FJavascriptWebSocketClientCon
5454
#if !PLATFORM_HTML5
5555
// setup log level.
5656
#if !UE_BUILD_SHIPPING
57-
lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_DEBUG | LLL_INFO, libwebsocket_debugLog);
57+
lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_DEBUG | LLL_INFO, libwebsocket_debugLog_JS);
5858
#endif
5959

6060
Protocols = new libwebsocket_protocols[3];

Plugins/UnrealJS/Source/V8/Private/JavascriptContext_Private.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,11 +1199,11 @@ class FJavascriptContextImplementation : public FJavascriptContext
11991199
FString Text;
12001200
if (FFileHelper::LoadFileToString(Text, *script_path))
12011201
{
1202-
Text = FString::Printf(TEXT("(function (__dirname) {\nvar module = { exports : {}, filename : __dirname }, exports = module.exports;\n%s\n;return module.exports;}('%s'));"), *Text, *script_path);
1202+
Text = FString::Printf(TEXT("(function (global,__dirname) {\nvar module = { exports : {}, filename : __dirname }, exports = module.exports;\n(function () { \n%s\n })()\n;return module.exports;}(this,'%s'));"), *Text, *script_path);
12031203
#if PLATFORM_WINDOWS
12041204
full_path = full_path.Replace(TEXT("/"), TEXT("\\"));
12051205
#endif
1206-
auto exports = Self->RunScript(full_path, Text, 2);
1206+
auto exports = Self->RunScript(full_path, Text, 3);
12071207
if (exports.IsEmpty())
12081208
{
12091209
UE_LOG(Javascript, Log, TEXT("Invalid script for require"));
@@ -1397,7 +1397,11 @@ class FJavascriptContextImplementation : public FJavascriptContext
13971397

13981398
auto Script = ReadScriptFile(Filename);
13991399

1400-
return RunScript(GetScriptFileFullPath(Filename), Script);
1400+
auto ScriptPath = GetScriptFileFullPath(Filename);
1401+
1402+
auto Text = FString::Printf(TEXT("(function (global,__dirname) {\n%s\n;}(this,'%s'));"), *Script, *ScriptPath);
1403+
1404+
return RunScript(ScriptPath, Text, 1);
14011405
}
14021406

14031407
void Public_RunFile(const FString& Filename)
@@ -1433,7 +1437,7 @@ class FJavascriptContextImplementation : public FJavascriptContext
14331437
auto Path = Filename;
14341438
#if PLATFORM_WINDOWS
14351439
// HACK for Visual Studio Code
1436-
if (Path[1] == ':')
1440+
if (Path.Len() && Path[1] == ':')
14371441
{
14381442
Path = Path.Mid(0, 1).ToLower() + Path.Mid(1);
14391443
}
@@ -1681,6 +1685,7 @@ inline void FJavascriptContextImplementation::AddReferencedObjects(UObject * InT
16811685
// All objects
16821686
for (auto It = ObjectToObjectMap.CreateIterator(); It; ++It)
16831687
{
1688+
// UE_LOG(Javascript, Log, TEXT("JavascriptContext referencing %s %s"), *(It.Key()->GetClass()->GetName()), *(It.Key()->GetName()));
16841689
Collector.AddReferencedObject(It.Key(), InThis);
16851690
}
16861691

Plugins/UnrealJS/Source/V8/Private/JavascriptIsolate_Private.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
413413
// All classes
414414
for (auto It = ClassToFunctionTemplateMap.CreateIterator(); It; ++It)
415415
{
416-
Collector.AddReferencedObject(It.Key(), InThis);
416+
UClass* Class = It.Key();
417+
//UE_LOG(Javascript, Log, TEXT("JavascriptIsolate referencing %s / %s %s (gen by %s %s)"), *(Class->GetOuter()->GetName()), *(Class->GetClass()->GetName()), *(Class->GetName()), Class->ClassGeneratedBy ? *(Class->ClassGeneratedBy->GetClass()->GetName()) : TEXT("none"), Class->ClassGeneratedBy ? *(Class->ClassGeneratedBy->GetName()) : TEXT("none"));
418+
Collector.AddReferencedObject(Class, InThis);
417419
}
418420

419421
// All structs
@@ -1918,7 +1920,13 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
19181920
}
19191921
else
19201922
{
1921-
auto v8_class = ExportClass(Object->GetClass());
1923+
auto Class = Object->GetClass();
1924+
if (Class->ClassGeneratedBy && Cast<ULevel>(Class->ClassGeneratedBy->GetOuter()))
1925+
{
1926+
return Undefined(isolate_);
1927+
}
1928+
1929+
auto v8_class = ExportClass(Class);
19221930
auto arg = I.External(Object);
19231931
Handle<Value> args[] = { arg };
19241932

0 commit comments

Comments
 (0)