public static LinearCurveConfig CreateFromString(string values) { LinearCurveConfig retVal = new LinearCurveConfig(); var chunks = values.Split(new[] { ' ', ',', '[', ']' }, StringSplitOptions.RemoveEmptyEntries); if (chunks.Length < 2) { throw new FormatException("LinearCurveConfig expects at least two 2D points"); } for (int i = 0; i < chunks.Length; i += 2) { var xStr = chunks[i]; var yStr = chunks[i + 1]; var point = new CurvePoint() { x = float.Parse(xStr, CultureInfo.InvariantCulture), y = float.Parse(yStr, CultureInfo.InvariantCulture) }; retVal.Points.Add(point); } return(retVal); }
public static LinearCurveConfig LinearCurve(this GameConfigUpgradable thiz, string key, int level, LinearCurveConfig defaultValue = null) { var values = thiz.RawValue(key, level); if (!string.IsNullOrEmpty(values)) { return(LinearCurveConfig.CreateFromString(values)); } return(defaultValue); }