Skip to content
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] Operate on BotSegmentLists so we can do validations there #374

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RGSegmentEntry : MonoBehaviour
* <summary>Indicates whether the Segment or Segment List is overridden by a local file.</summary>
*/
public bool isOverride;

/**
* UI component fields
*/
Expand All @@ -49,7 +49,7 @@ public class RGSegmentEntry : MonoBehaviour

[SerializeField]
public GameObject segmentListIndicatorComponent;

[SerializeField]
public GameObject overrideIndicator;

Expand Down Expand Up @@ -84,8 +84,8 @@ public void Start()
resourcePathComponent.gameObject.SetActive(false);
}
}
// set indicator that this Segment is being overriden by a local file, within a build

// set indicator that this Segment is being overriden by a local file, within a build
overrideIndicator.gameObject.SetActive(isOverride);

// assign values to the UI components
Expand Down Expand Up @@ -141,7 +141,8 @@ private void OnPlay()
}

// play the segment
playbackController.SetDataContainer(new BotSegmentsPlaybackContainer(segmentList.segments, new List<SegmentValidation>(), sessionId));
playbackController.SetDataContainer(new BotSegmentsPlaybackContainer(new List<BotSegmentList>() {segmentList}, new List<SegmentValidation>(), sessionId));

playbackController.Play();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using System.IO.Compression;
using System.Linq;
using Newtonsoft.Json;
using RegressionGames.StateRecorder.BotSegments.JsonConverters;
using RegressionGames.StateRecorder.BotSegments.Models;
using StateRecorder.BotSegments;

namespace RegressionGames.StateRecorder.BotSegments
{
Expand Down Expand Up @@ -66,9 +64,9 @@ public static IOrderedEnumerable<ZipArchiveEntry> OrderZipJsonEntries(IEnumerabl
return entries;
}

public static List<BotSegment> ParseBotSegmentZipFromSystemPath(string zipFilePath, out string sessionId)
public static List<BotSegmentList> ParseBotSegmentZipFromSystemPath(string zipFilePath, out string sessionId)
{
List<BotSegment> results = new();
List<BotSegmentList> results = new();

sessionId = null;

Expand Down Expand Up @@ -100,17 +98,7 @@ public static List<BotSegment> ParseBotSegmentZipFromSystemPath(string zipFilePa
break;
}

foreach (var botSegment in botSegmentList.segments)
{
botSegment.Replay_SegmentNumber = replayNumber++;

if (sessionId == null)
{
sessionId = botSegment.sessionId;
}

results.Add(botSegment);
}
results.Add(botSegmentList);
}
catch (Exception)
{
Expand All @@ -132,7 +120,16 @@ public static List<BotSegment> ParseBotSegmentZipFromSystemPath(string zipFilePa
sessionId = frameData.sessionId;
}

results.Add(frameData);
results.Add(new BotSegmentList()
{
segments = new List<BotSegment>()
{
frameData
},
name = "BotSegmentList for BotSegment - " + frameData.name,
description = "BotSegmentList for BotSegment - " + frameData.description,
validations = new()
});
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,71 @@ namespace RegressionGames.StateRecorder.BotSegments

public class BotSegmentsPlaybackContainer
{
private readonly List<BotSegment> _botSegments;

private readonly List<BotSegmentList> _botSegmentLists;
private int _botSegmentListIndex = 0;
private int _botSegmentIndex = 0;

/**
* A top-level set of validations to run for an entire sequence of segments
*/
public readonly List<SegmentValidation> Validations;

public readonly string SessionId;

public BotSegmentsPlaybackContainer(IEnumerable<BotSegment> segments, IEnumerable<SegmentValidation> validations, string sessionId = null)
public BotSegmentsPlaybackContainer(IEnumerable<BotSegmentList> segmentLists, IEnumerable<SegmentValidation> validations, string sessionId = null)
{
var replayNumber = 1; // 1 to align with the actual numbers in the recording
_botSegments = new(segments);
_botSegmentLists = new(segmentLists);
_botSegmentLists.ForEach(a => a.segments.ForEach(b => b.Replay_SegmentNumber = replayNumber++));
Validations = new(validations);
_botSegments.ForEach(a => a.Replay_SegmentNumber = replayNumber++);
this.SessionId = sessionId ?? Guid.NewGuid().ToString("n");
}

public void Reset()
{
// sets indexes back to 0
_botSegmentIndex = 0;
_botSegmentListIndex = 0;

// reset all the tracking flags
foreach (var botSegment in _botSegments)
// reset all the tracking flags in the segmentlists / segments
_botSegmentLists.ForEach(a =>
{
botSegment.ReplayReset();
}

a.segments.ForEach(b => b.ReplayReset());
a.validations.ForEach(b => b.ReplayReset());
});

// reset all the top-level validations
foreach (var validation in Validations)
{
validation.ReplayReset();
}
}

public BotSegment DequeueBotSegment()
{
if (_botSegmentIndex < _botSegments.Count)
{
return _botSegments[_botSegmentIndex++];
}

return null;
}

public BotSegment PeekBotSegment()
/**
* Returns the next bot segment to evaluate and also provides the current segmentList level validations
*/
public BotSegment DequeueBotSegment(out List<SegmentValidation> segmentListValidations)
{
if (_botSegmentIndex < _botSegments.Count)
while (_botSegmentListIndex < _botSegmentLists.Count)
{
// do not update index
return _botSegments[_botSegmentIndex];
var segmentList = _botSegmentLists[_botSegmentListIndex];
if (_botSegmentIndex < segmentList.segments.Count)
{
var segment = segmentList.segments[_botSegmentIndex++];
segmentListValidations = segmentList.validations;
return segment;
}
else
{
// move to the next segmentlist starting on the 0th segment in that list
_botSegmentIndex = 0;
++_botSegmentListIndex;
}

}

segmentListValidations = new List<SegmentValidation>();
return null;
}
}
Expand Down
Loading
Loading