Added more symbols to the game, added gates blocking pathfinding and improved DSL feedback system with enum for better control and UX
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
public enum NodeResult
|
||||
{
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
RUNNING
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dpp7ycquabyq8
|
||||
@@ -6,7 +6,7 @@ public class CraftNode : ProgramNode
|
||||
{
|
||||
DisplayText = "Craft";
|
||||
}
|
||||
public override bool Execute(Robot robot, double delta)
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
GD.Print("Craft");
|
||||
if (nextNode != null)
|
||||
@@ -15,7 +15,7 @@ public class CraftNode : ProgramNode
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ public class HarvestNode : ProgramNode
|
||||
{
|
||||
DisplayText = "Harvest";
|
||||
}
|
||||
public override bool Execute(Robot robot, double delta)
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
GD.Print("Harvest");
|
||||
if (nextNode != null)
|
||||
@@ -15,7 +15,7 @@ public class HarvestNode : ProgramNode
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,14 @@ public class MoveNode : ProgramNode
|
||||
{
|
||||
DisplayText = "Move";
|
||||
}
|
||||
public override bool Execute(Robot robot, double delta)
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
pathPoints ??= [.. Pathfinding.GetPath(Pathfinding.GetClosestStartPoint(robot.Position), targetPosition)];
|
||||
|
||||
if (pathPoints.Count <= 0)
|
||||
{
|
||||
lastExecutionMessage = "No path available";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
startPosition = robot.Position;
|
||||
Vector3 target = pathPoints[0] - startPosition;
|
||||
float distance = target.Length();
|
||||
@@ -32,11 +36,12 @@ public class MoveNode : ProgramNode
|
||||
pathPoints.Remove(pathPoints[0]);
|
||||
if (pathPoints.Count <= 0)
|
||||
{
|
||||
pathPoints = null;
|
||||
return true;
|
||||
lastExecutionMessage = "";
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
return false;
|
||||
lastExecutionMessage = "";
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
Vector3 direction = target / distance;
|
||||
@@ -47,14 +52,12 @@ public class MoveNode : ProgramNode
|
||||
}
|
||||
robot.GlobalPosition += direction * (float)delta * GameData.robotSpeed;
|
||||
|
||||
return false;
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
||||
|
||||
GD.Print(valueContainer.GetNode<SpinBox>("./CoordinateX").Value);
|
||||
int posX = (int)valueContainer.GetNode<SpinBox>("./CoordinateX").Value;
|
||||
int posY = (int)valueContainer.GetNode<SpinBox>("./CoordinateY").Value;
|
||||
int posZ = (int)valueContainer.GetNode<SpinBox>("./CoordinateZ").Value;
|
||||
|
||||
@@ -4,8 +4,9 @@ public abstract class ProgramNode
|
||||
{
|
||||
public ProgramNode nextNode;
|
||||
public string DisplayText;
|
||||
public string lastExecutionMessage;
|
||||
|
||||
public abstract bool Execute(Robot robot, double delta);
|
||||
public abstract NodeResult Execute(Robot robot, double delta);
|
||||
public abstract void ReadParameters(NodeDisplay display);
|
||||
public abstract ProgramNode Duplicate();
|
||||
}
|
||||
+14
-5
@@ -18,13 +18,22 @@ public partial class Robot : Node3D
|
||||
{
|
||||
if (isExecuting)
|
||||
{
|
||||
if (currentNode.Execute(this, delta))
|
||||
switch (currentNode.Execute(this, delta))
|
||||
{
|
||||
currentNode = currentNode.nextNode;
|
||||
if (currentNode == null)
|
||||
{
|
||||
case NodeResult.SUCCESS:
|
||||
currentNode = currentNode.nextNode;
|
||||
if (currentNode == null)
|
||||
{
|
||||
isExecuting = false;
|
||||
}
|
||||
break;
|
||||
case NodeResult.FAILURE:
|
||||
isExecuting = false;
|
||||
}
|
||||
GD.Print(currentNode.lastExecutionMessage);
|
||||
break;
|
||||
case NodeResult.RUNNING:
|
||||
//Currently does nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public partial class Layer : Node3D
|
||||
public bool hasContentGenerated = false;
|
||||
public Vector2I gateCoordinate;
|
||||
public List<string> currentResources;
|
||||
public bool isGateOpen = false;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
@@ -89,7 +90,7 @@ public partial class Layer : Node3D
|
||||
var node = new Node3D
|
||||
{
|
||||
Position = tile.Position,
|
||||
Visible = false
|
||||
Visible = tile.collapsedMesh != null && tile.collapsedMesh == "gate"
|
||||
};
|
||||
decorationRoot.AddChild(node);
|
||||
|
||||
@@ -115,7 +116,7 @@ public partial class Layer : Node3D
|
||||
for (int z = 0; z < layerSize; z++)
|
||||
{
|
||||
//Exclude spawn from border generation
|
||||
if(x == 0 && z == 0) continue;
|
||||
if(x == 0 && z == 0 && level == 0) continue;
|
||||
if (!IsBorder(x, z))
|
||||
continue;
|
||||
|
||||
@@ -155,6 +156,7 @@ public partial class Layer : Node3D
|
||||
if (tiles[posX, posY].tileMeshes.ContainsKey("gate"))
|
||||
{
|
||||
tiles[posX, posY].Collapse("gate");
|
||||
tiles[posX, posY].containsDecoration = true;
|
||||
gateCoordinate = new Vector2I(posX, posY);
|
||||
Propagate(gateCoordinate);
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,7 @@ public class Pathfinding
|
||||
private static Dictionary<Vector3I, long> coordToId = new();
|
||||
private static Dictionary<long, Vector3I> idToCoord = new();
|
||||
private static long nextId = 1;
|
||||
private static long[] layerGateIds = new long[GameData.ruinSize];
|
||||
|
||||
private static long GetOrCreateId(Vector3I coord)
|
||||
{
|
||||
@@ -26,6 +27,7 @@ public class Pathfinding
|
||||
aStar.Clear();
|
||||
coordToId.Clear();
|
||||
idToCoord.Clear();
|
||||
layerGateIds = new long[GameData.ruinSize];
|
||||
nextId = 1;
|
||||
|
||||
for (int y = 0; y < GameData.ruinSize; y++)
|
||||
@@ -43,6 +45,10 @@ public class Pathfinding
|
||||
long id = GetOrCreateId(coord);
|
||||
|
||||
aStar.AddPoint(id, tile.Position);
|
||||
if (tile.collapsedMesh == "gate")
|
||||
{
|
||||
layerGateIds[y] = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +80,16 @@ public class Pathfinding
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < GameData.ruinSize; y++)
|
||||
{
|
||||
UpdateGatePoint(y, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateGatePoint(int layer, bool isOpen)
|
||||
{
|
||||
aStar.SetPointDisabled(layerGateIds[layer], !isOpen);
|
||||
}
|
||||
|
||||
public static List<Vector3> GetPath(Vector3I start, Vector3I end)
|
||||
|
||||
@@ -132,7 +132,10 @@ public partial class Tile
|
||||
Position = placeholder.transform.Origin
|
||||
};
|
||||
ContentNode.AddChild(decoration);
|
||||
decoration.LookAt(transform.Origin, Vector3.Up);
|
||||
if (!key.ToLower().Contains("gate"))
|
||||
{
|
||||
decoration.LookAt(transform.Origin, Vector3.Up);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class WFC
|
||||
}
|
||||
else
|
||||
{
|
||||
return fromTile.collapsedMesh == "gate";
|
||||
return fromTile.collapsedMesh == "gate" && GameData.map[from.Y].isGateOpen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user