Worked on Task interfaces and Program handler
Started breaking down the interfaces into simpler ones so its easier to create tasks without extra junk. As well worked more on the Program class and how it handles the tasks. Is getting close to fully coded to be used in the encoder. Though i need to do more work and test it fully. I might end up creating a fake program before the encoder is finished just to test this. At this point i've failed to follow coding guide lines to test everything you code.
This commit is contained in:
parent
8b6b6f6399
commit
ac953b2c50
29 changed files with 377 additions and 181 deletions
BIN
docs/B1iB0DI.png
Normal file
BIN
docs/B1iB0DI.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
BIN
resources/assets/al/textures/gui/logic/DEFINEDPROCESS.png
Normal file
BIN
resources/assets/al/textures/gui/logic/DEFINEDPROCESS.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 220 B |
BIN
resources/assets/al/textures/gui/logic/IF.png
Normal file
BIN
resources/assets/al/textures/gui/logic/IF.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 456 B |
BIN
resources/assets/al/textures/gui/logic/PROCESS.png
Normal file
BIN
resources/assets/al/textures/gui/logic/PROCESS.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 B |
|
@ -1,4 +1,4 @@
|
|||
package dark.api.al.coding;
|
||||
package dark.api.al;
|
||||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
/**
|
|
@ -1,7 +1,8 @@
|
|||
package dark.api.al.coding;
|
||||
package dark.api.al;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/** Container like class to handle several servos in an object.
|
||||
*
|
||||
* @author DarkGuardsman */
|
20
src/minecraft/dark/api/al/coding/ILogicTask.java
Normal file
20
src/minecraft/dark/api/al/coding/ILogicTask.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
/** Task in which it doesn't go right to the next task in the row. In this case the task will store
|
||||
* the entry point, and exit points. As well handle anything in between. Examples are IF statements
|
||||
* and loops.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface ILogicTask extends IProcessTask
|
||||
{
|
||||
/** There is always only one exit though you can do logic to pick from all your exit points. Exit
|
||||
* is the next task rather than the exit of the statement. Use #IRedirectTask to force the logic back to this task. */
|
||||
public IProcessTask getExitPoint();
|
||||
|
||||
/** Mainly used by the encoder to understand the limit on connections */
|
||||
public int getMaxExitPoints();
|
||||
|
||||
/** Adds a possible exit point to the split off */
|
||||
public void addExitPoint(IProcessTask task);
|
||||
|
||||
}
|
|
@ -20,20 +20,8 @@ import dark.api.al.coding.args.ArgumentData;
|
|||
* the task. That way it can save values after the task has been refreshed or even deleted.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IDeviceTask extends Cloneable
|
||||
public interface IProcessTask extends ITask
|
||||
{
|
||||
/** Location in the column and row format. */
|
||||
public Vector2 getPosition();
|
||||
|
||||
public void setPosition(Vector2 pos);
|
||||
|
||||
/** Method name or rather command name this will be called. Uses both to ID this command, and do
|
||||
* basic command structuring. */
|
||||
public String getMethodName();
|
||||
|
||||
/** Should be the same as getMethodName() but can be different */
|
||||
public String getCCMethod();
|
||||
|
||||
/** Passed in from the device to the program manager then here after a Computer craft machine
|
||||
* calls a this commands method name. {@IPeripheral #callMethod()} */
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IProgramableMachine device, IComputerAccess computer, ILuaContext context) throws Exception;
|
||||
|
@ -54,24 +42,6 @@ public interface IDeviceTask extends Cloneable
|
|||
/** Called when the task is finish and then cleared */
|
||||
public void terminated();
|
||||
|
||||
/** Read the command from the armbot save. */
|
||||
public IDeviceTask load(NBTTagCompound nbt);
|
||||
|
||||
/** Writes the command to the armbot save. Should only be used to save the data used to recreate
|
||||
* a new version of this command */
|
||||
public NBTTagCompound save(NBTTagCompound nbt);
|
||||
|
||||
/** Saves the current progress of the current command */
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt);
|
||||
|
||||
/** Reads the progress of the command if it was saved mid process */
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt);
|
||||
|
||||
public TaskType getType();
|
||||
|
||||
/** Can this task function for this machine */
|
||||
public boolean canUseTask(IProgramableMachine device);
|
||||
|
||||
/** ArgumentData used to both restrict and set values into the argument hashmap */
|
||||
public List<ArgumentData> getEncoderParms();
|
||||
|
||||
|
@ -81,21 +51,8 @@ public interface IDeviceTask extends Cloneable
|
|||
/** Get all given arguments */
|
||||
public HashMap<String, Object> getArgs();
|
||||
|
||||
/** Used mainly for display purposes in the encoder */
|
||||
public static enum TaskType
|
||||
{
|
||||
DATA("Data"),
|
||||
DEFINEDPROCESS("Defined Process"),
|
||||
PROCESS("Process"),
|
||||
DECISION("Decision");
|
||||
public ResourceLocation blockTexure;
|
||||
public String name;
|
||||
|
||||
private TaskType(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
/** Get all given arguments */
|
||||
public void setArgs(HashMap<String, Object> args);
|
||||
|
||||
public static enum ProcessReturn
|
||||
{
|
||||
|
@ -113,5 +70,4 @@ public interface IDeviceTask extends Cloneable
|
|||
}
|
||||
}
|
||||
|
||||
public IDeviceTask clone();
|
||||
}
|
|
@ -10,7 +10,7 @@ import universalelectricity.core.vector.Vector2;
|
|||
* Column and row based system.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IProgram
|
||||
public interface IProgram extends Cloneable
|
||||
{
|
||||
/** Called when the program is added to an encoder, machine, or devices. */
|
||||
public void init();
|
||||
|
@ -20,17 +20,23 @@ public interface IProgram
|
|||
public HashMap<String, Object> getDeclairedVarables();
|
||||
|
||||
/** Next task in the set. Its up to the program to increment down the list */
|
||||
public IDeviceTask getNextTask();
|
||||
public ITask getNextTask();
|
||||
|
||||
/** Gets a task at the given x y location in the program */
|
||||
public IDeviceTask getTaskAt(Vector2 vector2);
|
||||
public ITask getTaskAt(Vector2 vector2);
|
||||
|
||||
public void setTaskAt(Vector2 vector2, IDeviceTask task);
|
||||
/** Returns the entire program as a map as grid locations and tasks. */
|
||||
public HashMap<Vector2, ITask> getTaskMap();
|
||||
|
||||
/** Return this program to its starting conditions
|
||||
*
|
||||
* @full - means full reset including memory clean */
|
||||
public void reset(boolean full);
|
||||
/** Sets the task at the point overriding what was there. If the task is null remove it and shift
|
||||
* everything up one */
|
||||
public void setTaskAt(Vector2 vector2, ITask task);
|
||||
|
||||
/** Inserts a task at the point. If a task is already there everything should shift down 1 */
|
||||
public void insertTask(Vector2 vector2, ITask task);
|
||||
|
||||
/** Return this program to its starting conditions */
|
||||
public void reset();
|
||||
|
||||
/** Sets the declared variable */
|
||||
public void setVar(String name, Object object);
|
||||
|
|
12
src/minecraft/dark/api/al/coding/IRedirectTask.java
Normal file
12
src/minecraft/dark/api/al/coding/IRedirectTask.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
/** Used to tell the program that this task is used to tell the program were to go next. Used by
|
||||
* things like LOOP, IF, and GOTO statement's end catches. Not actually used by the statement itself
|
||||
* other than to help control the flow of the program
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IRedirectTask extends IProcessTask
|
||||
{
|
||||
/** Were does this task redirect to */
|
||||
public IProcessTask getExit();
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
/** Task in which it doesn't go right to the next task in the row. In this case the task will store
|
||||
* the entry point, and exit points. As well handle anything in between. Examples are IF statements
|
||||
* and loops.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface ISplitArmbotTask extends IDeviceTask
|
||||
{
|
||||
/** Point were this task is entered from. Normally is the task above it, and is never used. */
|
||||
public IDeviceTask getEntryPoint();
|
||||
|
||||
/** There is always only one exit though you can do logic to pick from all your exit points */
|
||||
public IDeviceTask getExitPoint();
|
||||
|
||||
/** Mainly used by the coder to understand the limit on connections */
|
||||
public int getMaxExitPoints();
|
||||
|
||||
/** Set by the coder, or when this is clone, to say what task was before this. */
|
||||
public ISplitArmbotTask setEntryPoint(IDeviceTask task);
|
||||
|
||||
/** Adds a possible exit point to the split off */
|
||||
public void addExitPoint(IDeviceTask task);
|
||||
|
||||
|
||||
}
|
56
src/minecraft/dark/api/al/coding/ITask.java
Normal file
56
src/minecraft/dark/api/al/coding/ITask.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
|
||||
public interface ITask extends Cloneable
|
||||
{
|
||||
/** Location in the column and row format. */
|
||||
public Vector2 getPosition();
|
||||
|
||||
public void setPosition(Vector2 pos);
|
||||
|
||||
/** Method name or rather command name this will be called. Uses both to ID this command, and do
|
||||
* basic command structuring. */
|
||||
public String getMethodName();
|
||||
|
||||
/** Type of task used mainly for GUI displays */
|
||||
public TaskType getType();
|
||||
|
||||
/** Read the command from the armbot save. */
|
||||
public ITask load(NBTTagCompound nbt);
|
||||
|
||||
/** Writes the command to the armbot save. Should only be used to save the data used to recreate
|
||||
* a new version of this command */
|
||||
public NBTTagCompound save(NBTTagCompound nbt);
|
||||
|
||||
/** Saves the current progress of the current command */
|
||||
public IProcessTask loadProgress(NBTTagCompound nbt);
|
||||
|
||||
/** Reads the progress of the command if it was saved mid process */
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt);
|
||||
|
||||
/** Can this task function for this machine */
|
||||
public boolean canUseTask(IProgramableMachine device);
|
||||
|
||||
/** Used to create a new task from this task. Make sure to return a fresh copy without anything.
|
||||
* This includes no arguments, progress, varables, etc. */
|
||||
public ITask clone();
|
||||
|
||||
/** Used mainly for display purposes in the encoder */
|
||||
public static enum TaskType
|
||||
{
|
||||
DATA("Data"),
|
||||
DEFINEDPROCESS("Defined Process"),
|
||||
PROCESS("Process"),
|
||||
DECISION("Decision");
|
||||
public ResourceLocation blockTexure;
|
||||
public String name;
|
||||
|
||||
private TaskType(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,14 +2,16 @@ package dark.api.al.coding;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.IProcessTask.ProcessReturn;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/** Basic class to handle a armbot like programs for any object that uses the IArmbot class
|
||||
/** Basic class to handle a machine like programs for any object that uses the IProgramable
|
||||
* interface. Doesn't actually do much then tell the program to function, and stores the programs
|
||||
* active run time memory.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class ProgramHelper
|
||||
|
@ -18,7 +20,7 @@ public class ProgramHelper
|
|||
protected IProgram program;
|
||||
protected IProgramableMachine bot;
|
||||
/** Current task in program */
|
||||
protected IDeviceTask currentTask;
|
||||
protected ITask currentTask;
|
||||
/** Do we have a memory to store values */
|
||||
boolean hasMemory = false;
|
||||
boolean hasTaskBeenCalled = false, nextTask = false;
|
||||
|
@ -46,23 +48,31 @@ public class ProgramHelper
|
|||
}
|
||||
if (this.currentTask != null)
|
||||
{
|
||||
if (!this.hasTaskBeenCalled)
|
||||
if (this.currentTask instanceof IProcessTask)
|
||||
{
|
||||
re = this.currentTask.onMethodCalled(world, botLocation, bot);
|
||||
if (!this.hasTaskBeenCalled)
|
||||
{
|
||||
this.hasTaskBeenCalled = true;
|
||||
re = ((IProcessTask) this.currentTask).onMethodCalled(world, botLocation, bot);
|
||||
if (re == ProcessReturn.DONE)
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
else if (re != ProcessReturn.CONTINUE)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
}
|
||||
|
||||
re = ((IProcessTask) this.currentTask).onUpdate();
|
||||
if (re == ProcessReturn.DONE)
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
else if (re != ProcessReturn.CONTINUE)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
}
|
||||
|
||||
re = this.currentTask.onUpdate();
|
||||
if (re == ProcessReturn.DONE)
|
||||
else
|
||||
{
|
||||
this.nextTask = true;
|
||||
re = ProcessReturn.CONTINUE;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ public class TaskRegistry
|
|||
/** A class of all available commands.
|
||||
*
|
||||
* String - Command name. Command - The actual command class. */
|
||||
private static final HashMap<String, IDeviceTask> COMMANDS = new HashMap();
|
||||
private static final HashMap<String, IProcessTask> COMMANDS = new HashMap();
|
||||
|
||||
private static final HashMap<String, IArmbot> SUDO_BOTS = new HashMap<String, IArmbot>();
|
||||
|
||||
/** Registers a command and tells armbots that it exists */
|
||||
public static void registerCommand(IDeviceTask task)
|
||||
public static void registerCommand(IProcessTask task)
|
||||
{
|
||||
if (!COMMANDS.containsKey(task.getMethodName()))
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ public class TaskRegistry
|
|||
}
|
||||
}
|
||||
|
||||
public static void registerCommand(String registryName, IDeviceTask task)
|
||||
public static void registerCommand(String registryName, IProcessTask task)
|
||||
{
|
||||
if (!COMMANDS.containsKey(registryName))
|
||||
{
|
||||
|
@ -37,9 +37,9 @@ public class TaskRegistry
|
|||
}
|
||||
|
||||
/** returns the first command with the same name */
|
||||
public static IDeviceTask getCommand(String name)
|
||||
public static IProcessTask getCommand(String name)
|
||||
{
|
||||
for (Entry<String, IDeviceTask> command : COMMANDS.entrySet())
|
||||
for (Entry<String, IProcessTask> command : COMMANDS.entrySet())
|
||||
{
|
||||
if (command.getKey().equalsIgnoreCase(name))
|
||||
{
|
||||
|
@ -50,10 +50,10 @@ public class TaskRegistry
|
|||
}
|
||||
|
||||
/** Gets all commands with the given name though there should only be one */
|
||||
public static List<IDeviceTask> getCommands(String name)
|
||||
public static List<IProcessTask> getCommands(String name)
|
||||
{
|
||||
List<IDeviceTask> tasks = new ArrayList<IDeviceTask>();
|
||||
for (Entry<String, IDeviceTask> command : COMMANDS.entrySet())
|
||||
List<IProcessTask> tasks = new ArrayList<IProcessTask>();
|
||||
for (Entry<String, IProcessTask> command : COMMANDS.entrySet())
|
||||
{
|
||||
if (command.getValue().getMethodName().equalsIgnoreCase(name))
|
||||
{
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
package dark.assembly.common.armbot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.ITask;
|
||||
import dark.api.al.coding.TaskRegistry;
|
||||
import dark.core.prefab.helpers.NBTFileHelper;
|
||||
|
||||
public class Program implements IProgram
|
||||
{
|
||||
protected Vector2 currentPos = new Vector2(0, 0);
|
||||
protected IDeviceTask currentTask;
|
||||
protected HashMap<Vector2, IDeviceTask> tasks = new HashMap();
|
||||
protected ITask currentTask;
|
||||
protected HashMap<Vector2, ITask> tasks = new HashMap();
|
||||
protected HashMap<String, Object> varables = new HashMap();
|
||||
protected int width = 0, hight = 0;
|
||||
boolean started = false;
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
|
@ -26,20 +32,22 @@ public class Program implements IProgram
|
|||
@Override
|
||||
public HashMap<String, Object> getDeclairedVarables()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return varables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getNextTask()
|
||||
public ITask getNextTask()
|
||||
{
|
||||
this.currentTask = this.getTaskAt(currentPos);
|
||||
this.currentPos.add(new Vector2(1, 0));
|
||||
if (!started)
|
||||
{
|
||||
this.currentTask = this.getTaskAt(currentPos);
|
||||
this.currentPos.add(new Vector2(1, 0));
|
||||
}
|
||||
return this.currentTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getTaskAt(Vector2 vector2)
|
||||
public ITask getTaskAt(Vector2 vector2)
|
||||
{
|
||||
if (vector2 != null)
|
||||
{
|
||||
|
@ -49,66 +57,200 @@ public class Program implements IProgram
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setTaskAt(Vector2 vector2, IDeviceTask task)
|
||||
public HashMap<Vector2, ITask> getTaskMap()
|
||||
{
|
||||
return this.tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskAt(Vector2 vector2, ITask task)
|
||||
{
|
||||
if (vector2 != null)
|
||||
{
|
||||
if (task != null)
|
||||
{
|
||||
if (task.getPosition().x > this.width)
|
||||
{
|
||||
this.width = (int) task.getPosition().x;
|
||||
}
|
||||
if (task.getPosition().y > this.hight)
|
||||
{
|
||||
this.hight = (int) task.getPosition().y;
|
||||
}
|
||||
this.tasks.put(new Vector2(vector2.intX(), vector2.intY()), task);
|
||||
}
|
||||
else if (this.tasks.containsKey(vector2))
|
||||
{
|
||||
this.tasks.remove(vector2);
|
||||
if (task.getPosition().intY() == this.hight && !this.isThereATaskInRow(this.hight))
|
||||
{
|
||||
this.hight--;
|
||||
}
|
||||
else if (!this.isThereATaskInRow(vector2.intY()))
|
||||
{
|
||||
this.moveAll(vector2.intY(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isThereATaskInRow(int row)
|
||||
{
|
||||
Vector2 vec = new Vector2(0, row);
|
||||
Vector2 slide = new Vector2(1, 0);
|
||||
for (int x = 0; x <= this.width; x++)
|
||||
{
|
||||
if (this.getTaskAt(vec) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
vec.add(slide);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isThereATaskInColume(int colume)
|
||||
{
|
||||
Vector2 vec = new Vector2(colume, 0);
|
||||
Vector2 slide = new Vector2(0, 1);
|
||||
for (int y = 0; y <= this.width; y++)
|
||||
{
|
||||
if (this.getTaskAt(vec) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
vec.add(slide);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Move all tasks at the row and in the direction given.
|
||||
*
|
||||
* @param row - row number or Y value of the position from the task
|
||||
* @param up - true will move all the tasks up one, false will move all the tasks down one */
|
||||
public void moveAll(int row, boolean up)
|
||||
{
|
||||
List<ITask> moveList = new ArrayList<ITask>();
|
||||
final Vector2 moveDown = up ? new Vector2(-1, 0) : new Vector2(1, 0);
|
||||
Vector2 targetPos;
|
||||
ITask tagetTask;
|
||||
/* Gather all task and remove them so they can be re-added wither there new positions */
|
||||
for (int x = 0; x <= this.width; x++)
|
||||
{
|
||||
for (int y = row; y <= this.hight; y++)
|
||||
{
|
||||
targetPos = new Vector2(x, y);
|
||||
tagetTask = this.getTaskAt(targetPos);
|
||||
if (tagetTask != null)
|
||||
{
|
||||
//Add the task to the move list
|
||||
moveList.add(tagetTask);
|
||||
//Removes the task
|
||||
this.tasks.remove(targetPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Update all the task locations */
|
||||
for (ITask moveTask : moveList)
|
||||
{
|
||||
moveTask.setPosition(moveTask.getPosition().add(moveDown));
|
||||
this.setTaskAt(moveTask.getPosition(), moveTask);
|
||||
}
|
||||
//TODO send to the client the updates map and key to unlock the delete button
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertTask(Vector2 vector2, ITask task)
|
||||
{
|
||||
if (vector2 != null && task != null)
|
||||
{
|
||||
if (this.getTaskAt(vector2) != null)
|
||||
{
|
||||
this.moveAll(vector2.intY(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setTaskAt(vector2, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(boolean full)
|
||||
public void reset()
|
||||
{
|
||||
this.currentTask = null;
|
||||
if (this.currentTask != null)
|
||||
{
|
||||
NBTTagCompound tag = this.currentTask.save(new NBTTagCompound());
|
||||
this.currentTask = TaskRegistry.getCommand(this.currentTask.getMethodName()).clone();
|
||||
this.currentTask.load(tag);
|
||||
this.setTaskAt(this.currentTask.getPosition(), this.currentTask);
|
||||
this.currentTask = null;
|
||||
}
|
||||
this.currentPos = new Vector2(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVar(String name, Object object)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
if (name != null)
|
||||
{
|
||||
if (object != null)
|
||||
{
|
||||
this.varables.put(name, object);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.varables.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getVar(String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.varables.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
{
|
||||
//Save process list
|
||||
NBTTagList taskList = new NBTTagList();
|
||||
for (Entry<Vector2, IDeviceTask> entry : this.tasks.entrySet())
|
||||
for (Entry<Vector2, ITask> entry : this.tasks.entrySet())
|
||||
{
|
||||
entry.getValue().setPosition(entry.getKey());
|
||||
NBTTagCompound task = entry.getValue().save(new NBTTagCompound());
|
||||
if (entry.getKey().equals(this.currentTask.getPosition()))
|
||||
{
|
||||
task.setBoolean("currentTask", true);
|
||||
entry.getValue().saveProgress(task);
|
||||
}
|
||||
task.setString("methodName", entry.getValue().getMethodName());
|
||||
task.setInteger("positionX", entry.getKey().intX());
|
||||
task.setInteger("positionY", entry.getKey().intY());
|
||||
taskList.appendTag(task);
|
||||
}
|
||||
nbt.setTag("tasks", taskList);
|
||||
//save varables
|
||||
taskList = new NBTTagList();
|
||||
for (Entry<String, Object> var : this.varables.entrySet())
|
||||
{
|
||||
taskList.appendTag(NBTFileHelper.saveObject(var.getKey(), var.getValue()));
|
||||
}
|
||||
nbt.setTag("vars", taskList);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
//Load process list
|
||||
NBTTagList taskList = nbt.getTagList("tasks");
|
||||
for (int s = 0; s < taskList.tagCount(); ++s)
|
||||
{
|
||||
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
|
||||
IDeviceTask task = TaskRegistry.getCommand(tag.getString("methodName"));
|
||||
ITask task = TaskRegistry.getCommand(tag.getString("methodName"));
|
||||
if (task != null)
|
||||
{
|
||||
task = task.clone();
|
||||
|
@ -117,10 +259,38 @@ public class Program implements IProgram
|
|||
task.load(tag);
|
||||
task.setPosition(new Vector2(nbt.getInteger("positionX"), nbt.getInteger("positionY")));
|
||||
this.tasks.put(task.getPosition(), task);
|
||||
if (tag.getBoolean("currentTask"))
|
||||
{
|
||||
this.currentTask = task;
|
||||
task.loadProgress(tag);
|
||||
this.currentPos = task.getPosition();
|
||||
}
|
||||
if (task.getPosition().x > this.width)
|
||||
{
|
||||
this.width = (int) task.getPosition().x;
|
||||
}
|
||||
if (task.getPosition().y > this.hight)
|
||||
{
|
||||
this.hight = (int) task.getPosition().y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
taskList = nbt.getTagList("vars");
|
||||
for (int s = 0; s < taskList.tagCount(); ++s)
|
||||
{
|
||||
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
|
||||
this.varables.put(tag.getName(), NBTFileHelper.loadObject(tag, tag.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Program clone()
|
||||
{
|
||||
Program program = new Program();
|
||||
program.load(this.save(new NBTTagCompound()));
|
||||
program.reset();
|
||||
return program;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,29 +5,26 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dan200.computer.api.IComputerAccess;
|
||||
import dan200.computer.api.ILuaContext;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IMemoryTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.core.prefab.helpers.NBTFileLoader;
|
||||
import dark.core.prefab.helpers.NBTFileHelper;
|
||||
|
||||
/** Basic command prefab used by machines like an armbot. You are not required to use this in order
|
||||
* to make armbot commands but it does help. Delete this if you don't plan to use it. */
|
||||
public abstract class TaskBase implements IDeviceTask, IMemoryTask
|
||||
public abstract class TaskBase implements IProcessTask, IMemoryTask
|
||||
{
|
||||
/** Program this is part of. Can be null while stores as a prefab waiting to be copied */
|
||||
protected IProgram program;
|
||||
|
@ -140,7 +137,7 @@ public abstract class TaskBase implements IDeviceTask, IMemoryTask
|
|||
NBTTagCompound parms = nbt.getCompoundTag("args");
|
||||
for (ArgumentData arg : this.getEncoderParms())
|
||||
{
|
||||
Object obj = NBTFileLoader.loadObject(parms, arg.getName());
|
||||
Object obj = NBTFileHelper.loadObject(parms, arg.getName());
|
||||
if (arg.isValid(obj))
|
||||
{
|
||||
this.aruguments.put(arg.getName(), obj);
|
||||
|
@ -157,7 +154,7 @@ public abstract class TaskBase implements IDeviceTask, IMemoryTask
|
|||
NBTTagCompound parms = new NBTTagCompound();
|
||||
for (Entry<String, Object> entry : this.aruguments.entrySet())
|
||||
{
|
||||
NBTFileLoader.saveObject(parms, entry.getKey(), entry.getValue());
|
||||
NBTFileHelper.saveObject(parms, entry.getKey(), entry.getValue());
|
||||
}
|
||||
nbt.setCompoundTag("args", parms);
|
||||
if (this.pos != null)
|
||||
|
@ -169,7 +166,7 @@ public abstract class TaskBase implements IDeviceTask, IMemoryTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt)
|
||||
public IProcessTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
@ -192,12 +189,6 @@ public abstract class TaskBase implements IDeviceTask, IMemoryTask
|
|||
return this.methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCCMethod()
|
||||
{
|
||||
return this.methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getType()
|
||||
{
|
||||
|
|
|
@ -7,8 +7,8 @@ import net.minecraft.entity.item.EntityItem;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.core.prefab.helpers.ItemWorldHelper;
|
||||
|
@ -71,7 +71,7 @@ public class CommandBreak extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt)
|
||||
public IProcessTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
this.breakTicks = nbt.getInteger("breakTicks");
|
||||
return this;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.api.al.coding.args.ArgumentFloatData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.world.World;
|
|||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
|
||||
/** Used by arms to break a specific block in a position.
|
||||
*
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import net.minecraft.block.Block;
|
||||
|
|
|
@ -4,8 +4,8 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.ProcessReturn;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
|
|
@ -14,7 +14,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.IProcessTask.ProcessReturn;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
|
|
@ -8,10 +8,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import dark.api.al.coding.IArmbotUseable;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.IProcessTask.ProcessReturn;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
@ -100,7 +100,7 @@ public class CommandUse extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt)
|
||||
public IProcessTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
this.curTimes = nbt.getInteger("useCurTimes");
|
||||
return this;
|
||||
|
|
|
@ -2,16 +2,16 @@ package dark.assembly.common.armbot.command;
|
|||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.ISplitArmbotTask;
|
||||
import dark.api.al.coding.ILogicTask;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
||||
public class TaskIF extends TaskBase implements ISplitArmbotTask
|
||||
public class TaskIF extends TaskBase implements ILogicTask
|
||||
{
|
||||
protected IDeviceTask entryPoint = null;
|
||||
protected IDeviceTask exitTruePoint = null;
|
||||
protected IDeviceTask exitFalsePoint = null;
|
||||
protected IProcessTask entryPoint = null;
|
||||
protected IProcessTask exitTruePoint = null;
|
||||
protected IProcessTask exitFalsePoint = null;
|
||||
protected boolean isTrue = false;
|
||||
|
||||
public TaskIF()
|
||||
|
@ -19,7 +19,7 @@ public class TaskIF extends TaskBase implements ISplitArmbotTask
|
|||
super("IF", TaskType.DECISION);
|
||||
}
|
||||
|
||||
public TaskIF(IDeviceTask entryPoint, IDeviceTask trueExit, IDeviceTask falseExit)
|
||||
public TaskIF(IProcessTask entryPoint, IProcessTask trueExit, IProcessTask falseExit)
|
||||
{
|
||||
this();
|
||||
this.setEntryPoint(this.entryPoint);
|
||||
|
@ -35,13 +35,13 @@ public class TaskIF extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getEntryPoint()
|
||||
public IProcessTask getEntryPoint()
|
||||
{
|
||||
return this.entryPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getExitPoint()
|
||||
public IProcessTask getExitPoint()
|
||||
{
|
||||
if (this.isTrue)
|
||||
{
|
||||
|
@ -57,14 +57,14 @@ public class TaskIF extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public ISplitArmbotTask setEntryPoint(IDeviceTask task)
|
||||
public ILogicTask setEntryPoint(IProcessTask task)
|
||||
{
|
||||
this.entryPoint = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExitPoint(IDeviceTask task)
|
||||
public void addExitPoint(IProcessTask task)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.ISplitArmbotTask;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.ILogicTask;
|
||||
import dark.api.al.coding.IProcessTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -16,10 +16,10 @@ import net.minecraft.world.World;
|
|||
/** Basic While loop that mainly handles number of repeats.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
||||
public class TaskLoop extends TaskBase implements ILogicTask
|
||||
{
|
||||
protected int numReps = -1;
|
||||
protected IDeviceTask entry, exit;
|
||||
protected IProcessTask entry, exit;
|
||||
|
||||
public TaskLoop()
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
|||
this.defautlArguments.add(new ArgumentIntData("loop", 1, Integer.MAX_VALUE, -1));
|
||||
}
|
||||
|
||||
public TaskLoop(IDeviceTask entry, IDeviceTask exit)
|
||||
public TaskLoop(IProcessTask entry, IProcessTask exit)
|
||||
{
|
||||
this();
|
||||
this.entry = entry;
|
||||
|
@ -49,13 +49,13 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getEntryPoint()
|
||||
public IProcessTask getEntryPoint()
|
||||
{
|
||||
return this.entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getExitPoint()
|
||||
public IProcessTask getExitPoint()
|
||||
{
|
||||
return this.exit;
|
||||
}
|
||||
|
@ -67,14 +67,14 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public ISplitArmbotTask setEntryPoint(IDeviceTask task)
|
||||
public ILogicTask setEntryPoint(IProcessTask task)
|
||||
{
|
||||
this.entry = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExitPoint(IDeviceTask task)
|
||||
public void addExitPoint(IProcessTask task)
|
||||
{
|
||||
this.exit = task;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.TaskRegistry;
|
||||
import dark.assembly.common.armbot.Program;
|
||||
|
@ -115,7 +115,7 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_CHANGE))
|
||||
{
|
||||
|
||||
IDeviceTask task = TaskRegistry.getCommand(dis.readUTF());
|
||||
IProcessTask task = TaskRegistry.getCommand(dis.readUTF());
|
||||
task.setPosition(new Vector2(dis.readInt(), dis.readInt()));
|
||||
task.load(PacketManager.readNBTTagCompound(dis));
|
||||
this.program.setTaskAt(task.getPosition(), task);
|
||||
|
@ -163,7 +163,7 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
}
|
||||
}
|
||||
|
||||
public void updateTask(IDeviceTask task)
|
||||
public void updateTask(IProcessTask task)
|
||||
{
|
||||
if (task != null)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue