// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // Standard Libraries using System; namespace AWS.GameKit.Editor.Models { /// /// A generic feature setting.

/// /// Feature settings are configured by the user through the AWS GameKit Settings window. Each feature has it's own settings to configure.

/// /// Feature settings are applied during deployment in the form of CloudFormation template parameters.

///
/// The data type of this feature setting. This type is used to convert to/from a string when communicating with the AWS GameKit C++ SDK. [Serializable] public abstract class FeatureSetting : IFeatureSetting { public string VariableName { get; } /// /// The current value of this setting as configured in the UI. /// public T CurrentValue; /// /// The default value that will be used for this setting if the user does not change it. /// public T DefaultValue { get; } public string CurrentValueString => ValueToString(CurrentValue); public string DefaultValueString => ValueToString(DefaultValue); /// /// Create a new instance of FeatureSetting which has it's current value set to the default value. /// /// Thrown when any constructor argument is null. protected FeatureSetting(string variableName, T defaultValue) { VariableName = variableName ?? throw new ArgumentNullException(nameof(variableName)); DefaultValue = defaultValue ?? throw new ArgumentNullException(nameof(defaultValue)); CurrentValue = defaultValue; } /// /// Set the CurrentValue to a new value specified by a string. /// /// The new current value. /// Thrown when the value argument is null. public void SetCurrentValueFromString(string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } CurrentValue = ValueFromString(value); } /// /// Convert the provided value to its string representation. /// /// The value to convert to a string. /// A string representation of the provided value. protected abstract string ValueToString(T value); /// /// Convert the provided string to a type T object. /// /// The string to convert to type T. /// A type T object created from the provided string. protected abstract T ValueFromString(string value); } }