コード例 #1
0
        /// <summary>
        /// Tries to convert a character to a corresponding enum type value.
        /// </summary>
        /// <param name="c">Character to convert</param>
        /// <param name="type">Resulting enum type, if convertable</param>
        /// <returns>True if character was able to be converted to an enum value</returns>
        public static bool TryGetGameSettingType(char c, out GameSettingType type)
        {
            switch (c)
            {
            case IntChar:
                type = GameSettingType.Int;
                return(true);

            case StringChar:
                type = GameSettingType.String;
                return(true);

            case FloatChar:
                type = GameSettingType.Float;
                return(true);

            case BoolChar:
                type = GameSettingType.Bool;
                return(true);

            case UIntChar:
                type = GameSettingType.UInt;
                return(true);

            default:
                type = default;
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Adjusts a string to be GameSetting compliant with the given type.
        /// This means having the correct character at the start of the string.
        /// </summary>
        /// <param name="input">String to check and correct</param>
        /// <param name="type">Game type to conform to</param>
        /// <returns>GameSetting compliant EditorID string</returns>
        public static string CorrectEDID(string input, GameSettingType type)
        {
            char triggerChar = type.GetChar();

            input = input.Trim();
            if (input.Length == 0)
            {
                return(string.Empty + triggerChar);
            }
            else if (!triggerChar.Equals(input[0]))
            {
                return(triggerChar + input);
            }
            return(input);
        }
コード例 #3
0
        /// <summary>
        /// Tries to convert a character to a corresponding enum type value.
        /// </summary>
        /// <param name="type">The type enum to convert</param>
        /// <returns>Character paired with the type enum</returns>
        public static char GetChar(this GameSettingType type)
        {
            switch (type)
            {
            case GameSettingType.Float:
                return(FloatChar);

            case GameSettingType.Int:
                return(IntChar);

            case GameSettingType.String:
                return(StringChar);

            case GameSettingType.Bool:
                return(BoolChar);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #4
0
 public GameSetting(string name, GameSettingType type) : this(new GameSettingKey(name), type)
 {
 }
コード例 #5
0
 public GameSetting(GameSettingKey key, GameSettingType type) : base(key)
 {
     Type = type;
 }