You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
[FYI] Leon.Huang Original CL Desc ----------------------------------------------------------------- Unreal Build Tool: Update PluginDescriptor to have parity with FPluginDescriptor in terms of handling custom JSON fields. The order in which the original fields are written to disk is preserved. When saving the PluginDescriptor to disk, the same order is followed and any new entries are added to the end of the plugin file. Note: PluginDescriptor.Save and PluginDescriptor.Save2 will exist concurrently for now. There are still parts of UBT that use PluginDescriptor.Write and the refactor to create a unified Save function will come later as a lot of testing still needs to be done. JsonObject: - Introduced AddOrSetFieldValue() methods overloaded on value types to add/set fields in JsonObject. - Changed the underlying data structure of JsonObject from Dictionary<string,Object?> to OrderedDictionary to guarantee that order of all .uplugin fields (default and custom) are preserved - Made the JsonObject constructor that takes an OrderedDictionary private to ensure type safety of values passed to JsonObject - Introduced ToJsonString() for JsonObject that serializes the JsonObject to match the formatting of .uplugin IMPORTANT: The ToJsonString() method uses the JavaScriptEncoder.UnsafeRelaxedJsonEscaping encoder for Utf8JsonWriter. This allows +,<,>,&,` etc characters to be written properly for .uplugins. As per MS docs, with this encoding, none of the contents should be written to HTML or a script. - Introduced JsonObjectTests that unit tested JsonObject to ensure previous behavior was maintained. PluginDescriptor - Added a JsonObject field that acts as the cache of all fields that were read from a file or parsed from a json string. - Cached JsonObject records the order of all fields that were read and captures custom fields in the .uplugin - Introduced Save2(), the new save algorithm that writes all fields (default and custom) to disk. - Deleted the private default constructor because it didn't seem to be used anywhere. - Introduced PluginDescriptorTests to ensure previous behavior is maintained. In particular when dealing with a .uplugin with only default fields, results of Save() and Save2() are the same. Descriptor Files: - Introduced ToJsonObject() methods to replace the previous JsonWriter patterns of writing the descriptor data. - Introduced the UpdateJsonObject pattern which mimics the old WriteArray pattern of writing data to a JsonWriter. #rb: Mark.Winter, Joe.Kirchoff #jira: none #test: Developed this in a TDD style with unit tests for all the major functions. Also reviewed output of created .uplugins and diffed them. [CL 26111662 by leon huang in ue5-main branch]
113 lines
2.6 KiB
C#
113 lines
2.6 KiB
C#
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
using System.Diagnostics;
|
|
using EpicGames.Core;
|
|
|
|
namespace UnrealBuildTool
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public enum LocalizationTargetDescriptorLoadingPolicy
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
Never,
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
Always,
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
Editor,
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
Game,
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
PropertyNames,
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
ToolTips,
|
|
};
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[DebuggerDisplay("Name={Name}")]
|
|
public class LocalizationTargetDescriptor
|
|
{
|
|
/// <summary>
|
|
/// Name of this target
|
|
/// </summary>
|
|
public readonly string Name;
|
|
|
|
/// <summary>
|
|
/// When should the localization data associated with a target should be loaded?
|
|
/// </summary>
|
|
public LocalizationTargetDescriptorLoadingPolicy LoadingPolicy;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="InName">Name of the target</param>
|
|
/// <param name="InLoadingPolicy">When should the localization data associated with a target should be loaded?</param>
|
|
public LocalizationTargetDescriptor(string InName, LocalizationTargetDescriptorLoadingPolicy InLoadingPolicy)
|
|
{
|
|
Name = InName;
|
|
LoadingPolicy = InLoadingPolicy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructs a LocalizationTargetDescriptor from a Json object
|
|
/// </summary>
|
|
/// <param name="InObject"></param>
|
|
/// <returns>The new localization target descriptor</returns>
|
|
public static LocalizationTargetDescriptor FromJsonObject(JsonObject InObject)
|
|
{
|
|
return new LocalizationTargetDescriptor(InObject.GetStringField("Name"), InObject.GetEnumField<LocalizationTargetDescriptorLoadingPolicy>("LoadingPolicy"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write this target to a JsonWriter
|
|
/// </summary>
|
|
/// <param name="Writer">Writer to output to</param>
|
|
void Write(JsonWriter Writer)
|
|
{
|
|
Writer.WriteObjectStart();
|
|
Writer.WriteValue("Name", Name);
|
|
Writer.WriteValue("LoadingPolicy", LoadingPolicy.ToString());
|
|
Writer.WriteObjectEnd();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write an array of target descriptors
|
|
/// </summary>
|
|
/// <param name="Writer">The Json writer to output to</param>
|
|
/// <param name="Name">Name of the array</param>
|
|
/// <param name="Targets">Array of targets</param>
|
|
public static void WriteArray(JsonWriter Writer, string Name, LocalizationTargetDescriptor[]? Targets)
|
|
{
|
|
if (Targets != null && Targets.Length > 0)
|
|
{
|
|
Writer.WriteArrayStart(Name);
|
|
foreach (LocalizationTargetDescriptor Target in Targets)
|
|
{
|
|
Target.Write(Writer);
|
|
}
|
|
Writer.WriteArrayEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|