using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Packager
{
///
/// Todo: we need to fix the way the data is transfered between the tasks, as of now, some tasks use the in ram data structures and some use the physical files as their inputs and outputs.
/// Todo: This makes in really difficult to use the tasks freely, which was one of the motivation of restructuring the old game tool.
///
public class ReferenceList : Reference
{
private readonly List _references = new List();
public void Add(params Reference[] referenceCollection)
{
foreach (var reference in referenceCollection)
{
_references.Add(reference);
}
}
public void Add(params string[] value)
{
foreach (var element in value)
{
var singleReference = new SingleReference(element);
Add(singleReference);
}
}
public void CleanAdd(params string[] value)
{
Clear();
Add(value);
}
public void CleanAdd(params Reference[] referenceCollection)
{
Clear();
Add(referenceCollection);
}
public void CleanAdd(IEnumerable collection)
{
Clear();
Add(collection.ToArray());
}
public override IEnumerator GetEnumerator()
{
return _references.SelectMany(x => x).GetEnumerator();
}
public override IEnumerable EnumerateChildren()
{
yield return this;
foreach (var reference in _references)
{
foreach (var childReference in reference.EnumerateChildren())
{
yield return childReference;
}
}
}
public override int Count
{
get { return _references.SelectMany(x => x).Count(); }
}
public void Remove(params Reference[] removeReferenceCollection)
{
foreach (var reference in removeReferenceCollection)
{
var removeRef = _references.FirstOrDefault(x => x == reference);
_references.Remove(removeRef);
}
}
public void Clear()
{
_references.Clear();
}
}
}
public class SingleReference : Reference
{
private string _value;
public SingleReference()
{
Value = "";
}
public SingleReference(string value)
{
Value = value;
}
///
/// While setting the value we use toLower() because values are also used to assign the names to .ipk files in the bundles,
/// and our engine reads everything in lowercase.
///
public string Value
{
get
{
return _value;
}
set
{
_value = FormatValue(value);
}
}
protected virtual string FormatValue(string value) => value.ToLower();
public override IEnumerator GetEnumerator()
{
yield return Value;
}
public override IEnumerable EnumerateChildren()
{
yield return this;
}
public override int Count
{
get
{
if (Value != "")
return 1;
else
return 0;
}
}
public override string ToString()
{
return Value;
}
}
public class CaseSensitiveReference : SingleReference
{
public CaseSensitiveReference(string value) : base(value) { }
protected override string FormatValue(string value) => value;
}
///
/// This class serves as a mechanism to create the references of the tasks in the tasklists, at the time of instantiation of the tasklist. These references are used later to:
/// 1. provide the tasks with appropriate input parameters.
/// 2. Execute tasks.
/// 3. Use the tasks' output parameters as input parameters to other tasks.
///
public class Reference : IEnumerable
{
public virtual int Count { get; set; }
public virtual IEnumerator GetEnumerator()
{
yield break;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public virtual IEnumerable EnumerateChildren()
{
yield break;
}
}