57 lines
1.1 KiB
C#
57 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Godot;
|
|
|
|
public partial class Robot : Node3D
|
|
{
|
|
List<ProgramNode> nodes;
|
|
bool isExecuting = false;
|
|
ProgramNode currentNode;
|
|
public string currentProgram;
|
|
public string currentMessage = "";
|
|
|
|
public override void _Ready()
|
|
{
|
|
|
|
}
|
|
|
|
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)
|
|
{
|
|
this.nodes = [.. nodes];
|
|
isExecuting = true;
|
|
currentNode = nodes[0];
|
|
}
|
|
}
|