Skip to content

Commit

Permalink
add strict JBP export mode
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed Feb 22, 2022
1 parent c93dbfb commit c61f6e0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
28 changes: 24 additions & 4 deletions BlueprintExplorer/BubblePrints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ internal static void Install()
{
var raw = File.ReadAllText(SettingsPath);
Settings = JsonSerializer.Deserialize<SettingsProxy>(raw);
if (Settings.StrictJsonForEditor && Settings.EditorExportMode == ExportMode.Bubble)
{
Settings.EditorExportMode = ExportMode.Json;
SaveSettings();
}

}
}

internal static void SetWrathPath()
{
var path = BubblePrints.Settings.WrathPath;
var path = Settings.WrathPath;
if (path == null || path.Length == 0 || !File.Exists(Path.Combine(path, "Wrath.exe")))
{
var folderBrowser = new FolderBrowserDialog();
Expand All @@ -69,8 +75,8 @@ internal static void SetWrathPath()
}
if (!errored)
{
BubblePrints.Settings.WrathPath = path;
BubblePrints.SaveSettings();
Settings.WrathPath = path;
SaveSettings();
}
}

Expand All @@ -82,7 +88,14 @@ internal static void SetWrathPath()
public static string SettingsPath => MakeDataPath("settings.json");


internal static void SaveSettings() => File.WriteAllText(BubblePrints.SettingsPath, JsonSerializer.Serialize(BubblePrints.Settings));
internal static void SaveSettings() => File.WriteAllText(SettingsPath, JsonSerializer.Serialize(Settings));
}

public enum ExportMode
{
Bubble,
Json,
JBP,
}

public class SettingsProxy
Expand Down Expand Up @@ -128,8 +141,15 @@ public SettingsProxy(SettingsProxy settings)

[Description("If true, the external editor will display strict json. If false, the external editor will display human-friendly text")]
[DisplayName("Generate json for 'Open in Editor'")]
[Browsable(false)]
public bool StrictJsonForEditor { get; set; } = true;

[Description("Bubble: easy-to-read text file, Json: strict json with some fields made more human readable, JBP: OwlcatTemplate compatible json")]
[DisplayName("Export Mode for 'Open in Editor'")]
[DefaultValue(ExportMode.Bubble)]
public ExportMode EditorExportMode { get; set; } = ExportMode.Bubble;


[Description("If true, the blueprint view will expand all fields automatically")]
[DisplayName("Expand all properties")]
public bool EagerExpand { get; set; } = true;
Expand Down
13 changes: 12 additions & 1 deletion BlueprintExplorer/TextExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ class ElementWriteState
}
public static void Export(TextWriter stream, BlueprintHandle blueprint)
{
bool json = BubblePrints.Settings.StrictJsonForEditor;
if (BubblePrints.Settings.EditorExportMode == ExportMode.JBP)
{
stream.WriteLine("{");
stream.WriteLine($"\"AssetId\": \"${blueprint.GuidText}\"");
stream.WriteLine("\"Data\":");
stream.Write(blueprint.Raw);
stream.WriteLine();
stream.WriteLine("}");
return;
}

bool json = BubblePrints.Settings.EditorExportMode == ExportMode.Json;
int level = 0;
Stack<ElementWriteState> stack = new();
stack.Push(new() { IsObj = true });
Expand Down

0 comments on commit c61f6e0

Please sign in to comment.