Set up IF command

This commit is contained in:
DarkGuardsman 2013-10-15 11:42:33 -04:00
parent 0227c0e58b
commit 30128f6850
2 changed files with 36 additions and 4 deletions

View file

@ -2,14 +2,25 @@ package dark.api.al.armbot;
import java.util.HashMap;
import universalelectricity.core.vector.Vector2;
/** Flow chart style program. Each command in the program needs to have a stored location so it can
* be saved and loaded with its correct connections. Though the location only need to be a simple
* Column and row based system.
*
* @author DarkGuardsman */
public interface IProgram
{
/** Called when the program is added to an encoder, machine, or devices.
* memory values. */
/** Called when the program is added to an encoder, machine, or devices. */
public void init();
/** Variables this program has to operate. Is still limited by the actual machine */
/** Variables this program has to operate. Is still limited by the actual machine. String is the
* name, Object is the starting value and data type */
public HashMap<String, Object> getDeclairedVarables();
/** Next task in the set. Its up to the program to increment down the list */
public IArmbotTask getNextTask();
/** Gets a task at the given x y location in the program */
public IArmbotTask getTaskAt(Vector2 vector2);
}

View file

@ -1,5 +1,6 @@
package dark.assembly.common.armbot.command;
import universalelectricity.core.vector.Vector2;
import net.minecraft.nbt.NBTTagCompound;
import dark.api.al.armbot.Command;
import dark.api.al.armbot.IArmbotTask;
@ -17,10 +18,12 @@ public class CommandIF extends Command implements ISplitArmbotTask
super("IF");
}
public CommandIF(IArmbotTask entryPoint, IArmbotTask left, IArmbotTask right)
public CommandIF(IArmbotTask entryPoint, IArmbotTask trueExit, IArmbotTask falseExit)
{
this();
this.setEntryPoint(this.entryPoint);
this.exitTruePoint = trueExit;
this.exitFalsePoint = falseExit;
}
@ -70,6 +73,9 @@ public class CommandIF extends Command implements ISplitArmbotTask
public Command readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.entryPoint = this.program.getTaskAt(new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY"))));
this.exitFalsePoint = this.program.getTaskAt(new Vector2(nbt.getDouble("exitFalseX"), (nbt.getDouble("exitFalseY"))));
this.exitTruePoint = this.program.getTaskAt(new Vector2(nbt.getDouble("exitTrueX"), (nbt.getDouble("exitTrueY"))));
return this;
}
@ -77,6 +83,21 @@ public class CommandIF extends Command implements ISplitArmbotTask
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (this.entryPoint != null)
{
nbt.setDouble("entryX", this.entryPoint.getPosition().x);
nbt.setDouble("entryY", this.entryPoint.getPosition().y);
}
if (this.exitFalsePoint != null)
{
nbt.setDouble("exitFalseX", this.exitFalsePoint.getPosition().x);
nbt.setDouble("exitFalseY", this.exitFalsePoint.getPosition().y);
}
if (this.exitTruePoint != null)
{
nbt.setDouble("exitTrueX", this.exitTruePoint.getPosition().x);
nbt.setDouble("exitTrueY", this.exitTruePoint.getPosition().y);
}
return nbt;
}