Added ability to delete nodes from editor, added complete node load and save for the DSL
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://y6p1ybasi0c2
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user