-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REG-2230, REG-2231] Implement Validations Within Segments #370
Changes from 8 commits
036150b
2e48658
20ac93f
38c32db
03a34e4
5b0c091
bb38d2c
55389f4
c6012dc
a14babe
0dbbc20
df4ebdc
c54475d
ccf2ff3
7bc3d56
a93f4b1
d23b43f
b508fbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using RegressionGames.Validation; | ||
using StateRecorder.BotSegments.Models.SegmentValidations; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace RegressionGames.Editor.Validation | ||
{ | ||
public class RGValidationPane : EditorWindow | ||
{ | ||
private ScrollView _mainScrollPane; | ||
|
||
[MenuItem("Regression Games/Validation Results")] | ||
public static void ShowMyEditor() | ||
{ | ||
// This method is called when the user selects the menu item in the Editor | ||
EditorWindow wnd = GetWindow<RGValidationPane>(); | ||
wnd.titleContent = new GUIContent("RG Validation Results"); | ||
wnd.Focus(); | ||
} | ||
|
||
void CreateGUI() | ||
{ | ||
|
||
_mainScrollPane = new ScrollView(ScrollViewMode.VerticalAndHorizontal); | ||
rootVisualElement.Add(_mainScrollPane); | ||
|
||
UpdateGUI(); | ||
|
||
} | ||
|
||
void UpdateGUI() | ||
{ | ||
|
||
_mainScrollPane.Clear(); | ||
UnsubscribeFromValidationEvents(); | ||
|
||
var validationScripts = FindObjectsOfType<RGValidateBehaviour>(); | ||
|
||
foreach (var validationScript in validationScripts) | ||
{ | ||
var scriptContainer = new VisualElement(); | ||
scriptContainer.Add(new Label("Suite: " + validationScript.GetType().Name)); | ||
_mainScrollPane.Add(scriptContainer); | ||
|
||
validationScript.OnValidationsUpdated += UpdateGUI; | ||
|
||
foreach (var validator in validationScript.Validators) | ||
{ | ||
var validatorContainer = new VisualElement(); | ||
validatorContainer.style.paddingLeft = 20; | ||
|
||
scriptContainer.Add(validatorContainer); | ||
|
||
var testText = ""; | ||
Color? color = null; | ||
|
||
switch (validator.Status) | ||
{ | ||
case SegmentValidationStatus.UNKNOWN: | ||
testText += "? "; | ||
break; | ||
case SegmentValidationStatus.PASSED: | ||
// If pass, show a green checkmark | ||
testText += "PASS "; | ||
color = Color.green; | ||
break; | ||
case SegmentValidationStatus.FAILED: | ||
testText += "FAIL "; | ||
color = Color.red; | ||
break; | ||
} | ||
|
||
testText += validator.Method.Name; | ||
var testLabel = new Label(testText); | ||
if (color != null) | ||
{ | ||
testLabel.style.color = color.Value; | ||
} | ||
|
||
validatorContainer.Add(testLabel); | ||
} | ||
} | ||
|
||
} | ||
|
||
private void UnsubscribeFromValidationEvents() | ||
{ | ||
var validationScripts = FindObjectsOfType<RGValidateBehaviour>(); | ||
foreach (var validationScript in validationScripts) | ||
{ | ||
validationScript.OnValidationsUpdated -= UpdateGUI; | ||
} | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using StateRecorder.BotSegments.Models.SegmentValidations; | ||
|
||
namespace RegressionGames.StateRecorder.BotSegments.JsonConverters | ||
{ | ||
public class ScriptSegmentValidationDataJsonConverter: JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return typeof(ScriptSegmentValidationData).IsAssignableFrom(objectType); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
JObject jObject = JObject.Load(reader); | ||
// ReSharper disable once UseObjectOrCollectionInitializer - easier to debug lines without this | ||
ScriptSegmentValidationData data = new(); | ||
data.classFullName = jObject.GetValue("classFullName").ToObject<string>(serializer); | ||
if (jObject.ContainsKey("apiVersion")) | ||
{ | ||
data.apiVersion = jObject.GetValue("apiVersion").ToObject<int>(serializer); | ||
} | ||
return data; | ||
} | ||
|
||
public override bool CanWrite => false; | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using RegressionGames.StateRecorder.BotSegments.Models; | ||
using RegressionGames.StateRecorder.BotSegments.Models.BotCriteria; | ||
using StateRecorder.BotSegments.Models; | ||
using StateRecorder.BotSegments.Models.SegmentValidations; | ||
|
||
namespace RegressionGames.StateRecorder.BotSegments.JsonConverters | ||
{ | ||
public class SegmentValidationJsonConverter: JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return typeof(SegmentValidation).IsAssignableFrom(objectType); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
JObject jObject = JObject.Load(reader); | ||
SegmentValidation validation = new(); | ||
validation.type = jObject["type"].ToObject<SegmentValidationType>(serializer); | ||
if (jObject.ContainsKey("apiVersion")) | ||
{ | ||
validation.apiVersion = jObject["apiVersion"].ToObject<int>(serializer); | ||
} | ||
IRGSegmentValidationData data = null; | ||
switch (validation.type) | ||
{ | ||
case SegmentValidationType.Script: | ||
data = jObject["data"].ToObject<ScriptSegmentValidationData>(serializer); | ||
break; | ||
default: | ||
throw new JsonSerializationException($"Unsupported SegmentValidation type: '{validation.type}'"); | ||
} | ||
|
||
validation.data = data; | ||
return validation; | ||
} | ||
|
||
public override bool CanWrite => false; | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related or relevant to the current PR... will remove in a moment, so you can ignore this for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been removed