Skip to content

Commit 8723d1d

Browse files
committed
Merge branch 'master' of https://github.com/ncsoft/Unreal.js
2 parents 2a07dc9 + 45a8241 commit 8723d1d

File tree

8 files changed

+123
-26
lines changed

8 files changed

+123
-26
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/Exception.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ struct FV8Exception
1616
}
1717
else
1818
{
19-
auto filename = StringFromV8(message->GetScriptResourceName());
20-
auto linenum = message->GetLineNumber();
21-
auto line = StringFromV8(message->GetSourceLine());
19+
if (!exception.IsEmpty())
20+
{
21+
auto filename = StringFromV8(message->GetScriptResourceName());
22+
auto linenum = message->GetLineNumber();
23+
auto line = StringFromV8(message->GetSourceLine());
2224

23-
UE_LOG(Javascript, Error, TEXT("%s:%d: %s"), *filename, linenum, *exception);
25+
UE_LOG(Javascript, Error, TEXT("%s:%d: %s"), *filename, linenum, *exception);
2426

25-
auto stack_trace = StringFromV8(try_catch.StackTrace());
26-
if (stack_trace.Len() > 0)
27-
{
28-
TArray<FString> Lines;
29-
stack_trace.ParseIntoArrayLines(Lines);
30-
for (const auto& line : Lines)
27+
auto stack_trace = StringFromV8(try_catch.StackTrace());
28+
if (stack_trace.Len() > 0)
3129
{
32-
UE_LOG(Javascript, Error, TEXT("%s"), *line);
30+
TArray<FString> Lines;
31+
stack_trace.ParseIntoArrayLines(Lines);
32+
for (const auto& line : Lines)
33+
{
34+
UE_LOG(Javascript, Error, TEXT("%s"), *line);
35+
}
3336
}
3437
}
3538
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,11 +1201,11 @@ class FJavascriptContextImplementation : public FJavascriptContext
12011201
FString Text;
12021202
if (FFileHelper::LoadFileToString(Text, *script_path))
12031203
{
1204-
Text = FString::Printf(TEXT("(function (__dirname) {\nvar module = { exports : {}, filename : __dirname }, exports = module.exports;\n%s\n;return module.exports;}('%s'));"), *Text, *script_path);
1204+
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);
12051205
#if PLATFORM_WINDOWS
12061206
full_path = full_path.Replace(TEXT("/"), TEXT("\\"));
12071207
#endif
1208-
auto exports = Self->RunScript(full_path, Text, 2);
1208+
auto exports = Self->RunScript(full_path, Text, 3);
12091209
if (exports.IsEmpty())
12101210
{
12111211
UE_LOG(Javascript, Log, TEXT("Invalid script for require"));
@@ -1399,7 +1399,11 @@ class FJavascriptContextImplementation : public FJavascriptContext
13991399

14001400
auto Script = ReadScriptFile(Filename);
14011401

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

14051409
void Public_RunFile(const FString& Filename)
@@ -1435,7 +1439,7 @@ class FJavascriptContextImplementation : public FJavascriptContext
14351439
auto Path = Filename;
14361440
#if PLATFORM_WINDOWS
14371441
// HACK for Visual Studio Code
1438-
if (Path[1] == ':')
1442+
if (Path.Len() && Path[1] == ':')
14391443
{
14401444
Path = Path.Mid(0, 1).ToLower() + Path.Mid(1);
14411445
}
@@ -1715,6 +1719,7 @@ inline void FJavascriptContextImplementation::AddReferencedObjects(UObject * InT
17151719
// All objects
17161720
for (auto It = ObjectToObjectMap.CreateIterator(); It; ++It)
17171721
{
1722+
// UE_LOG(Javascript, Log, TEXT("JavascriptContext referencing %s %s"), *(It.Key()->GetClass()->GetName()), *(It.Key()->GetName()));
17181723
Collector.AddReferencedObject(It.Key(), InThis);
17191724
}
17201725

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
408408
// All classes
409409
for (auto It = ClassToFunctionTemplateMap.CreateIterator(); It; ++It)
410410
{
411-
Collector.AddReferencedObject(It.Key(), InThis);
411+
UClass* Class = It.Key();
412+
//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"));
413+
Collector.AddReferencedObject(Class, InThis);
412414
}
413415

414416
// All structs
@@ -1960,7 +1962,13 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
19601962
}
19611963
else
19621964
{
1963-
auto v8_class = ExportClass(Object->GetClass());
1965+
auto Class = Object->GetClass();
1966+
if (Class->ClassGeneratedBy && Cast<ULevel>(Class->ClassGeneratedBy->GetOuter()))
1967+
{
1968+
return Undefined(isolate_);
1969+
}
1970+
1971+
auto v8_class = ExportClass(Class);
19641972
auto arg = I.External(Object);
19651973
Handle<Value> args[] = { arg };
19661974

0 commit comments

Comments
 (0)