public override ValidationResult Validate() { var result = new ValidationResult(DefinitionBase.CreateValidationSourceString(this)); if (string.IsNullOrWhiteSpace(Name)) { result.Errors.Add(new ValidationError($"{nameof(Name)} is null or whitespace.")); } //Disabling this check for rooted, because at the point this is ran, InvasionManager may not have been set yet, causing //an NRE to get logged. //var rooted = Path.Combine(InvasionManager.Instance.BasePath, ScriptPath ?? ""); //if( ScriptPath != null && !File.Exists(rooted) ) //{ // //throw new FormatException($"{nameof(ScriptPath)} points to an invalid script file."); // result.AddError($"{nameof(ScriptPath)} points to an invalid script file.", FilePath, LineNumber, LinePosition); //} if (NpcPointValues == null) { result.Errors.Add(new ValidationError($"{nameof(NpcPointValues)} is null.")); } if (NpcPointValues.Count == 0) { result.Errors.Add(new ValidationError($"{nameof(NpcPointValues)} must not be empty.")); } if (NpcPointValues.Any(kvp => kvp.Value <= 0)) { result.Errors.Add(new ValidationError($"{nameof(NpcPointValues)} must contain positive values.")); } if (CompletedMessage == null) { result.Errors.Add(new ValidationError($"{nameof(CompletedMessage)} is null.")); } if (Waves == null) { result.Errors.Add(new ValidationError($"{nameof(Waves)} is null.")); } if (Waves.Count == 0) { result.Errors.Add(new ValidationError($"{nameof(Waves)} must not be empty.")); } foreach (var wave in Waves) { var waveResult = wave.Validate(); result.Children.Add(waveResult); } return(result); }
public override ValidationResult Validate() { var result = new ValidationResult(DefinitionBase.CreateValidationSourceString(this)); if (string.IsNullOrWhiteSpace(Name)) { result.Errors.Add(new ValidationError($"{nameof(Name)} is null or whitespace.")); } if (int.TryParse(Name, out _)) { result.Errors.Add(new ValidationError($"{nameof(Name)} cannot be a number.")); } //if (BaseType < -65) //{ // throw new FormatException($"{nameof(BaseType)} is too small."); //} if (BaseType >= Main.maxProjectileTypes) { result.Errors.Add(new ValidationError($"{nameof(BaseType)} is greater than {Main.maxProjectileTypes}.")); } if (ScriptPath != null && !File.Exists(Path.Combine("npcs", ScriptPath))) { result.Errors.Add(new ValidationError($"{nameof(ScriptPath)} points to invalid script file, '{ScriptPath}'.")); } if (BaseOverride != null) { var baseResult = BaseOverride.Validate(); baseResult.Source = result.Source; result.Children.Add(baseResult); } else { result.Errors.Add(new ValidationError($"{nameof(BaseOverride)} is null.")); } return(result); }
public override ValidationResult Validate() { var result = new ValidationResult(DefinitionBase.CreateValidationSourceString(this)); if (string.IsNullOrWhiteSpace(Name)) { result.Errors.Add(new ValidationError($"{nameof(Name)} is null or whitespace.")); } if (int.TryParse(Name, out _)) { result.Errors.Add(new ValidationError($"{nameof(Name)} cannot be a number.")); } if (BaseType < -65) { result.Errors.Add(new ValidationError($"{nameof(BaseType)} is too small. Value must be greater than -65.")); } if (BaseType >= Main.maxNPCTypes) { result.Errors.Add(new ValidationError($"{nameof(BaseType)} is too large. Value must be less than {Main.maxNPCTypes}.")); } if (ScriptPath != null && !File.Exists(Path.Combine("npcs", ScriptPath))) { result.Errors.Add(new ValidationError($"{nameof(ScriptPath)} points to invalid script file, '{ScriptPath}'.")); } //BaseOverride if (_baseOverride != null) { var baseResult = _baseOverride.Validate(); baseResult.Source = result.Source; result.Children.Add(baseResult); } else { result.Errors.Add(new ValidationError("BaseOverride is null.")); } //Loot if (_loot != null) { var lootResult = _loot.Validate(); lootResult.Source = result.Source; result.Children.Add(lootResult); } else { result.Errors.Add(new ValidationError("Loot is null.")); } //Spawning if (_spawning != null) { var spawnResult = _spawning.Validate(); spawnResult.Source = result.Source; result.Children.Add(spawnResult); } else { result.Errors.Add(new ValidationError("Spawning is null.")); } //var source = ""; //if (!string.IsNullOrWhiteSpace(Name)) // source = $"{FilePath} {LineNumber},{LinePosition}: in '{Name}'"; //else // source = $"{FilePath} {LineNumber},{LinePosition}:"; //result.Children.Add(baseResult); //baseResult.SetSources(source); //result.SetSources(source); return(result); }