public static Biome GetBiome(ScienceSubject subject) { if (subject == null || ResearchAndDevelopment.Instance == null) { return(null); } Match m = Regex.Match(subject.id, @"@([A-Z][\w]+?)([A-Z].*)"); string celestialBody = m.Groups[1].Value; string sitAndBiome = m.Groups[2].Value; string biome = ""; while (!string.IsNullOrEmpty(sitAndBiome)) { try { Enum.Parse(typeof(ExperimentSituations), sitAndBiome); break; } catch { m = Regex.Match(sitAndBiome, @"(.*)([A-Z][\w&]*)$$"); sitAndBiome = m.Groups[1].Value; biome = m.Groups[2].Value + biome; } } return(string.IsNullOrEmpty(biome) ? null : new Biome(ConfigNodeUtil.ParseCelestialBodyValue(celestialBody), biome)); }
internal override CelestialBody ParseIdentifier(Token token) { if (token.sval.Equals("null", StringComparison.CurrentCultureIgnoreCase)) { return(null); } return(ConfigNodeUtil.ParseCelestialBodyValue(token.sval)); }
public static CelestialBody GetCelestialBody(ScienceSubject subject) { if (subject == null || ResearchAndDevelopment.Instance == null) { return(null); } Match m = Regex.Match(subject.id, @"@([A-Z][\w]+?)([A-Z].*)"); string celestialBody = m.Groups[1].Value; return(string.IsNullOrEmpty(celestialBody) ? null : ConfigNodeUtil.ParseCelestialBodyValue(celestialBody)); }
public override CelestialBody ParseIdentifier(Token token) { // Try to parse more, as celestibla body names can have spaces Match m = Regex.Match(expression, @"^((?>\s*[\w\d]+)+).*"); string identifier = m.Groups[1].Value; expression = (expression.Length > identifier.Length ? expression.Substring(identifier.Length) : ""); identifier = token.sval + identifier; if (identifier.Equals("null", StringComparison.CurrentCultureIgnoreCase)) { return(null); } return(ConfigNodeUtil.ParseCelestialBodyValue(identifier)); }
public override CelestialBody ParseIdentifier(Token token) { // Try to parse more, as celestial body names can have spaces Match m = Regex.Match(expression, @"^((?>\s*[\w\d]+)+).*"); string identifier = m.Groups[1].Value; expression = (expression.Length > identifier.Length ? expression.Substring(identifier.Length) : ""); identifier = token.sval + identifier; if (identifier.Equals("null", StringComparison.CurrentCultureIgnoreCase)) { return(null); } try { return(ConfigNodeUtil.ParseCelestialBodyValue(identifier)); } // Treat invalid CBs as null, improves compatibility with planet packs catch (ArgumentException) { return(null); } }