// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; namespace EpicGames.BuildGraph { /// /// Represents a graph option. These are expanded during preprocessing, but are retained in order to display help messages. /// public abstract class BgOptionDef { /// /// Name of this option /// public string Name { get; } /// /// Label for the option in the dashboard /// public string? Label { get; set; } /// /// Description for this option /// public string? Description { get; set; } /// /// Constructor /// /// The name of this option protected BgOptionDef(string name) { Name = name; } /// /// Returns the default argument value /// /// Default argument value public abstract string? GetDefaultArgument(); /// /// Returns a name of this option for debugging /// /// Name of the option public override string ToString() { return Name; } } /// /// Definition of a boolean option /// [BgObject(typeof(BgBoolOptionSerializer))] public class BgBoolOptionDef : BgOptionDef { /// /// Default value for the option /// public bool DefaultValue { get; set; } /// /// Constructor /// /// The name of this option public BgBoolOptionDef(string name) : base(name) { } /// public override string? GetDefaultArgument() => DefaultValue.ToString(); } /// /// Serializer for bool options /// class BgBoolOptionSerializer : BgObjectSerializer { /// public override BgBoolOptionDef Deserialize(BgObjectDef obj) { BgBoolOptionDef option = new BgBoolOptionDef(obj.Get(x => x.Name, null!)); obj.CopyTo(option); return option; } } /// /// Definition of an integer option /// [BgObject(typeof(BgIntOptionSerializer))] public class BgIntOptionDef : BgOptionDef { /// /// Default value for the option /// public int DefaultValue { get; set; } /// /// Minimum allowed value /// public int? MinValue { get; set; } /// /// Maximum allowed value /// public int? MaxValue { get; set; } /// /// Constructor /// /// The name of this option public BgIntOptionDef(string name) : base(name) { } /// public override string? GetDefaultArgument() => DefaultValue.ToString(); } /// /// Serializer for int options /// class BgIntOptionSerializer : BgObjectSerializer { /// public override BgIntOptionDef Deserialize(BgObjectDef obj) { BgIntOptionDef option = new BgIntOptionDef(obj.Get(x => x.Name, null!)); obj.CopyTo(option); return option; } } /// /// Style for a string option /// public enum BgStringOptionStyle { /// /// Free-form text entry /// Text, /// /// List of options /// DropList, } /// /// Definition of a string option /// [BgObject(typeof(BgStringOptionSerializer))] public class BgStringOptionDef : BgOptionDef { /// /// Default value for the option /// public string DefaultValue { get; set; } = String.Empty; /// /// Style for this option /// public BgStringOptionStyle Style { get; } /// /// Regex for validating values for the option /// public string? Pattern { get; set; } /// /// Message to display if validation fails /// public string? PatternFailed { get; set; } /// /// List of values to choose from /// public List? Values { get; set; } /// /// Matching list of descriptions for each value /// public List? ValueDescriptions { get; set; } /// /// Constructor /// /// Name of the option public BgStringOptionDef(string name) : base(name) { } /// public override string? GetDefaultArgument() => DefaultValue; } /// /// Serializer for string options /// class BgStringOptionSerializer : BgObjectSerializer { /// public override BgStringOptionDef Deserialize(BgObjectDef obj) { BgStringOptionDef option = new BgStringOptionDef(obj.Get(x => x.Name, null!)); obj.CopyTo(option); return option; } } /// /// Style for a list option /// public enum BgListOptionStyle { /// /// List of checkboxes /// CheckList = 0, /// /// Tag picker /// TagPicker = 1, } /// /// A list option definition /// [BgObject(typeof(BgListOptionSerializer))] public class BgListOptionDef : BgOptionDef { /// /// Style for this list box /// public BgListOptionStyle Style { get; } /// /// Default value for the option /// public string? DefaultValue { get; set; } /// /// List of values to choose from /// public List? Values { get; set; } /// /// Matching list of descriptions for each value /// public List? ValueDescriptions { get; set; } /// /// Constructor /// /// Name of the option public BgListOptionDef(string name) : base(name) { } /// public override string? GetDefaultArgument() => DefaultValue; } /// /// Serializer for string options /// class BgListOptionSerializer : BgObjectSerializer { /// public override BgListOptionDef Deserialize(BgObjectDef obj) { BgListOptionDef option = new BgListOptionDef(obj.Get(x => x.Name, null!)); obj.CopyTo(option); return option; } } }