Esempio n. 1
0
        /*
         * Iterates over the given boundaries, and passes the step value to the ForBody
         * provided in the last parameter. Useful for replacing delegates with basic
         * for loops inside of them. The events returned by this function happen as
         * separate events; if the ForBody's AISequence has a delay, this will appear
         * between all the events produced.
         */
        public static AISequence For(float start, float end, float step, ForBody body)
        {
            Debug.Log("For called!");
            if (Mathf.Approximately(step, 0))
            {
                Debug.LogError("Found for loop with step size 0.");
                return(body(start));
            }

            if (Mathf.Abs(Mathf.Sign(end - start) - Mathf.Sign(step)) > 0.01f)
            {
                Debug.LogError("Found for loop that will never terminate.");
                return(body(start));
            }

            AISequence[] sequences = new AISequence[(int)Mathf.Abs((end - start) / step)];
            int          count     = 0;

            if (start > end)
            {
                for (float i = start; i > end; i += step)
                {
                    sequences[count++] = body(i);
                }
            }
            else
            {
                for (float i = start; i < end; i += step)
                {
                    sequences[count++] = body(i);
                }
            }
            return(new AISequence(sequences));
        }
Esempio n. 2
0
 public static AISequence For(float start, float end, ForBody body)
 {
     if (end < start)
     {
         Debug.LogError("Found a for loop with end before start.");
         return(body(start));
     }
     return(For(start, end, 1, body));
 }
Esempio n. 3
0
 public static AISequence For(float count, ForBody body)
 {
     if (count <= 0)
     {
         Debug.LogError("Found a for loop with negative count.");
         return(body(0));
     }
     return(For(0, count, 1, body));
 }
Esempio n. 4
0
 public void RunFor(string variable, string collection, ForBody forBody)
 {
     if (collection != null && variable != null)
     {
         variable = "@" + variable.Trim();
         LoopContext context = GetEnumerator(variable, collection.Trim());
         if (context.enumerator != null)
         {
             while (context.enumerator.MoveNext())
             {
                 forBody();
                 context.current++;
             }
             _loopCollection.Remove(variable);
         }
     }
 }
Esempio n. 5
0
 /*
  * Does the same as "For", but all the events generated happen in one frame.
  * Useful for generating sequences with multiple projectiles appearing at once.
  *
  * This means a wait returned by ForBody will happen at the end, rather than
  * between each sequence.
  */
 public static AISequence ForConcurrent(float start, float end, float step, ForBody body)
 {
     return(Merge(For(start, end, step, body).GetChildren()));
 }
Esempio n. 6
0
 public static AISequence ForConcurrent(float start, float end, ForBody body)
 {
     return(ForConcurrent(start, end, 1, body));
 }
Esempio n. 7
0
 public static AISequence ForConcurrent(float count, ForBody body)
 {
     return(ForConcurrent(0, count, 1, body));
 }
Esempio n. 8
0
 public void BodyAdd(StatementBridge _) => ForBody.Add(_);
Esempio n. 9
0
 public void RunFor(string variable, string collection, ForBody forBody)
 {
     if (collection != null && variable != null)
     {
         variable = "@" + variable.Trim();
         LoopContext context = GetEnumerator(variable, collection.Trim());
         if (context.enumerator != null)
         {
             while (context.enumerator.MoveNext())
             {
                 forBody();
                 context.current++;
             }
             _loopCollection.Remove(variable);
         }
     }
 }