using System;
namespace Ariadne.Vellum.UnitTests
{
///
/// Offers a passage that pauses until a gate it is given opens, counting the frames it waited in a local.
///
public partial class GatedPlantScript : Arc
{
public int Total;
public int Measure(Gates gates, string gate, int amount)
{
int waited = 0;
wait:
while (!gates.Open.Contains(gate))
{
waited++;
Yield();
}
Total += amount + waited;
return Total;
}
protected override void Run(Gates gates)
{
}
}
///
/// Adds what two passages of two arcs hand back to a local, in one statement.
///
public partial class GatedSumOperatorScript : Arc
{
public GatedPlantScript First;
public GatedPlantScript Second;
public string Result;
protected override void Run(Gates gates)
{
int before = 100;
sum:
Result = "sum " + (before + First.Measure(gates, "a", 5) + Second.Measure(gates, "b", 7));
}
}
///
/// Offers a passage that pauses until its gate opens, then hands back a span.
///
public partial class DelayPlantScript : Arc
{
public TimeSpan Ask(Gates gates)
{
ask:
while (!gates.Open.Contains("answer"))
{
Yield();
}
return TimeSpan.FromSeconds(2);
}
protected override void Run(Gates gates)
{
}
}
///
/// Waits for as long as a passage of another arc says.
///
public partial class AskWaitOperatorScript : Arc
{
public DelayPlantScript Delay;
public string Result;
protected override void Run(Gates gates)
{
first:
Wait(Delay.Ask(gates));
Result = "done";
}
}
}