55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System.Collections;
|
|
|
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
|
|
|
public class ScriptIterator : IEnumerable<ScriptContainer>
|
|
{
|
|
private readonly IReadOnlyList<IEnumerable<ScriptContainer>> _scripts;
|
|
|
|
public ScriptIterator(IReadOnlyList<IEnumerable<ScriptContainer>> scripts)
|
|
{
|
|
_scripts = scripts;
|
|
}
|
|
|
|
private IEnumerable<ScriptContainer> GetAsEnumerable()
|
|
{
|
|
foreach (var enumerable in _scripts)
|
|
{
|
|
if (enumerable is IScriptSet set)
|
|
{
|
|
// We can't assume that the set remains the same size, so we need to iterate through it
|
|
// with a for loop.
|
|
for (var j = 0; j < set.Count; j++)
|
|
{
|
|
var script = set.At(j);
|
|
// We can ignore empty scripts.
|
|
if (script.IsEmpty)
|
|
continue;
|
|
yield return script;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var script in enumerable)
|
|
{
|
|
// We can ignore empty scripts.
|
|
if (script.IsEmpty)
|
|
continue;
|
|
yield return script;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IEnumerator<ScriptContainer> GetEnumerator()
|
|
{
|
|
return GetAsEnumerable().GetEnumerator();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
} |