All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.ihmc.simulationconstructionset.scripts.ConditionalScript Maven / Gradle / Ivy

There is a newer version: 0.25.2
Show newest version
package us.ihmc.simulationconstructionset.scripts;

import java.util.ArrayList;

public class ConditionalScript implements Script
{
   private ArrayList conditionalScriptEntries = new ArrayList<>();

   public ConditionalScript()
   {
   }

   @Override
   public void doScript(double t)
   {
      for (int i = 0; i < conditionalScriptEntries.size(); i++)
      {
         ConditionalScriptEntry entry = conditionalScriptEntries.get(i);

         if (entry.isActive())
         {
            entry.doActivity();

            if (entry.finishCondition())
            {
               entry.event_state.set(ConditionalScriptEntry.FINISHED);
               entry.deactivate();
               entry.considerArmingChildren();
            }
         }

         else if (entry.isArmed())
         {
            if (entry.startCondition())
            {
               entry.event_state.set(ConditionalScriptEntry.ACTIVE);
               entry.activate();
            }
         }
      }

   }

   public void addEntry(ConditionalScriptEntry cse)
   {
      if (cse == null)
         return;
      conditionalScriptEntries.add(cse);
   }

   public void removeEntry(ConditionalScriptEntry cse)
   {
      if (cse == null)
         return;

      cse.removeParentsAndChildren();
      conditionalScriptEntries.remove(cse);
   }

   public void reset()
   {
      for (ConditionalScriptEntry entry : conditionalScriptEntries)
      {
         entry.reset();
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy