Skip to content

Commit

Permalink
Add UEContext to carry context built from Unreal Engine needed for bl…
Browse files Browse the repository at this point in the history
…ueprint generation
  • Loading branch information
trumank committed Aug 31, 2022
1 parent 90d019b commit 193801e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
5 changes: 4 additions & 1 deletion KismetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,14 @@ public override int GetHashCode() {
}
}

UEContext Context;

UAsset Asset;
TextWriter Output;
Dictionary<Address, KismetExpression> ExpressionMap;

public BlueprintGenerator(UAsset asset) {
public BlueprintGenerator(UEContext context, UAsset asset) {
Context = context;
Asset = asset;
Output = Console.Out;
ExpressionMap = new Dictionary<Address, KismetExpression>();
Expand Down
8 changes: 6 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class MergeFunctionsOptions {

[Verb("generate", HelpText = "Generate blueprint asset")]
class GenerateOptions {
[Value(0, Required = true, MetaName = "source", HelpText = "Path of the source asset")]
[Value(0, Required = true, MetaName = "context", HelpText = "Path to context JSON object generated by BPGen plugin (kismet.json in UE project directory)")]
public string ContextPath { get; set; }
[Value(1, Required = true, MetaName = "source", HelpText = "Path of the source asset")]
public string SourcePath { get; set; }
//[Value(1, Required = true, MetaName = "dest", HelpText = "Path of the dest asset")]
//public string DestPath { get; set; }
Expand Down Expand Up @@ -213,8 +215,10 @@ static int MergeFunctions(MergeFunctionsOptions opts) {
return 0;
}
static int Generate(GenerateOptions opts) {
var context = UEContext.FromFile(opts.ContextPath);

UAsset source = new UAsset(opts.SourcePath, UE4Version.VER_UE4_27);
var generator = new BlueprintGenerator(source);
var generator = new BlueprintGenerator(context, source);
generator.Generate();
return 0;
}
Expand Down
42 changes: 42 additions & 0 deletions UEContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace KismetAnalyzer;

using Newtonsoft.Json;

public class UEContext {
[JsonProperty("classes")]
public Dictionary<string, UEClass> Classes { get; init; }

public static UEContext FromFile(string path) {
using (StreamReader r = new StreamReader(path)) {
return JsonConvert.DeserializeObject<UEContext>(r.ReadToEnd());
}
}
}

public class UEClass {
[JsonProperty("functions")]
public Dictionary<string, UEFunction> Functions { get; init; }
}

public class UEFunction {
[JsonProperty("pure")]
public bool Pure;
[JsonProperty("pins")]
public IEnumerable<UEPin> Pins { get; init; }
}

public class UEPin {
[JsonProperty("name")]
public string Name;
[JsonProperty("isRef")]
public bool IsRef;
[JsonProperty("direction")]
public UEPinDirection Direction;
}

public enum UEPinDirection {
[JsonProperty("input")]
Input,
[JsonProperty("output")]
Output,
}

0 comments on commit 193801e

Please sign in to comment.