Cleaned up project with better structure.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
public partial class Robot : Node3D
|
||||
{
|
||||
private List<ProgramNode> nodes = new List<ProgramNode>();
|
||||
private bool isExecuting = false;
|
||||
private ProgramNode currentNode;
|
||||
|
||||
public string currentProgram;
|
||||
public string currentMessage = "";
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (isExecuting)
|
||||
{
|
||||
switch (currentNode.Execute(this, delta))
|
||||
{
|
||||
case NodeResult.SUCCESS:
|
||||
currentNode = currentNode.nextNode;
|
||||
if (currentNode == null)
|
||||
{
|
||||
isExecuting = false;
|
||||
}
|
||||
break;
|
||||
case NodeResult.FAILURE:
|
||||
isExecuting = false;
|
||||
currentMessage = "(FAILED)" + currentNode.lastExecutionMessage;
|
||||
break;
|
||||
case NodeResult.RUNNING:
|
||||
currentMessage = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (currentMessage.Length <= 0)
|
||||
{
|
||||
currentMessage = "No script executing";
|
||||
}
|
||||
|
||||
Visible = Math.Round(Math.Abs(Position.Y / GameData.tileHeight), 0) == GameData.visibleLayer;
|
||||
|
||||
}
|
||||
|
||||
public void SetupExecution(List<ProgramNode> nodes)
|
||||
{
|
||||
if (nodes.Count <= 0) return;
|
||||
|
||||
this.nodes = new List<ProgramNode>(nodes);
|
||||
isExecuting = true;
|
||||
currentNode = nodes[0];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user