us.ihmc.simulationconstructionset.scripts.ConditionalScript Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simulation-construction-set
Show all versions of simulation-construction-set
Simulation Construction Set
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();
}
}
}