-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
668371c
commit f2270bb
Showing
6 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...age/Runtime/CrashKonijn.Goap.Runtime/Classes/Validators/DuplicateTargetSensorValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Linq; | ||
using CrashKonijn.Goap.Core; | ||
|
||
namespace CrashKonijn.Goap.Runtime | ||
{ | ||
public class DuplicateTargetSensorValidator : IValidator<IAgentTypeConfig> | ||
{ | ||
public void Validate(IAgentTypeConfig config, IValidationResults results) | ||
{ | ||
var provided = this.GetTargetSensorKeys(config).Concat(this.GetMultiSensorKeys(config)); | ||
var duplicates = provided | ||
.GroupBy(x => x) | ||
.Where(x => x.Count() > 1) | ||
.Select(x => x.Key) | ||
.ToArray(); | ||
|
||
if (!duplicates.Any()) | ||
return; | ||
|
||
results.AddWarning($"Duplicate target sensor keys: {string.Join(", ", duplicates)}"); | ||
} | ||
|
||
private string[] GetTargetSensorKeys(IAgentTypeConfig agentTypeConfig) | ||
{ | ||
return agentTypeConfig.TargetSensors | ||
.Where(x => x.Key != null) | ||
.Select(x => x.Key.Name) | ||
.ToArray(); | ||
} | ||
|
||
private string [] GetMultiSensorKeys(IAgentTypeConfig agentTypeConfig) | ||
{ | ||
var temp = new ClassResolver().Load<IMultiSensor, IMultiSensorConfig>(agentTypeConfig.MultiSensors); | ||
|
||
return temp | ||
.SelectMany(x => x.GetKeys()) | ||
.Select(x => x.Name) | ||
.ToArray(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...untime/CrashKonijn.Goap.Runtime/Classes/Validators/DuplicateTargetSensorValidator.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Validators/DuplicateWorldSensorValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Linq; | ||
using CrashKonijn.Goap.Core; | ||
|
||
namespace CrashKonijn.Goap.Runtime | ||
{ | ||
public class DuplicateWorldSensorValidator : IValidator<IAgentTypeConfig> | ||
{ | ||
public void Validate(IAgentTypeConfig config, IValidationResults results) | ||
{ | ||
var provided = this.GetWorldSensorKeys(config).Concat(this.GetMultiSensorKeys(config)); | ||
var duplicates = provided | ||
.GroupBy(x => x) | ||
.Where(x => x.Count() > 1) | ||
.Select(x => x.Key) | ||
.ToArray(); | ||
|
||
if (!duplicates.Any()) | ||
return; | ||
|
||
results.AddWarning($"Duplicate world sensor keys: {string.Join(", ", duplicates)}"); | ||
} | ||
|
||
private string[] GetWorldSensorKeys(IAgentTypeConfig agentTypeConfig) | ||
{ | ||
return agentTypeConfig.WorldSensors | ||
.Where(x => x.Key != null) | ||
.Select(x => x.Key.Name) | ||
.Distinct() | ||
.ToArray(); | ||
} | ||
|
||
private string [] GetMultiSensorKeys(IAgentTypeConfig agentTypeConfig) | ||
{ | ||
var temp = new ClassResolver().Load<IMultiSensor, IMultiSensorConfig>(agentTypeConfig.MultiSensors); | ||
|
||
return temp | ||
.SelectMany(x => x.GetKeys()) | ||
.Select(x => x.Name) | ||
.Distinct() | ||
.ToArray(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...Runtime/CrashKonijn.Goap.Runtime/Classes/Validators/DuplicateWorldSensorValidator.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.