Added ability to delete nodes from editor, added complete node load and save for the DSL

This commit is contained in:
2026-05-06 09:29:28 +02:00
parent 44bfd7ce1d
commit 18b76f3cbc
20 changed files with 451 additions and 84 deletions
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://wq8yc0u0ee33"
path="res://.godot/imported/TrashSymbol.png-3f91ec9cd1f5cf96bc959424d5164ff1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/Images/TrashSymbol.png"
dest_files=["res://.godot/imported/TrashSymbol.png-3f91ec9cd1f5cf96bc959424d5164ff1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
+12 -1
View File
@@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://cinn18bl736rk"]
[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_qemp1"]
[ext_resource type="Texture2D" uid="uid://wq8yc0u0ee33" path="res://Assets/Images/TrashSymbol.png" id="2_loic7"]
[node name="Craft" type="PanelContainer" unique_id=247502695 node_paths=PackedStringArray("editorDisplay", "listDisplay")]
anchors_preset = 14
@@ -43,6 +44,16 @@ rounded = true
alignment = 1
prefix = "x"
[node name="ListDisplay" type="Button" parent="." unique_id=200731038]
[node name="TextureButton" type="TextureButton" parent="EditorDisplay/HBoxContainer" unique_id=479938935]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
texture_normal = ExtResource("2_loic7")
[node name="ListDisplay" type="Button" parent="." unique_id=200731038]
visible = false
layout_mode = 2
tooltip_text = "Crafts the amount of the selected item."
text = "Craft"
[connection signal="pressed" from="EditorDisplay/HBoxContainer/TextureButton" to="." method="DeleteNodePressed"]
+11
View File
@@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://dit4u45jegwv0"]
[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_3kgh4"]
[ext_resource type="Texture2D" uid="uid://wq8yc0u0ee33" path="res://Assets/Images/TrashSymbol.png" id="2_6eg2n"]
[node name="Explore" type="PanelContainer" unique_id=1474470717 node_paths=PackedStringArray("editorDisplay", "listDisplay")]
anchors_preset = 14
@@ -24,12 +25,22 @@ alignment = 1
[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1497013575]
layout_mode = 2
size_flags_horizontal = 3
text = "Randomly explore"
fit_content = true
autowrap_mode = 0
horizontal_alignment = 1
vertical_alignment = 1
[node name="TextureButton" type="TextureButton" parent="EditorDisplay/HBoxContainer" unique_id=57412049]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
texture_normal = ExtResource("2_6eg2n")
[node name="ListDisplay" type="Button" parent="." unique_id=347942160]
layout_mode = 2
tooltip_text = "Randomly explores the available ruin"
text = "Explore"
[connection signal="pressed" from="EditorDisplay/HBoxContainer/TextureButton" to="." method="DeleteNodePressed"]
+11 -2
View File
@@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://com0ou37wj2xo"]
[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_ve3v1"]
[ext_resource type="Texture2D" uid="uid://wq8yc0u0ee33" path="res://Assets/Images/TrashSymbol.png" id="2_u1say"]
[node name="Harvest" type="PanelContainer" unique_id=1323721153 node_paths=PackedStringArray("editorDisplay", "listDisplay")]
anchors_preset = 14
@@ -25,13 +26,21 @@ alignment = 1
[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1393328640]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
text = "Harvest: "
text = "Harvest"
fit_content = true
autowrap_mode = 0
horizontal_alignment = 1
vertical_alignment = 1
[node name="TextureButton" type="TextureButton" parent="EditorDisplay/HBoxContainer" unique_id=661274351]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
texture_normal = ExtResource("2_u1say")
[node name="ListDisplay" type="Button" parent="." unique_id=884865258]
layout_mode = 2
tooltip_text = "Harvests the resource from the tile the robot is currently standing on."
text = "Harvest"
[connection signal="pressed" from="EditorDisplay/HBoxContainer/TextureButton" to="." method="DeleteNodePressed"]
+14
View File
@@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://by0khq5dmxjvm"]
[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_mexpj"]
[ext_resource type="Texture2D" uid="uid://wq8yc0u0ee33" path="res://Assets/Images/TrashSymbol.png" id="2_5ujwv"]
[node name="Move" type="PanelContainer" unique_id=1474470717 node_paths=PackedStringArray("editorDisplay", "listDisplay")]
anchors_preset = 14
@@ -24,6 +25,7 @@ alignment = 1
[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1497013575]
layout_mode = 2
size_flags_horizontal = 3
text = "Move to: "
fit_content = true
autowrap_mode = 0
@@ -32,22 +34,34 @@ vertical_alignment = 1
[node name="CoordinateX" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=485214217]
layout_mode = 2
size_flags_horizontal = 3
rounded = true
alignment = 1
prefix = "X"
[node name="CoordinateY" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=724940645]
layout_mode = 2
size_flags_horizontal = 3
rounded = true
alignment = 1
prefix = "Y"
[node name="CoordinateZ" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=578943647]
layout_mode = 2
size_flags_horizontal = 3
rounded = true
alignment = 1
prefix = "Z"
[node name="TextureButton" type="TextureButton" parent="EditorDisplay/HBoxContainer" unique_id=753598237]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
texture_normal = ExtResource("2_5ujwv")
[node name="ListDisplay" type="Button" parent="." unique_id=347942160]
layout_mode = 2
tooltip_text = "Moves the robot to the selected coordinate"
text = "Move"
[connection signal="pressed" from="EditorDisplay/HBoxContainer/TextureButton" to="." method="DeleteNodePressed"]
+9 -3
View File
@@ -140,7 +140,7 @@ vertical_alignment = 1
layout_mode = 2
size_flags_vertical = 3
[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow")]
[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow", "availableScripts", "scriptName", "nameInput")]
visible = false
layout_mode = 1
anchors_preset = 11
@@ -154,6 +154,9 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_7lihs")
script = ExtResource("6_7lihs")
codeBlocks = NodePath("VBoxContainer/Scripting/CodeBlocks/VBoxContainer")
editorWindow = NodePath("VBoxContainer/Scripting/EditorWindow/CodeContainer/VBoxContainer")
availableScripts = NodePath("VBoxContainer/Scripting/EditorWindow/Load")
scriptName = NodePath("VBoxContainer/Scripting/EditorWindow/Saving/ScriptName")
nameInput = NodePath("VBoxContainer/Renaming/LineEdit")
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" unique_id=582741975]
layout_mode = 2
@@ -254,10 +257,9 @@ layout_mode = 2
size_flags_horizontal = 3
text = "Save"
[node name="Load" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow" unique_id=2064954816]
[node name="Load" type="OptionButton" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow" unique_id=970393437]
layout_mode = 2
size_flags_horizontal = 3
text = "Load script"
[node name="Close" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer" unique_id=200541741]
layout_mode = 2
@@ -430,8 +432,12 @@ layout_mode = 2
tooltip_text = "Menu (ESC)"
texture_normal = ExtResource("12_3so38")
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Renaming/Button" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="SaveRobotName"]
[connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Clear" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="ClearWindow"]
[connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Compile" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CompileProgram"]
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Saving/Save" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="SaveProgram"]
[connection signal="item_selected" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Load" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="LoadProgram"]
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Close" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CloseWindow"]
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button" to="CanvasLayer/UIHandler" method="HandleMenu"]
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button2" to="CanvasLayer/UIHandler" method="ShowOptions"]
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button3" to="CanvasLayer/UIHandler" method="ExitGame"]
+88 -4
View File
@@ -4,11 +4,17 @@ using System.Collections.Generic;
public partial class CodingWindow : PanelContainer
{
//General
Robot robot;
//Scripting
[Export] VBoxContainer codeBlocks;
[Export] VBoxContainer editorWindow;
public Dictionary<ProgramNode, PackedScene> DSLNodes;
Robot robot;
[Export] OptionButton availableScripts;
[Export] LineEdit scriptName;
//Renaming
[Export] LineEdit nameInput;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@@ -23,7 +29,43 @@ public partial class CodingWindow : PanelContainer
}
//Move, Harvest, Craft
public override void _Notification(int id)
{
if (id == NotificationVisibilityChanged)
{
if (Visible) LoadWindow();
}
}
private void LoadWindow()
{
nameInput.Text = robot.Name;
SetupScriptOptions();
ClearWindow();
}
private void SetupScriptOptions()
{
availableScripts.Clear();
availableScripts.AddItem("Select script to load...");
List<string> scripts = FileHandler.LoadProgramNames();
scripts.Sort((a, b) => a.CompareTo(b));
foreach (string script in scripts)
{
availableScripts.AddItem(script);
}
}
public void SaveRobotName()
{
robot.Name = nameInput.Text;
}
public void CloseWindow()
{
Hide();
}
public void GenerateCodingBlocks()
{
NodeDisplay nodeDisplay;
@@ -39,6 +81,10 @@ public partial class CodingWindow : PanelContainer
editorDisplay.node = node;
editorWindow.AddChild(editorDisplay);
editorDisplay.ShowEditorDisplay();
editorDisplay.OnDeleteNode += () =>
{
editorWindow.RemoveChild(editorDisplay);
};
};
}
}
@@ -50,6 +96,7 @@ public partial class CodingWindow : PanelContainer
editorWindow.RemoveChild(node);
node.QueueFree();
}
scriptName.Text = "";
}
public void CompileProgram()
@@ -62,15 +109,52 @@ public partial class CodingWindow : PanelContainer
nodes.Add(editorWindow.GetChild<NodeDisplay>(i).node.Duplicate());
if (i != 0)
{
nodes[i-1].nextNode = nodes[i];
nodes[i - 1].nextNode = nodes[i];
}
}
if(nodes.Count > 0) robot.SetupExecution(nodes);
if (nodes.Count > 0) robot.SetupExecution(nodes);
}
public void SetRobot(Robot robot)
{
this.robot = robot;
}
public void LoadProgram(int index)
{
ClearWindow();
string scriptContent = FileHandler.LoadProgram(availableScripts.GetItemText(index));
string[] nodes = scriptContent.Split(";");
foreach (string node in nodes)
{
NodeDisplay nodeDisplay = NodeDisplay.Load(node, DSLNodes);
if (nodeDisplay != null)
{
editorWindow.AddChild(nodeDisplay);
nodeDisplay.ShowEditorDisplay();
nodeDisplay.OnDeleteNode += () =>
{
editorWindow.RemoveChild(nodeDisplay);
};
}
}
scriptName.Text = availableScripts.GetItemText(index);
availableScripts.Select(0);
}
public void SaveProgram()
{
string result = "";
for (int i = 0; i < editorWindow.GetChildCount(); i++)
{
editorWindow.GetChild<NodeDisplay>(i).node.ReadParameters(editorWindow.GetChild<NodeDisplay>(i));
result += editorWindow.GetChild<NodeDisplay>(i).node.Save();
result += ";\r\n";
}
if (result.Length <= 0) return;
string filename = scriptName.Text.Length <= 0 ? $"Script{availableScripts.ItemCount}" : scriptName.Text;
FileHandler.SaveProgram(filename, result);
SetupScriptOptions();
}
}
+94
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Godot;
public partial class NodeDisplay : PanelContainer
@@ -7,6 +8,9 @@ public partial class NodeDisplay : PanelContainer
[Export] public Button listDisplay;
public ProgramNode node;
[Signal]
public delegate void OnDeleteNodeEventHandler();
public void SetNode(ProgramNode node)
{
this.node = node;
@@ -33,4 +37,94 @@ public partial class NodeDisplay : PanelContainer
editorDisplay.Visible = true;
listDisplay.Visible = false;
}
public void DeleteNodePressed()
{
EmitSignal(SignalName.OnDeleteNode);
}
public static NodeDisplay Load(string content, Dictionary<ProgramNode, PackedScene> DSLNodes)
{
NodeDisplay result = null;
ProgramNode program;
string nodeName;
string nodeSanitized;
PackedScene prefab = null;
nodeSanitized = content.Replace("\r\n", "");
nodeName = nodeSanitized.Split(",")[0].Replace("Name: ", "").ToLower();
foreach (ProgramNode programNode in DSLNodes.Keys)
{
if (programNode.DisplayText.ToLower() == nodeName)
{
prefab = DSLNodes[programNode];
break;
}
}
switch (nodeName)
{
case "move":
program = new MoveNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadMove(nodeSanitized);
break;
case "harvest":
program = new HarvestNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadHarvest(nodeSanitized);
break;
case "explore":
program = new ExploreNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadExplore(nodeSanitized);
break;
case "craft":
program = new CraftNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadCraft(nodeSanitized);
break;
}
return result;
}
public void LoadHarvest(string content)
{
//Currently does nothing
}
public void LoadMove(string content)
{
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
string[] parts = content.Split(",");
string positionValues = parts[1].Replace("Position: ", "").Replace("(", "").Replace(")", "");
int posX = int.Parse(positionValues.Split("|")[0]);
int posY = int.Parse(positionValues.Split("|")[1]);
int posZ = int.Parse(positionValues.Split("|")[2]);
valueContainer.GetNode<SpinBox>("./CoordinateX").Value = posX;
valueContainer.GetNode<SpinBox>("./CoordinateY").Value = posY;
valueContainer.GetNode<SpinBox>("./CoordinateZ").Value = posZ;
(node as MoveNode).targetPosition = new Vector3I(posX, posY, posZ);
}
public void LoadExplore(string content)
{
//Currently does nothing
}
public void LoadCraft(string content)
{
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
string[] parts = content.Split(",");
string itemString = parts[1].Replace("Item: ", "").Replace(" ", "");
if (itemString.ToLower() != "empty")
{
(node as CraftNode).selectedItem = new Item { data = GameData.availableItems[itemString] };
}
string amountString = parts[2].Replace("Amount: ", "");
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
}
}
+82 -65
View File
@@ -1,75 +1,92 @@
using System.Linq;
using Godot;
public class CraftNode : ProgramNode
{
Item selectedItem;
int amount;
public CraftNode()
{
DisplayText = "Craft";
}
public override NodeResult Execute(Robot robot, double delta)
{
if (selectedItem == null)
{
lastExecutionMessage = "No Item selected";
return NodeResult.FAILURE;
}
if (amount <= 0)
{
lastExecutionMessage = "Amount has to be atleast 1";
return NodeResult.FAILURE;
}
if (!GameData.inventory.CanCraft(selectedItem.data.Inputs, amount))
{
lastExecutionMessage = "Not enough items to craft this";
return NodeResult.FAILURE;
}
public Item selectedItem;
public int amount;
public CraftNode()
{
DisplayText = "Craft";
}
public override NodeResult Execute(Robot robot, double delta)
{
if (selectedItem == null)
{
lastExecutionMessage = "No Item selected";
return NodeResult.FAILURE;
}
if (amount <= 0)
{
lastExecutionMessage = "Amount has to be atleast 1";
return NodeResult.FAILURE;
}
if (!GameData.inventory.CanCraft(selectedItem.data.Inputs, amount))
{
lastExecutionMessage = "Not enough items to craft this";
return NodeResult.FAILURE;
}
switch (selectedItem.Craft(amount, delta))
{
case CraftingResult.FAILED:
lastExecutionMessage = "Not enough space to add item to inventory";
return NodeResult.FAILURE;
case CraftingResult.FINISHED:
return NodeResult.SUCCESS;
}
switch (selectedItem.Craft(amount, delta))
{
case CraftingResult.FAILED:
lastExecutionMessage = "Not enough space to add item to inventory";
return NodeResult.FAILURE;
case CraftingResult.FINISHED:
return NodeResult.SUCCESS;
}
return NodeResult.RUNNING;
}
return NodeResult.RUNNING;
}
public override void ReadParameters(NodeDisplay display)
{
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
string readableItem = items.GetItemText(items.GetSelectedId());
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
{
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)]};
}
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
}
public override void ReadParameters(NodeDisplay display)
{
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
string readableItem = items.GetItemText(items.GetSelectedId());
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
{
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
}
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
}
public override ProgramNode Duplicate()
{
CraftNode duplicate = new CraftNode()
{
selectedItem = selectedItem,
amount = amount
};
return duplicate;
}
public override ProgramNode Duplicate()
{
CraftNode duplicate = new CraftNode()
{
selectedItem = selectedItem,
amount = amount
};
return duplicate;
}
public override void Setup(NodeDisplay display)
{
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/HBoxContainer/Item");
options.AddItem("Select item...");
foreach (ItemData item in GameData.availableItems.Values)
{
if (item.Inputs.Count > 0)
{
options.AddItem(item.GetReadableName());
}
}
}
public override void Setup(NodeDisplay display)
{
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/HBoxContainer/Item");
options.AddItem("Select item...");
foreach (ItemData item in GameData.availableItems.Values)
{
if (item.Inputs.Count > 0)
{
options.AddItem(item.GetReadableName());
}
}
if (selectedItem != null)
{
for (int i = 0; i < options.ItemCount; i++)
{
if (ItemData.GetIndex(options.GetItemText(i)) == selectedItem.data.Id)
{
options.Select(i);
break;
}
}
}
}
public override string Save()
{
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Amount: {amount}";
}
}
+5
View File
@@ -92,4 +92,9 @@ public class ExploreNode : ProgramNode
{
//Currently does nothing
}
public override string Save()
{
return $"Name: {DisplayText}";
}
}
+5
View File
@@ -49,4 +49,9 @@ public class HarvestNode : ProgramNode
{
//Currently does nothing
}
public override string Save()
{
return $"Name: {DisplayText}";
}
}
+5
View File
@@ -77,4 +77,9 @@ public class MoveNode : ProgramNode
{
//Currently does nothing
}
public override string Save()
{
return $"Name: {DisplayText}, Position: ({targetPosition.X}|{targetPosition.Y}|{targetPosition.Z})";
}
}
+1
View File
@@ -10,4 +10,5 @@ public abstract class ProgramNode
public abstract NodeResult Execute(Robot robot, double delta);
public abstract void ReadParameters(NodeDisplay display);
public abstract ProgramNode Duplicate();
public abstract string Save();
}
+57
View File
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using Godot;
public class FileHandler()
{
public static void CreateScriptDirectory()
{
DirAccess.MakeDirRecursiveAbsolute("user://scripts");
}
public static void SaveProgram(string filename, string content)
{
CreateScriptDirectory();
string path = $"user://scripts/{filename}.dsl";
FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreString(content);
}
public static List<string> LoadProgramNames()
{
CreateScriptDirectory();
List<string> programs = new List<string>();
DirAccess dir = DirAccess.Open("user://scripts");
if (dir == null)
return programs;
dir.ListDirBegin();
while (true)
{
string fileName = dir.GetNext();
if (fileName == "")
break;
if (!dir.CurrentIsDir() && fileName.EndsWith(".dsl"))
{
programs.Add(fileName.Replace(".dsl", ""));
}
}
dir.ListDirEnd();
return programs;
}
public static string LoadProgram(string name)
{
CreateScriptDirectory();
string path = $"user://scripts/{name}.dsl";
if (!FileAccess.FileExists(path))
return "";
FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
return file.GetAsText();
}
}
+1
View File
@@ -0,0 +1 @@
uid://y6p1ybasi0c2
+1 -1
View File
@@ -18,7 +18,7 @@ public partial class GameData
public static float robotSpeed = 20f;
public static float tileWidth = 6;
public static float tileHeight = 4;
public static Dictionary<string, ItemData> availableItems = ResourceLoader.LoadItems();
public static SortedDictionary<string, ItemData> availableItems = ResourceLoader.LoadItems();
//--- PLAYER ADJUSTABLE VALUES ---
//Color used in primary objects (e.g. Robots)
+2 -2
View File
@@ -85,13 +85,13 @@ public partial class ResourceLoader
return symbols;
}
public static Dictionary<string, ItemData> LoadItems()
public static SortedDictionary<string, ItemData> LoadItems()
{
FileAccess file = FileAccess.Open("res://Assets/Recipes.json", FileAccess.ModeFlags.Read);
string json = file.GetAsText();
Dictionary<string, ItemData> result = new();
SortedDictionary<string, ItemData> result = new();
List<ItemData> items = JsonSerializer.Deserialize<List<ItemData>>(json);
foreach (ItemData item in items)
+8 -1
View File
@@ -26,6 +26,7 @@ public partial class UIHandler : Control
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
DisplayStats();
robotList.OnRobotJumpTo += (robot) =>
{
if(receivedRobotJumpSignal) return;
@@ -35,11 +36,17 @@ public partial class UIHandler : Control
OpenUIElement(codingWindow);
};
//Enable user to write in input fields
Control focused = GetViewport().GuiGetFocusOwner();
if (focused is LineEdit || focused is TextEdit)
return;
if (Input.IsActionJustPressed("map")) HandleMapButton();
if (Input.IsActionJustPressed("menu")) HandleMenuButton();
if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton();
if (Input.IsActionJustPressed("inventory")) HandleInventoryButton();
DisplayStats();
}
public void HandleMenuButton()