AcManager.Tools.Objects.WeatherObject.TryToDetectWeatherTypeById C# (CSharp) Method

TryToDetectWeatherTypeById() private static method

private static TryToDetectWeatherTypeById ( string id ) : WeatherType
id string
return WeatherType
        private static WeatherType TryToDetectWeatherTypeById(string id) {
            var l = id.ToLower();

            if (l.Contains(@"fog")) {
                if (l.Contains(@"light")) return WeatherType.Mist;
                return WeatherType.Fog;
            }

            if (l.Contains(@"drizzle")) {
                if (l.Contains(@"light")) return WeatherType.LightDrizzle;
                if (l.Contains(@"heavy")) return WeatherType.HeavyDrizzle;
                return WeatherType.Drizzle;
            }

            if (l.Contains(@"rain")) {
                if (l.Contains(@"light")) return WeatherType.LightRain;
                if (l.Contains(@"heavy")) return WeatherType.HeavyRain;
                return WeatherType.Rain;
            }

            if (l.Contains(@"snow")) {
                if (l.Contains(@"light")) return WeatherType.LightSnow;
                if (l.Contains(@"heavy")) return WeatherType.HeavySnow;
                return WeatherType.Snow;
            }

            if (l.Contains(@"clouds")) {
                if (l.Contains(@"light")) return WeatherType.ScatteredClouds;
                if (l.Contains(@"heavy")) return WeatherType.OvercastClouds;
                if (l.Contains(@"mid") || l.Contains(@"few")) return WeatherType.FewClouds;
                return WeatherType.BrokenClouds;
            }

            if (l.Contains(@"few")) return WeatherType.FewClouds;
            if (l.Contains(@"overcast")) return WeatherType.OvercastClouds;
            if (l.Contains(@"scattered")) return WeatherType.ScatteredClouds;
            if (l.Contains(@"cold")) return WeatherType.Cold;
            if (l.Contains(@"hot")) return WeatherType.Hot;

            if (l.Contains(@"clear")) {
                if (l.Contains(@"mid")) return WeatherType.FewClouds;
                return WeatherType.Clear;
            }
            
            return WeatherType.None;
        }

Usage Example

            public bool WeatherIcon(Table v)
            {
                var icons = _data?.GetKeys(GetText(v, "icons") ?? "").ToList();

                if (icons == null || icons.Count == 0)
                {
                    Logging.Warning($"Icons not found: {GetText(v, "icons")}");
                    return(false);
                }

                if (_texturesContext.Weather == null)
                {
                    return(false);
                }

                var weatherType = _texturesContext.Weather.Type;

                if (weatherType == WeatherType.None)
                {
                    weatherType = WeatherObject.TryToDetectWeatherTypeById(_texturesContext.Weather.Id);
                }

                var availableTypes = icons.Select(x => new {
                    Type     = Enum.TryParse <WeatherType>(Regex.Replace(x, @"^.*/|\.\w+$|\W", ""), true, out var type) ? type : WeatherType.None,
                    FileName = x
                }).ToList();