예제 #1
0
        public static Keyframe FromSpec(string arg)
        {
            // No ( -> constant
            if (!arg.Contains('('))
            {
                return(new Keyframe
                {
                    Value = ParseValue(arg)
                });
            }

            var regexp = new Regex(@"^(.+)\((.+)\)$");
            var match  = regexp.Match(arg);

            if (!match.Success)
            {
                throw new ArgumentException("Invalid keyframe: " + arg);
            }

            var result = new Keyframe();

            if (match.Groups[2].Value.EndsWith("%"))
            {
                // Parse everything up to the percentage sign as the percentage of the emitter lifespan
                var val = match.Groups[2].Value;
                result.PositionPercentage = int.Parse(val.Substring(0, val.Length - 1));
            }
            else
            {
                result.PositionLifespan = VariableParam.ParseFloat(match.Groups[2].Value);
            }
            result.Value = ParseValue(match.Groups[1].Value);
            return(result);
        }
예제 #2
0
        /// <summary>
        ///     Vanilla ToEE particle systems contain keyframe values that are actually invalid: 100?200.
        ///     Apparently, designers tried to do random values inside of keyframes, but this actually
        ///     was never implemented and as such we skip it.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static float ParseValue(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                // TODO: Warn here...
                return(0);
            }

            var pos = value.IndexOf('?');

            if (pos != -1)
            {
                return(VariableParam.ParseFloat(value.Substring(0, pos)));
            }
            return(VariableParam.ParseFloat(value));
        }