From 6708aa277f3ef140b0f767a50618a8e2a1015a6b Mon Sep 17 00:00:00 2001 From: Nicola Date: Sat, 9 May 2026 11:29:48 +0200 Subject: [PATCH] Cleaned up project with better structure. --- Prefabs/Crafting/ItemDisplay.tscn | 2 +- Prefabs/DSL/CraftNode.tscn | 2 +- Prefabs/DSL/ExploreNode.tscn | 2 +- Prefabs/DSL/HarvestNode.tscn | 2 +- Prefabs/DSL/MoveNode.tscn | 2 +- Prefabs/Layer.tscn | 2 +- Prefabs/Robot/Robot.tscn | 2 +- Prefabs/Robot/RobotDisplay.tscn | 2 +- Scenes/Game.tscn | 18 +-- Scenes/MainMenu.tscn | 2 +- Scripts/{Helpers => Core}/FileHandler.cs | 28 ++-- Scripts/{Helpers => Core}/FileHandler.cs.uid | 0 Scripts/{Helpers => Core}/GameData.cs | 16 +-- Scripts/{Helpers => Core}/GameData.cs.uid | 0 Scripts/Core/ResourceLoader.cs | 130 ++++++++++++++++++ .../{Helpers => Core}/ResourceLoader.cs.uid | 0 .../{Helpers => Core}/SteamworksHandler.cs | 12 +- .../SteamworksHandler.cs.uid | 0 Scripts/Crafting/ItemDisplay.cs | 19 --- Scripts/DSL/Nodes/CraftNode.cs | 6 +- Scripts/DSL/Nodes/ExploreNode.cs | 10 +- Scripts/DSL/Nodes/HarvestNode.cs | 4 +- Scripts/DSL/Nodes/MoveNode.cs | 9 +- Scripts/{ => Gameplay}/Crafting/Building.cs | 4 +- .../{ => Gameplay}/Crafting/Building.cs.uid | 0 .../{ => Gameplay}/Crafting/CraftingResult.cs | 0 .../Crafting/CraftingResult.cs.uid | 0 .../{ => Gameplay}/Crafting/GameResource.cs | 23 ++-- .../Crafting/GameResource.cs.uid | 0 Scripts/{ => Gameplay}/Crafting/Ingredient.cs | 8 +- .../{ => Gameplay}/Crafting/Ingredient.cs.uid | 0 Scripts/{ => Gameplay}/Crafting/Inventory.cs | 39 +++--- .../{ => Gameplay}/Crafting/Inventory.cs.uid | 0 Scripts/{ => Gameplay}/Crafting/Item.cs | 10 +- Scripts/{ => Gameplay}/Crafting/Item.cs.uid | 0 Scripts/{ => Gameplay}/Crafting/ItemData.cs | 10 +- .../{ => Gameplay}/Crafting/ItemData.cs.uid | 0 Scripts/{ => Gameplay}/Research/Research.cs | 6 +- .../{ => Gameplay}/Research/Research.cs.uid | 0 .../{ => Gameplay}/Research/ResearchData.cs | 3 +- .../Research/ResearchData.cs.uid | 0 .../{ => Gameplay}/Research/ResearchResult.cs | 0 .../Research/ResearchResult.cs.uid | 0 .../{ => Gameplay}/Research/ResearchState.cs | 0 .../Research/ResearchState.cs.uid | 0 Scripts/{Robot => Gameplay/Robots}/Robot.cs | 19 ++- .../{Robot => Gameplay/Robots}/Robot.cs.uid | 0 Scripts/Helpers/MultimeshHandler.cs | 39 ------ Scripts/Helpers/ResourceLoader.cs | 121 ---------------- Scripts/Menus/MainMenu.cs | 25 ---- Scripts/Research/ResearchDisplay.cs | 0 Scripts/Research/ResearchDisplay.cs.uid | 1 - Scripts/{ => UI/Common}/Camera3d.cs | 11 +- Scripts/{ => UI/Common}/Camera3d.cs.uid | 0 Scripts/{Helpers => UI/Common}/UIHandler.cs | 55 ++++---- .../{Helpers => UI/Common}/UIHandler.cs.uid | 0 Scripts/{ => UI}/DSL/CodingWindow.cs | 62 +++++---- Scripts/{ => UI}/DSL/CodingWindow.cs.uid | 0 Scripts/{ => UI}/DSL/NodeDisplay.cs | 99 ++++++------- Scripts/{ => UI}/DSL/NodeDisplay.cs.uid | 0 .../Inventory}/InventoryDisplay.cs | 14 +- .../Inventory}/InventoryDisplay.cs.uid | 0 Scripts/UI/Inventory/ItemDisplay.cs | 9 ++ .../Inventory}/ItemDisplay.cs.uid | 0 Scripts/UI/Menus/MainMenu.cs | 14 ++ Scripts/{ => UI}/Menus/MainMenu.cs.uid | 0 Scripts/{ => UI}/Research/ResearchList.cs | 73 +++++----- Scripts/{ => UI}/Research/ResearchList.cs.uid | 0 Scripts/{Robot => UI/Robots}/RobotDisplay.cs | 10 +- .../{Robot => UI/Robots}/RobotDisplay.cs.uid | 0 Scripts/{Robot => UI/Robots}/RobotList.cs | 11 +- Scripts/{Robot => UI/Robots}/RobotList.cs.uid | 0 Scripts/{WorldGeneration => World}/Layer.cs | 62 ++++----- .../{WorldGeneration => World}/Layer.cs.uid | 0 Scripts/{Helpers => World}/LightHandler.cs | 12 +- .../{Helpers => World}/LightHandler.cs.uid | 0 Scripts/{WorldGeneration => World}/Map.cs | 115 ++++++++-------- Scripts/{WorldGeneration => World}/Map.cs.uid | 0 Scripts/World/MultimeshHandler.cs | 45 ++++++ .../MultimeshHandler.cs.uid | 0 .../{WorldGeneration => World}/Pathfinding.cs | 36 +++-- .../Pathfinding.cs.uid | 0 Scripts/{Helpers => World}/Placeholder.cs | 5 +- Scripts/{Helpers => World}/Placeholder.cs.uid | 0 Scripts/World/ResourceDistributor.cs | 33 +++++ .../ResourceDistributor.cs.uid | 0 Scripts/{WorldGeneration => World}/Tile.cs | 12 +- .../{WorldGeneration => World}/Tile.cs.uid | 0 Scripts/{Structs => World}/TileRenderData.cs | 0 .../{Structs => World}/TileRenderData.cs.uid | 0 Scripts/{WorldGeneration => World}/WFC.cs | 76 +++++----- Scripts/{WorldGeneration => World}/WFC.cs.uid | 0 Scripts/{WorldGeneration => World}/World.cs | 58 ++++---- .../{WorldGeneration => World}/World.cs.uid | 0 .../WorldGeneration/ResourceDistributor.cs | 21 --- 95 files changed, 711 insertions(+), 700 deletions(-) rename Scripts/{Helpers => Core}/FileHandler.cs (61%) rename Scripts/{Helpers => Core}/FileHandler.cs.uid (100%) rename Scripts/{Helpers => Core}/GameData.cs (68%) rename Scripts/{Helpers => Core}/GameData.cs.uid (100%) create mode 100644 Scripts/Core/ResourceLoader.cs rename Scripts/{Helpers => Core}/ResourceLoader.cs.uid (100%) rename Scripts/{Helpers => Core}/SteamworksHandler.cs (68%) rename Scripts/{Helpers => Core}/SteamworksHandler.cs.uid (100%) delete mode 100644 Scripts/Crafting/ItemDisplay.cs rename Scripts/{ => Gameplay}/Crafting/Building.cs (61%) rename Scripts/{ => Gameplay}/Crafting/Building.cs.uid (100%) rename Scripts/{ => Gameplay}/Crafting/CraftingResult.cs (100%) rename Scripts/{ => Gameplay}/Crafting/CraftingResult.cs.uid (100%) rename Scripts/{ => Gameplay}/Crafting/GameResource.cs (78%) rename Scripts/{ => Gameplay}/Crafting/GameResource.cs.uid (100%) rename Scripts/{ => Gameplay}/Crafting/Ingredient.cs (61%) rename Scripts/{ => Gameplay}/Crafting/Ingredient.cs.uid (100%) rename Scripts/{ => Gameplay}/Crafting/Inventory.cs (58%) rename Scripts/{ => Gameplay}/Crafting/Inventory.cs.uid (100%) rename Scripts/{ => Gameplay}/Crafting/Item.cs (86%) rename Scripts/{ => Gameplay}/Crafting/Item.cs.uid (100%) rename Scripts/{ => Gameplay}/Crafting/ItemData.cs (93%) rename Scripts/{ => Gameplay}/Crafting/ItemData.cs.uid (100%) rename Scripts/{ => Gameplay}/Research/Research.cs (98%) rename Scripts/{ => Gameplay}/Research/Research.cs.uid (100%) rename Scripts/{ => Gameplay}/Research/ResearchData.cs (98%) rename Scripts/{ => Gameplay}/Research/ResearchData.cs.uid (100%) rename Scripts/{ => Gameplay}/Research/ResearchResult.cs (100%) rename Scripts/{ => Gameplay}/Research/ResearchResult.cs.uid (100%) rename Scripts/{ => Gameplay}/Research/ResearchState.cs (100%) rename Scripts/{ => Gameplay}/Research/ResearchState.cs.uid (100%) rename Scripts/{Robot => Gameplay/Robots}/Robot.cs (78%) rename Scripts/{Robot => Gameplay/Robots}/Robot.cs.uid (100%) delete mode 100644 Scripts/Helpers/MultimeshHandler.cs delete mode 100644 Scripts/Helpers/ResourceLoader.cs delete mode 100644 Scripts/Menus/MainMenu.cs delete mode 100644 Scripts/Research/ResearchDisplay.cs delete mode 100644 Scripts/Research/ResearchDisplay.cs.uid rename Scripts/{ => UI/Common}/Camera3d.cs (86%) rename Scripts/{ => UI/Common}/Camera3d.cs.uid (100%) rename Scripts/{Helpers => UI/Common}/UIHandler.cs (74%) rename Scripts/{Helpers => UI/Common}/UIHandler.cs.uid (100%) rename Scripts/{ => UI}/DSL/CodingWindow.cs (73%) rename Scripts/{ => UI}/DSL/CodingWindow.cs.uid (100%) rename Scripts/{ => UI}/DSL/NodeDisplay.cs (70%) rename Scripts/{ => UI}/DSL/NodeDisplay.cs.uid (100%) rename Scripts/{Crafting => UI/Inventory}/InventoryDisplay.cs (82%) rename Scripts/{Crafting => UI/Inventory}/InventoryDisplay.cs.uid (100%) create mode 100644 Scripts/UI/Inventory/ItemDisplay.cs rename Scripts/{Crafting => UI/Inventory}/ItemDisplay.cs.uid (100%) create mode 100644 Scripts/UI/Menus/MainMenu.cs rename Scripts/{ => UI}/Menus/MainMenu.cs.uid (100%) rename Scripts/{ => UI}/Research/ResearchList.cs (69%) rename Scripts/{ => UI}/Research/ResearchList.cs.uid (100%) rename Scripts/{Robot => UI/Robots}/RobotDisplay.cs (69%) rename Scripts/{Robot => UI/Robots}/RobotDisplay.cs.uid (100%) rename Scripts/{Robot => UI/Robots}/RobotList.cs (78%) rename Scripts/{Robot => UI/Robots}/RobotList.cs.uid (100%) rename Scripts/{WorldGeneration => World}/Layer.cs (81%) rename Scripts/{WorldGeneration => World}/Layer.cs.uid (100%) rename Scripts/{Helpers => World}/LightHandler.cs (59%) rename Scripts/{Helpers => World}/LightHandler.cs.uid (100%) rename Scripts/{WorldGeneration => World}/Map.cs (60%) rename Scripts/{WorldGeneration => World}/Map.cs.uid (100%) create mode 100644 Scripts/World/MultimeshHandler.cs rename Scripts/{Helpers => World}/MultimeshHandler.cs.uid (100%) rename Scripts/{WorldGeneration => World}/Pathfinding.cs (80%) rename Scripts/{WorldGeneration => World}/Pathfinding.cs.uid (100%) rename Scripts/{Helpers => World}/Placeholder.cs (74%) rename Scripts/{Helpers => World}/Placeholder.cs.uid (100%) create mode 100644 Scripts/World/ResourceDistributor.cs rename Scripts/{WorldGeneration => World}/ResourceDistributor.cs.uid (100%) rename Scripts/{WorldGeneration => World}/Tile.cs (96%) rename Scripts/{WorldGeneration => World}/Tile.cs.uid (100%) rename Scripts/{Structs => World}/TileRenderData.cs (100%) rename Scripts/{Structs => World}/TileRenderData.cs.uid (100%) rename Scripts/{WorldGeneration => World}/WFC.cs (62%) rename Scripts/{WorldGeneration => World}/WFC.cs.uid (100%) rename Scripts/{WorldGeneration => World}/World.cs (81%) rename Scripts/{WorldGeneration => World}/World.cs.uid (100%) delete mode 100644 Scripts/WorldGeneration/ResourceDistributor.cs diff --git a/Prefabs/Crafting/ItemDisplay.tscn b/Prefabs/Crafting/ItemDisplay.tscn index 306b713..a189b92 100644 --- a/Prefabs/Crafting/ItemDisplay.tscn +++ b/Prefabs/Crafting/ItemDisplay.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://4by1t1x6m4yt"] -[ext_resource type="Script" uid="uid://qdjn5oqn6p5d" path="res://Scripts/Crafting/ItemDisplay.cs" id="1_if7q5"] +[ext_resource type="Script" uid="uid://qdjn5oqn6p5d" path="res://Scripts/UI/Inventory/ItemDisplay.cs" id="1_if7q5"] [node name="Item" type="PanelContainer" unique_id=247502695 node_paths=PackedStringArray("texture", "text", "amount")] anchors_preset = 14 diff --git a/Prefabs/DSL/CraftNode.tscn b/Prefabs/DSL/CraftNode.tscn index c3b5495..8e7e961 100644 --- a/Prefabs/DSL/CraftNode.tscn +++ b/Prefabs/DSL/CraftNode.tscn @@ -1,6 +1,6 @@ [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="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/UI/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")] diff --git a/Prefabs/DSL/ExploreNode.tscn b/Prefabs/DSL/ExploreNode.tscn index ba0aff6..a120842 100644 --- a/Prefabs/DSL/ExploreNode.tscn +++ b/Prefabs/DSL/ExploreNode.tscn @@ -1,6 +1,6 @@ [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="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/UI/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")] diff --git a/Prefabs/DSL/HarvestNode.tscn b/Prefabs/DSL/HarvestNode.tscn index 06103c7..82c22bf 100644 --- a/Prefabs/DSL/HarvestNode.tscn +++ b/Prefabs/DSL/HarvestNode.tscn @@ -1,6 +1,6 @@ [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="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/UI/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")] diff --git a/Prefabs/DSL/MoveNode.tscn b/Prefabs/DSL/MoveNode.tscn index e6885a9..3f1a3b6 100644 --- a/Prefabs/DSL/MoveNode.tscn +++ b/Prefabs/DSL/MoveNode.tscn @@ -1,6 +1,6 @@ [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="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/UI/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")] diff --git a/Prefabs/Layer.tscn b/Prefabs/Layer.tscn index f261ad2..3f0cf52 100644 --- a/Prefabs/Layer.tscn +++ b/Prefabs/Layer.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://ck10wk10me3tx"] -[ext_resource type="Script" path="res://Scripts/WorldGeneration/Layer.cs" id="1_trar1"] +[ext_resource type="Script" path="res://Scripts/World/Layer.cs" id="1_trar1"] [node name="Node3D" type="Node3D" unique_id=724642284] script = ExtResource("1_trar1") diff --git a/Prefabs/Robot/Robot.tscn b/Prefabs/Robot/Robot.tscn index 94e7491..f678455 100644 --- a/Prefabs/Robot/Robot.tscn +++ b/Prefabs/Robot/Robot.tscn @@ -1,7 +1,7 @@ [gd_scene format=3 uid="uid://dciwxejdji2lg"] [ext_resource type="PackedScene" uid="uid://cjae60v4c60vb" path="res://Prefabs/Robot/RobotVisual.tscn" id="2_3hvm5"] -[ext_resource type="Script" uid="uid://e0pgy7jya41y" path="res://Scripts/Robot/Robot.cs" id="2_j80uv"] +[ext_resource type="Script" uid="uid://e0pgy7jya41y" path="res://Scripts/Gameplay/Robots/Robot.cs" id="2_j80uv"] [sub_resource type="BoxShape3D" id="BoxShape3D_vquur"] size = Vector3(1.1176758, 0.7307129, 1.0234375) diff --git a/Prefabs/Robot/RobotDisplay.tscn b/Prefabs/Robot/RobotDisplay.tscn index 126717d..00ed7f6 100644 --- a/Prefabs/Robot/RobotDisplay.tscn +++ b/Prefabs/Robot/RobotDisplay.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://dribqey54i62n"] -[ext_resource type="Script" uid="uid://dcxom1paffp0p" path="res://Scripts/Robot/RobotDisplay.cs" id="1_ltmdd"] +[ext_resource type="Script" uid="uid://dcxom1paffp0p" path="res://Scripts/UI/Robots/RobotDisplay.cs" id="1_ltmdd"] [node name="Robot" type="PanelContainer" unique_id=247502695 node_paths=PackedStringArray("listItem", "currentScript")] anchors_preset = 14 diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index a68082e..e949c93 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -1,21 +1,21 @@ [gd_scene format=3 uid="uid://cgsmfi2s51cbd"] -[ext_resource type="Script" uid="uid://br2udyi6t8yvf" path="res://Scripts/WorldGeneration/World.cs" id="1_7lihs"] -[ext_resource type="Script" uid="uid://dqrdb3bvws6b6" path="res://Scripts/Helpers/SteamworksHandler.cs" id="2_b2bpf"] -[ext_resource type="Script" uid="uid://c7khr6oist3ku" path="res://Scripts/Camera3d.cs" id="3_7lihs"] -[ext_resource type="Script" uid="uid://bm7knir4552j5" path="res://Scripts/Helpers/UIHandler.cs" id="4_fgofq"] -[ext_resource type="Script" uid="uid://bsd6n6b06a4pe" path="res://Scripts/DSL/CodingWindow.cs" id="6_7lihs"] -[ext_resource type="Script" uid="uid://k6vlo7ulvtep" path="res://Scripts/Robot/RobotList.cs" id="7_2irst"] +[ext_resource type="Script" uid="uid://br2udyi6t8yvf" path="res://Scripts/World/World.cs" id="1_7lihs"] +[ext_resource type="Script" uid="uid://dqrdb3bvws6b6" path="res://Scripts/Core/SteamworksHandler.cs" id="2_b2bpf"] +[ext_resource type="Script" uid="uid://c7khr6oist3ku" path="res://Scripts/UI/Common/Camera3d.cs" id="3_7lihs"] +[ext_resource type="Script" uid="uid://bm7knir4552j5" path="res://Scripts/UI/Common/UIHandler.cs" id="4_fgofq"] +[ext_resource type="Script" uid="uid://bsd6n6b06a4pe" path="res://Scripts/UI/DSL/CodingWindow.cs" id="6_7lihs"] +[ext_resource type="Script" uid="uid://k6vlo7ulvtep" path="res://Scripts/UI/Robots/RobotList.cs" id="7_2irst"] [ext_resource type="PackedScene" uid="uid://cpq7ppe8bw2bq" path="res://Scenes/Options.tscn" id="8_71axn"] -[ext_resource type="Script" uid="uid://fegfbcnlk8p5" path="res://Scripts/WorldGeneration/Map.cs" id="8_bf53h"] +[ext_resource type="Script" uid="uid://fegfbcnlk8p5" path="res://Scripts/World/Map.cs" id="8_bf53h"] [ext_resource type="Texture2D" uid="uid://deuxffyhsrinn" path="res://Assets/Images/EnergySymbol.png" id="9_71axn"] [ext_resource type="Texture2D" uid="uid://dje86ro2e37xl" path="res://Assets/Images/Resources/WaterSymbol.png" id="10_71axn"] [ext_resource type="Texture2D" uid="uid://d068gyi3e48cv" path="res://Assets/Images/MapSymbol.png" id="11_3cx6b"] -[ext_resource type="Script" uid="uid://com0u7nqag6pp" path="res://Scripts/Crafting/InventoryDisplay.cs" id="11_acvyw"] +[ext_resource type="Script" uid="uid://com0u7nqag6pp" path="res://Scripts/UI/Inventory/InventoryDisplay.cs" id="11_acvyw"] [ext_resource type="Texture2D" uid="uid://ban872p4eh4gi" path="res://Assets/Images/RobotSymbol.png" id="11_dahhg"] [ext_resource type="Texture2D" uid="uid://ciehcg34et0q3" path="res://Assets/Images/InventorySymbol.png" id="11_wxwew"] [ext_resource type="Texture2D" uid="uid://b77mo4fhklnja" path="res://Assets/Images/OptionsSymbol.png" id="12_3so38"] -[ext_resource type="Script" uid="uid://drscsrkfphpy7" path="res://Scripts/Research/ResearchList.cs" id="12_4q8tf"] +[ext_resource type="Script" uid="uid://drscsrkfphpy7" path="res://Scripts/UI/Research/ResearchList.cs" id="12_4q8tf"] [ext_resource type="Texture2D" uid="uid://dt84awx33mulb" path="res://Assets/Images/ResearchSymbol.png" id="13_alh3a"] [ext_resource type="Texture2D" uid="uid://bmcpkt6mae2qi" path="res://Assets/Images/AlarmSign.png" id="13_x3xnh"] diff --git a/Scenes/MainMenu.tscn b/Scenes/MainMenu.tscn index 29b1392..0e5e1bc 100644 --- a/Scenes/MainMenu.tscn +++ b/Scenes/MainMenu.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://dlommaelbbw2b"] -[ext_resource type="Script" uid="uid://dda0bhhqspbr0" path="res://Scripts/Menus/MainMenu.cs" id="1_tt5f1"] +[ext_resource type="Script" uid="uid://dda0bhhqspbr0" path="res://Scripts/UI/Menus/MainMenu.cs" id="1_tt5f1"] [ext_resource type="Texture2D" uid="uid://ban872p4eh4gi" path="res://Assets/Images/RobotSymbol.png" id="2_853f1"] [ext_resource type="Texture2D" uid="uid://dt84awx33mulb" path="res://Assets/Images/ResearchSymbol.png" id="3_df05h"] [ext_resource type="Texture2D" uid="uid://dm0w2gtcsa5l4" path="res://Assets/Images/Items/Batteryv1Symbol.png" id="4_8um5k"] diff --git a/Scripts/Helpers/FileHandler.cs b/Scripts/Core/FileHandler.cs similarity index 61% rename from Scripts/Helpers/FileHandler.cs rename to Scripts/Core/FileHandler.cs index befb9ce..f2aaf69 100644 --- a/Scripts/Helpers/FileHandler.cs +++ b/Scripts/Core/FileHandler.cs @@ -1,17 +1,20 @@ using System.Collections.Generic; using Godot; -public class FileHandler() +public class FileHandler { + private const string ScriptDirectory = "user://scripts"; + private const string ScriptExtension = ".dsl"; + public static void CreateScriptDirectory() { - DirAccess.MakeDirRecursiveAbsolute("user://scripts"); + DirAccess.MakeDirRecursiveAbsolute(ScriptDirectory); } public static void SaveProgram(string filename, string content) { CreateScriptDirectory(); - string path = $"user://scripts/{filename}.dsl"; + string path = GetProgramPath(filename); FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Write); file.StoreString(content); @@ -22,9 +25,11 @@ public class FileHandler() CreateScriptDirectory(); List programs = new List(); - DirAccess dir = DirAccess.Open("user://scripts"); + DirAccess dir = DirAccess.Open(ScriptDirectory); if (dir == null) + { return programs; + } dir.ListDirBegin(); while (true) @@ -33,9 +38,9 @@ public class FileHandler() if (fileName == "") break; - if (!dir.CurrentIsDir() && fileName.EndsWith(".dsl")) + if (!dir.CurrentIsDir() && fileName.EndsWith(ScriptExtension)) { - programs.Add(fileName.Replace(".dsl", "")); + programs.Add(fileName.Replace(ScriptExtension, "")); } } dir.ListDirEnd(); @@ -46,12 +51,19 @@ public class FileHandler() public static string LoadProgram(string name) { CreateScriptDirectory(); - string path = $"user://scripts/{name}.dsl"; + string path = GetProgramPath(name); if (!FileAccess.FileExists(path)) + { return ""; + } FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Read); return file.GetAsText(); } -} \ No newline at end of file + + private static string GetProgramPath(string filename) + { + return $"{ScriptDirectory}/{filename}{ScriptExtension}"; + } +} diff --git a/Scripts/Helpers/FileHandler.cs.uid b/Scripts/Core/FileHandler.cs.uid similarity index 100% rename from Scripts/Helpers/FileHandler.cs.uid rename to Scripts/Core/FileHandler.cs.uid diff --git a/Scripts/Helpers/GameData.cs b/Scripts/Core/GameData.cs similarity index 68% rename from Scripts/Helpers/GameData.cs rename to Scripts/Core/GameData.cs index 98a4bfa..c92e435 100644 --- a/Scripts/Helpers/GameData.cs +++ b/Scripts/Core/GameData.cs @@ -4,15 +4,14 @@ using Godot; public partial class GameData { - public static bool DEBUGMODE = false; + public static bool debugMode = false; public static Random rand = new Random(seed); public static Layer[] map; - //Current layer the player wants to see + public static int currentLayer = 0; - //The layer that is currently visible public static int visibleLayer = 0; public static int lowestLayer = 0; - //Determines if the player can move the camera or not (Necessary for input and options menu) + public static bool canMove = true; public static int maxRobotCount = 1000; public static List robots = new List(); @@ -22,19 +21,12 @@ public partial class GameData public static SortedDictionary availableItems = ResourceLoader.LoadItems(); public static Dictionary availableResearch = ResourceLoader.LoadResearch(); - //--- PLAYER ADJUSTABLE VALUES --- - //Color used in primary objects (e.g. Robots) public static Color primaryColor = new Color("#276ac2"); - //Color used in lights public static Color lightColor = new Color("#7efff5"); - //Amount of layers generated + public static int ruinSize = 10; - //Width+Height of layers public static int layerSize = 20; - //Seed used for all random generation except WFC public static int seed = 12345; - //--- PLAYER VALUES --- public static Inventory inventory = new Inventory(); - } diff --git a/Scripts/Helpers/GameData.cs.uid b/Scripts/Core/GameData.cs.uid similarity index 100% rename from Scripts/Helpers/GameData.cs.uid rename to Scripts/Core/GameData.cs.uid diff --git a/Scripts/Core/ResourceLoader.cs b/Scripts/Core/ResourceLoader.cs new file mode 100644 index 0000000..ccbcdf8 --- /dev/null +++ b/Scripts/Core/ResourceLoader.cs @@ -0,0 +1,130 @@ +using Godot; +using System.Collections.Generic; +using System.Text.Json; + +public partial class ResourceLoader +{ + private const string LayerPrefabPath = "res://Prefabs/Layer.tscn"; + private const string RobotPrefabPath = "res://Prefabs/Robot/Robot.tscn"; + private const string RobotDisplayPath = "res://Prefabs/Robot/RobotDisplay.tscn"; + private const string ItemDisplayPath = "res://Prefabs/Crafting/ItemDisplay.tscn"; + private const string RecipesPath = "res://Assets/Recipes.json"; + private const string ResearchPath = "res://Assets/Research.json"; + + public static PackedScene LoadLayerPrefab() + { + return GD.Load(LayerPrefabPath); + } + + public static PackedScene LoadRobotPrefab() + { + return GD.Load(RobotPrefabPath); + } + + public static PackedScene LoadRobotDisplay() + { + return GD.Load(RobotDisplayPath); + } + + public static PackedScene LoadItemDisplay() + { + return GD.Load(ItemDisplayPath); + } + + public static Texture2D LoadPath(string path) + { + return GD.Load(path); + } + + public static Dictionary LoadTiles() + { + Dictionary tileMeshes = new Dictionary(); + PackedScene tileCollection = GD.Load($"res://Assets/Objects/Tiles.glb"); + Node root = tileCollection.Instantiate(); + foreach (MeshInstance3D child in root.GetChildren()) + { + tileMeshes.Add(child.Name.ToString().ToLower(), child); + } + + return tileMeshes; + } + + public static Dictionary LoadDecorations() + { + Dictionary decorationMeshes = new Dictionary(); + PackedScene decorationCollection = GD.Load($"res://Assets/Objects/Decorations.glb"); + Node root = decorationCollection.Instantiate(); + foreach (MeshInstance3D child in root.GetChildren()) + { + decorationMeshes.Add(child.Name.ToString().ToLower(), child); + } + + return decorationMeshes; + } + + public static Dictionary LoadDSLNodes() + { + Dictionary nodes = new Dictionary() + { + { new MoveNode(), GD.Load("res://Prefabs/DSL/MoveNode.tscn") }, + { new HarvestNode(), GD.Load("res://Prefabs/DSL/HarvestNode.tscn") }, + { new CraftNode(), GD.Load("res://Prefabs/DSL/CraftNode.tscn") }, + { new ExploreNode(), GD.Load("res://Prefabs/DSL/ExploreNode.tscn") } + }; + return nodes; + } + + public static Dictionary LoadResourceSymbols() + { + Dictionary symbols = new Dictionary() + { + { "iron_ore", GD.Load("res://Assets/Images/Resources/IronSymbol.png") }, + { "tin_ore", GD.Load("res://Assets/Images/Resources/TinSymbol.png") }, + { "copper_ore", GD.Load("res://Assets/Images/Resources/CopperSymbol.png") }, + { "mushroom", GD.Load("res://Assets/Images/Resources/MushroomSymbol.png") }, + { "spider_silk", GD.Load("res://Assets/Images/Resources/SpiderSilkSymbol.png") }, + { "coal", GD.Load("res://Assets/Images/Resources/CoalSymbol.png") }, + { "water", GD.Load("res://Assets/Images/Resources/WaterSymbol.png") }, + { "stone", GD.Load("res://Assets/Images/Resources/StoneSymbol.png") }, + }; + return symbols; + } + + public static SortedDictionary LoadItems() + { + + FileAccess file = FileAccess.Open(RecipesPath, FileAccess.ModeFlags.Read); + string json = file.GetAsText(); + + SortedDictionary result = new SortedDictionary(); + + List items = JsonSerializer.Deserialize>(json); + if (items == null) return result; + + foreach (ItemData item in items) + { + result.Add(item.Id, item); + } + + return result; + } + + public static Dictionary LoadResearch() + { + + FileAccess file = FileAccess.Open(ResearchPath, FileAccess.ModeFlags.Read); + string json = file.GetAsText(); + + Dictionary result = new Dictionary(); + + List researches = JsonSerializer.Deserialize>(json); + if (researches == null) return result; + + foreach (ResearchData research in researches) + { + result.Add(research.Id, new Research(research)); + } + + return result; + } +} diff --git a/Scripts/Helpers/ResourceLoader.cs.uid b/Scripts/Core/ResourceLoader.cs.uid similarity index 100% rename from Scripts/Helpers/ResourceLoader.cs.uid rename to Scripts/Core/ResourceLoader.cs.uid diff --git a/Scripts/Helpers/SteamworksHandler.cs b/Scripts/Core/SteamworksHandler.cs similarity index 68% rename from Scripts/Helpers/SteamworksHandler.cs rename to Scripts/Core/SteamworksHandler.cs index 667fd16..788de29 100644 --- a/Scripts/Helpers/SteamworksHandler.cs +++ b/Scripts/Core/SteamworksHandler.cs @@ -1,10 +1,15 @@ using Godot; using GodotSteam; + public partial class SteamworksHandler : Node { + [Export] private bool enableSteam = false; + private bool isSteamInitialized = false; + public override void _Ready() { - return; + if (!enableSteam) return; + SteamInitExStatus status = Steam.SteamInitEx(false).Status; if (status != 0) { @@ -14,15 +19,20 @@ public partial class SteamworksHandler : Node GD.Print("Steam initialized!"); GD.Print("User: " + Steam.GetPersonaName()); + isSteamInitialized = true; } public override void _Process(double delta) { + if (!isSteamInitialized) return; + Steam.RunCallbacks(); } public override void _ExitTree() { + if (!isSteamInitialized) return; + Steam.SteamShutdown(); } } diff --git a/Scripts/Helpers/SteamworksHandler.cs.uid b/Scripts/Core/SteamworksHandler.cs.uid similarity index 100% rename from Scripts/Helpers/SteamworksHandler.cs.uid rename to Scripts/Core/SteamworksHandler.cs.uid diff --git a/Scripts/Crafting/ItemDisplay.cs b/Scripts/Crafting/ItemDisplay.cs deleted file mode 100644 index c2003bb..0000000 --- a/Scripts/Crafting/ItemDisplay.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Godot; -using System; - -public partial class ItemDisplay : PanelContainer -{ - [Export] public TextureRect texture; - [Export] public RichTextLabel text; - [Export] public RichTextLabel amount; - public Item item; - // Called when the node enters the scene tree for the first time. - public override void _Ready() - { - } - - // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(double delta) - { - } -} diff --git a/Scripts/DSL/Nodes/CraftNode.cs b/Scripts/DSL/Nodes/CraftNode.cs index ed9cf6c..d6cdd42 100644 --- a/Scripts/DSL/Nodes/CraftNode.cs +++ b/Scripts/DSL/Nodes/CraftNode.cs @@ -1,4 +1,3 @@ -using System.Linq; using Godot; public class CraftNode : ProgramNode @@ -16,11 +15,13 @@ public class CraftNode : ProgramNode 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"; @@ -67,12 +68,13 @@ public class CraftNode : ProgramNode options.AddItem("Select item..."); foreach (ItemData item in GameData.availableItems.Values) { - if(GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue; + if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue; if (item.Inputs.Count > 0) { options.AddItem(item.GetCraftingDisplay()); } } + if (selectedItem != null) { for (int i = 0; i < options.ItemCount; i++) diff --git a/Scripts/DSL/Nodes/ExploreNode.cs b/Scripts/DSL/Nodes/ExploreNode.cs index 5ffa469..773e8ef 100644 --- a/Scripts/DSL/Nodes/ExploreNode.cs +++ b/Scripts/DSL/Nodes/ExploreNode.cs @@ -16,9 +16,10 @@ public class ExploreNode : ProgramNode if (pathPoints == null) { int safetyCounter = 0; + int layerRange = Math.Max(GameData.lowestLayer, 1); while (true) { - targetPosition = new Vector3I(GameData.rand.Next(GameData.layerSize), GameData.rand.Next(GameData.lowestLayer), GameData.rand.Next(GameData.layerSize)); + targetPosition = new Vector3I(GameData.rand.Next(GameData.layerSize), GameData.rand.Next(layerRange), GameData.rand.Next(GameData.layerSize)); if (!GameData.map[targetPosition.Y].tiles[targetPosition.X, targetPosition.Z].wasVisited) break; safetyCounter++; if (safetyCounter > Math.Pow(GameData.layerSize, 2) * 2) @@ -29,7 +30,7 @@ public class ExploreNode : ProgramNode } } - pathPoints ??= [.. Pathfinding.GetPath(Pathfinding.GetClosestStartPoint(robot.Position), targetPosition)]; + pathPoints ??= new List(Pathfinding.GetPath(Pathfinding.GetClosestStartPoint(robot.Position), targetPosition)); if (pathPoints.Count <= 0) { @@ -50,6 +51,7 @@ public class ExploreNode : ProgramNode { tile.VisitTile(); } + pathPoints.Remove(pathPoints[0]); if (pathPoints.Count <= 0) { @@ -84,16 +86,14 @@ public class ExploreNode : ProgramNode public override void ReadParameters(NodeDisplay display) { - //Currently does nothing } public override void Setup(NodeDisplay display) { - //Currently does nothing } public override string Save() { return $"Name: {DisplayText}"; } -} \ No newline at end of file +} diff --git a/Scripts/DSL/Nodes/HarvestNode.cs b/Scripts/DSL/Nodes/HarvestNode.cs index 9064d24..1aa2514 100644 --- a/Scripts/DSL/Nodes/HarvestNode.cs +++ b/Scripts/DSL/Nodes/HarvestNode.cs @@ -36,7 +36,6 @@ public class HarvestNode : ProgramNode public override void ReadParameters(NodeDisplay display) { - //Currently does nothing } public override ProgramNode Duplicate() @@ -47,11 +46,10 @@ public class HarvestNode : ProgramNode public override void Setup(NodeDisplay display) { - //Currently does nothing } public override string Save() { return $"Name: {DisplayText}"; } -} \ No newline at end of file +} diff --git a/Scripts/DSL/Nodes/MoveNode.cs b/Scripts/DSL/Nodes/MoveNode.cs index 61bda06..78fc252 100644 --- a/Scripts/DSL/Nodes/MoveNode.cs +++ b/Scripts/DSL/Nodes/MoveNode.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using Godot; @@ -13,12 +12,14 @@ public class MoveNode : ProgramNode } public override NodeResult Execute(Robot robot, double delta) { - pathPoints ??= [.. Pathfinding.GetPath(Pathfinding.GetClosestStartPoint(robot.Position), targetPosition)]; + pathPoints ??= new List(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,6 +33,7 @@ public class MoveNode : ProgramNode { tile.VisitTile(); } + pathPoints.Remove(pathPoints[0]); if (pathPoints.Count <= 0) { @@ -74,11 +76,10 @@ public class MoveNode : ProgramNode public override void Setup(NodeDisplay display) { - //Currently does nothing } public override string Save() { return $"Name: {DisplayText}, Position: ({targetPosition.X}|{targetPosition.Y}|{targetPosition.Z})"; } -} \ No newline at end of file +} diff --git a/Scripts/Crafting/Building.cs b/Scripts/Gameplay/Crafting/Building.cs similarity index 61% rename from Scripts/Crafting/Building.cs rename to Scripts/Gameplay/Crafting/Building.cs index ba88a9d..93505a1 100644 --- a/Scripts/Crafting/Building.cs +++ b/Scripts/Gameplay/Crafting/Building.cs @@ -1,5 +1,3 @@ -using Godot; - public class Building { -} \ No newline at end of file +} diff --git a/Scripts/Crafting/Building.cs.uid b/Scripts/Gameplay/Crafting/Building.cs.uid similarity index 100% rename from Scripts/Crafting/Building.cs.uid rename to Scripts/Gameplay/Crafting/Building.cs.uid diff --git a/Scripts/Crafting/CraftingResult.cs b/Scripts/Gameplay/Crafting/CraftingResult.cs similarity index 100% rename from Scripts/Crafting/CraftingResult.cs rename to Scripts/Gameplay/Crafting/CraftingResult.cs diff --git a/Scripts/Crafting/CraftingResult.cs.uid b/Scripts/Gameplay/Crafting/CraftingResult.cs.uid similarity index 100% rename from Scripts/Crafting/CraftingResult.cs.uid rename to Scripts/Gameplay/Crafting/CraftingResult.cs.uid diff --git a/Scripts/Crafting/GameResource.cs b/Scripts/Gameplay/Crafting/GameResource.cs similarity index 78% rename from Scripts/Crafting/GameResource.cs rename to Scripts/Gameplay/Crafting/GameResource.cs index 692efa3..1059ab8 100644 --- a/Scripts/Crafting/GameResource.cs +++ b/Scripts/Gameplay/Crafting/GameResource.cs @@ -1,15 +1,14 @@ -using Godot; - public class GameResource { public string name; - int currentAmount; - int maxAmount; - bool isEndless; - float extractionSpeed; - double timeSinceLastExtraction; public ItemData item; + private int currentAmount; + private int maxAmount; + private bool isEndless; + private float extractionSpeed; + private double timeSinceLastExtraction; + public GameResource(string name) { this.name = name; @@ -24,14 +23,16 @@ public class GameResource { timeSinceLastExtraction += delta; if (timeSinceLastExtraction < extractionSpeed) return false; + timeSinceLastExtraction = 0; - if(isEndless) return true; + if (isEndless) return true; + if (currentAmount > 0) { currentAmount--; - - return true; + return true; } + return false; } @@ -39,4 +40,4 @@ public class GameResource { return (isEndless || currentAmount > 0) && GameData.availableResearch[item.Research].state == ResearchState.RESEARCHED; } -} \ No newline at end of file +} diff --git a/Scripts/Crafting/GameResource.cs.uid b/Scripts/Gameplay/Crafting/GameResource.cs.uid similarity index 100% rename from Scripts/Crafting/GameResource.cs.uid rename to Scripts/Gameplay/Crafting/GameResource.cs.uid diff --git a/Scripts/Crafting/Ingredient.cs b/Scripts/Gameplay/Crafting/Ingredient.cs similarity index 61% rename from Scripts/Crafting/Ingredient.cs rename to Scripts/Gameplay/Crafting/Ingredient.cs index 5b69187..bcaff09 100644 --- a/Scripts/Crafting/Ingredient.cs +++ b/Scripts/Gameplay/Crafting/Ingredient.cs @@ -1,10 +1,10 @@ using System.Text.Json.Serialization; -using Godot; public class Ingredient { [JsonPropertyName("item")] - public string Item {get; set;} + public string Item { get; set; } + [JsonPropertyName("amount")] - public int Amount {get;set;} -} \ No newline at end of file + public int Amount { get; set; } +} diff --git a/Scripts/Crafting/Ingredient.cs.uid b/Scripts/Gameplay/Crafting/Ingredient.cs.uid similarity index 100% rename from Scripts/Crafting/Ingredient.cs.uid rename to Scripts/Gameplay/Crafting/Ingredient.cs.uid diff --git a/Scripts/Crafting/Inventory.cs b/Scripts/Gameplay/Crafting/Inventory.cs similarity index 58% rename from Scripts/Crafting/Inventory.cs rename to Scripts/Gameplay/Crafting/Inventory.cs index 1201e58..6236c2e 100644 --- a/Scripts/Crafting/Inventory.cs +++ b/Scripts/Gameplay/Crafting/Inventory.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; -using Godot; public class Inventory { - public List items = new(); + public List items = new List(); public int maxInventorySize = 8; public event EventHandler OnInventoryUpdate; @@ -15,36 +14,33 @@ public class Inventory if (inventoryItem != null) { inventoryItem.currentAmount += amount; - OnInventoryUpdate?.Invoke(this, EventArgs.Empty); + NotifyInventoryChanged(); return true; } - else + + if (items.Count < maxInventorySize) { - if (items.Count < maxInventorySize) - { - items.Add(item); - items[items.Count - 1].currentAmount += amount; - OnInventoryUpdate?.Invoke(this, EventArgs.Empty); - return true; - } + items.Add(item); + items[items.Count - 1].currentAmount += amount; + NotifyInventoryChanged(); + return true; } + return false; } public bool CanCraft(List neededIngredients, int amount) { - bool canCraft = true; - Item item; foreach (Ingredient ingredient in neededIngredients) { - item = items.Find(x => x.data.Id == ingredient.Item && x.currentAmount >= ingredient.Amount * amount); + Item item = items.Find(x => x.data.Id == ingredient.Item && x.currentAmount >= ingredient.Amount * amount); if (item == null) { - canCraft = false; - break; + return false; } } - return canCraft; + + return true; } public void RemoveItem(string id, int amount) @@ -53,7 +49,12 @@ public class Inventory if (item != null) { item.currentAmount -= amount; - OnInventoryUpdate?.Invoke(this, EventArgs.Empty); + NotifyInventoryChanged(); } } -} \ No newline at end of file + + private void NotifyInventoryChanged() + { + OnInventoryUpdate?.Invoke(this, EventArgs.Empty); + } +} diff --git a/Scripts/Crafting/Inventory.cs.uid b/Scripts/Gameplay/Crafting/Inventory.cs.uid similarity index 100% rename from Scripts/Crafting/Inventory.cs.uid rename to Scripts/Gameplay/Crafting/Inventory.cs.uid diff --git a/Scripts/Crafting/Item.cs b/Scripts/Gameplay/Crafting/Item.cs similarity index 86% rename from Scripts/Crafting/Item.cs rename to Scripts/Gameplay/Crafting/Item.cs index 7051864..7a9f8bb 100644 --- a/Scripts/Crafting/Item.cs +++ b/Scripts/Gameplay/Crafting/Item.cs @@ -1,7 +1,3 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using Godot; - public class Item { public ItemData data; @@ -15,14 +11,16 @@ public class Item if (elapsedCraftTime >= data.CraftTime) { elapsedCraftTime -= data.CraftTime; - if(!GameData.inventory.AddItem(this, 1)) + if (!GameData.inventory.AddItem(this, 1)) { return CraftingResult.FAILED; } + foreach (Ingredient ingredient in data.Inputs) { GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount); } + amountCrafted++; if (amountCrafted >= amount) { @@ -31,7 +29,7 @@ public class Item return CraftingResult.FINISHED; } } + return CraftingResult.CRAFTING; } } - diff --git a/Scripts/Crafting/Item.cs.uid b/Scripts/Gameplay/Crafting/Item.cs.uid similarity index 100% rename from Scripts/Crafting/Item.cs.uid rename to Scripts/Gameplay/Crafting/Item.cs.uid diff --git a/Scripts/Crafting/ItemData.cs b/Scripts/Gameplay/Crafting/ItemData.cs similarity index 93% rename from Scripts/Crafting/ItemData.cs rename to Scripts/Gameplay/Crafting/ItemData.cs index 566fd4e..d334421 100644 --- a/Scripts/Crafting/ItemData.cs +++ b/Scripts/Gameplay/Crafting/ItemData.cs @@ -1,4 +1,3 @@ -using Godot; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -47,13 +46,16 @@ public class ItemData public string GetCraftingDisplay() { - string result = ""; - result += GetReadableName() + ": \r"; + string result = GetReadableName() + ": \r"; + foreach (Ingredient ingredient in Inputs) { result += $"{GetReadableName(ingredient.Item)} ({ingredient.Amount}),\r"; } + + if (Inputs.Count <= 0) return result; + result = result.Remove(result.Length - 2); return result; } -} \ No newline at end of file +} diff --git a/Scripts/Crafting/ItemData.cs.uid b/Scripts/Gameplay/Crafting/ItemData.cs.uid similarity index 100% rename from Scripts/Crafting/ItemData.cs.uid rename to Scripts/Gameplay/Crafting/ItemData.cs.uid diff --git a/Scripts/Research/Research.cs b/Scripts/Gameplay/Research/Research.cs similarity index 98% rename from Scripts/Research/Research.cs rename to Scripts/Gameplay/Research/Research.cs index c818120..14d7e6a 100644 --- a/Scripts/Research/Research.cs +++ b/Scripts/Gameplay/Research/Research.cs @@ -1,5 +1,3 @@ -using Godot; - public class Research { public ResearchData data; @@ -23,12 +21,14 @@ public class Research } paidResources = true; } + elapsedResearchTime += delta; if (elapsedResearchTime >= data.CraftTime) { state = ResearchState.RESEARCHED; return ResearchResult.FINISHED; } + return ResearchResult.RESEARCHING; } -} \ No newline at end of file +} diff --git a/Scripts/Research/Research.cs.uid b/Scripts/Gameplay/Research/Research.cs.uid similarity index 100% rename from Scripts/Research/Research.cs.uid rename to Scripts/Gameplay/Research/Research.cs.uid diff --git a/Scripts/Research/ResearchData.cs b/Scripts/Gameplay/Research/ResearchData.cs similarity index 98% rename from Scripts/Research/ResearchData.cs rename to Scripts/Gameplay/Research/ResearchData.cs index 5d6e4e4..e28ff7c 100644 --- a/Scripts/Research/ResearchData.cs +++ b/Scripts/Gameplay/Research/ResearchData.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -using Godot; public class ResearchData { @@ -29,4 +28,4 @@ public class ResearchData { return readable.ToLower().Replace(" ", "_"); } -} \ No newline at end of file +} diff --git a/Scripts/Research/ResearchData.cs.uid b/Scripts/Gameplay/Research/ResearchData.cs.uid similarity index 100% rename from Scripts/Research/ResearchData.cs.uid rename to Scripts/Gameplay/Research/ResearchData.cs.uid diff --git a/Scripts/Research/ResearchResult.cs b/Scripts/Gameplay/Research/ResearchResult.cs similarity index 100% rename from Scripts/Research/ResearchResult.cs rename to Scripts/Gameplay/Research/ResearchResult.cs diff --git a/Scripts/Research/ResearchResult.cs.uid b/Scripts/Gameplay/Research/ResearchResult.cs.uid similarity index 100% rename from Scripts/Research/ResearchResult.cs.uid rename to Scripts/Gameplay/Research/ResearchResult.cs.uid diff --git a/Scripts/Research/ResearchState.cs b/Scripts/Gameplay/Research/ResearchState.cs similarity index 100% rename from Scripts/Research/ResearchState.cs rename to Scripts/Gameplay/Research/ResearchState.cs diff --git a/Scripts/Research/ResearchState.cs.uid b/Scripts/Gameplay/Research/ResearchState.cs.uid similarity index 100% rename from Scripts/Research/ResearchState.cs.uid rename to Scripts/Gameplay/Research/ResearchState.cs.uid diff --git a/Scripts/Robot/Robot.cs b/Scripts/Gameplay/Robots/Robot.cs similarity index 78% rename from Scripts/Robot/Robot.cs rename to Scripts/Gameplay/Robots/Robot.cs index 527d4b2..b848d47 100644 --- a/Scripts/Robot/Robot.cs +++ b/Scripts/Gameplay/Robots/Robot.cs @@ -1,21 +1,16 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; using Godot; public partial class Robot : Node3D { - List nodes; - bool isExecuting = false; - ProgramNode currentNode; + private List nodes = new List(); + private bool isExecuting = false; + private ProgramNode currentNode; + public string currentProgram; public string currentMessage = ""; - public override void _Ready() - { - - } - public override void _Process(double delta) { if (isExecuting) @@ -38,7 +33,7 @@ public partial class Robot : Node3D break; } } - else if(currentMessage.Length <= 0) + else if (currentMessage.Length <= 0) { currentMessage = "No script executing"; } @@ -49,7 +44,9 @@ public partial class Robot : Node3D public void SetupExecution(List nodes) { - this.nodes = [.. nodes]; + if (nodes.Count <= 0) return; + + this.nodes = new List(nodes); isExecuting = true; currentNode = nodes[0]; } diff --git a/Scripts/Robot/Robot.cs.uid b/Scripts/Gameplay/Robots/Robot.cs.uid similarity index 100% rename from Scripts/Robot/Robot.cs.uid rename to Scripts/Gameplay/Robots/Robot.cs.uid diff --git a/Scripts/Helpers/MultimeshHandler.cs b/Scripts/Helpers/MultimeshHandler.cs deleted file mode 100644 index 3cb40e9..0000000 --- a/Scripts/Helpers/MultimeshHandler.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Godot; -using System.Collections.Generic; - -public class MultiMeshHandler -{ - private Dictionary multiMeshes; - - public MultiMeshHandler(Dictionary multiMeshes) - { - this.multiMeshes = multiMeshes; - } - - public void Build(List tiles) - { - foreach (var mm in multiMeshes.Values) - mm.Multimesh.InstanceCount = 0; - - var batches = new Dictionary>(); - - foreach (var tile in tiles) - { - if (!batches.ContainsKey(tile.MeshKey)) - batches[tile.MeshKey] = new List(); - - batches[tile.MeshKey].Add(tile.Transform); - } - - foreach (var kvp in batches) - { - var mm = multiMeshes[kvp.Key].Multimesh; - var list = kvp.Value; - - mm.InstanceCount = list.Count; - - for (int i = 0; i < list.Count; i++) - mm.SetInstanceTransform(i, list[i]); - } - } -} \ No newline at end of file diff --git a/Scripts/Helpers/ResourceLoader.cs b/Scripts/Helpers/ResourceLoader.cs deleted file mode 100644 index 39965d5..0000000 --- a/Scripts/Helpers/ResourceLoader.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Godot; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json; -public partial class ResourceLoader -{ - - public static PackedScene LoadLayerPrefab() - { - return GD.Load($"res://Prefabs/Layer.tscn"); - } - - public static PackedScene LoadRobotPrefab() - { - return GD.Load($"res://Prefabs/Robot/Robot.tscn"); - } - - public static PackedScene LoadRobotDisplay() - { - return GD.Load($"res://Prefabs/Robot/RobotDisplay.tscn"); - } - - public static PackedScene LoadItemDisplay() - { - return GD.Load($"res://Prefabs/Crafting/ItemDisplay.tscn"); - } - - public static Texture2D LoadPath(string path) - { - return GD.Load(path); - } - - public static Dictionary LoadTiles() - { - Dictionary tileMeshes = new Dictionary(); - PackedScene tileCollection = GD.Load($"res://Assets/Objects/Tiles.glb"); - Node root = tileCollection.Instantiate(); - foreach (MeshInstance3D child in root.GetChildren()) - { - tileMeshes.Add(child.Name.ToString().ToLower(), child); - } - - return tileMeshes; - } - - public static Dictionary LoadDecorations() - { - Dictionary decorationMeshes = new Dictionary(); - PackedScene decorationCollection = GD.Load($"res://Assets/Objects/Decorations.glb"); - Node root = decorationCollection.Instantiate(); - foreach (MeshInstance3D child in root.GetChildren()) - { - decorationMeshes.Add(child.Name.ToString().ToLower(), child); - } - - return decorationMeshes; - } - - public static Dictionary LoadDSLNodes() - { - Dictionary nodes = new() - { - { new MoveNode(), GD.Load($"res://Prefabs/DSL/MoveNode.tscn") }, - { new HarvestNode(), GD.Load($"res://Prefabs/DSL/HarvestNode.tscn") }, - { new CraftNode(), GD.Load($"res://Prefabs/DSL/CraftNode.tscn") }, - { new ExploreNode(), GD.Load($"res://Prefabs/DSL/ExploreNode.tscn") } - }; - return nodes; - } - - public static Dictionary LoadResourceSymbols() - { - Dictionary symbols = new() - { - { "iron_ore", GD.Load($"res://Assets/Images/Resources/IronSymbol.png") }, - { "tin_ore", GD.Load($"res://Assets/Images/Resources/TinSymbol.png") }, - { "copper_ore", GD.Load($"res://Assets/Images/Resources/CopperSymbol.png") }, - { "mushroom", GD.Load($"res://Assets/Images/Resources/MushroomSymbol.png") }, - { "spider_silk", GD.Load($"res://Assets/Images/Resources/SpiderSilkSymbol.png") }, - { "coal", GD.Load($"res://Assets/Images/Resources/CoalSymbol.png") }, - { "water", GD.Load($"res://Assets/Images/Resources/WaterSymbol.png") }, - { "stone", GD.Load($"res://Assets/Images/Resources/StoneSymbol.png") }, - }; - return symbols; - } - - public static SortedDictionary LoadItems() - { - - FileAccess file = FileAccess.Open("res://Assets/Recipes.json", FileAccess.ModeFlags.Read); - string json = file.GetAsText(); - - SortedDictionary result = new(); - - List items = JsonSerializer.Deserialize>(json); - foreach (ItemData item in items) - { - result.Add(item.Id, item); - } - - return result; - } - - public static Dictionary LoadResearch() - { - - FileAccess file = FileAccess.Open("res://Assets/Research.json", FileAccess.ModeFlags.Read); - string json = file.GetAsText(); - - Dictionary result = new(); - - List researches = JsonSerializer.Deserialize>(json); - foreach (ResearchData research in researches) - { - result.Add(research.Id, new Research(research)); - } - - return result; - } -} diff --git a/Scripts/Menus/MainMenu.cs b/Scripts/Menus/MainMenu.cs deleted file mode 100644 index 599ed5f..0000000 --- a/Scripts/Menus/MainMenu.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Godot; -using System; - -public partial class MainMenu : Control -{ - // Called when the node enters the scene tree for the first time. - public override void _Ready() - { - } - - // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(double delta) - { - } - - public void OnPlayPressed() - { - GetTree().ChangeSceneToFile("res://Scenes/Game.tscn"); - } - - public void OnQuitPressed() - { - GetTree().Quit(); - } -} diff --git a/Scripts/Research/ResearchDisplay.cs b/Scripts/Research/ResearchDisplay.cs deleted file mode 100644 index e69de29..0000000 diff --git a/Scripts/Research/ResearchDisplay.cs.uid b/Scripts/Research/ResearchDisplay.cs.uid deleted file mode 100644 index 6c1076f..0000000 --- a/Scripts/Research/ResearchDisplay.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://pxegmc5nenad diff --git a/Scripts/Camera3d.cs b/Scripts/UI/Common/Camera3d.cs similarity index 86% rename from Scripts/Camera3d.cs rename to Scripts/UI/Common/Camera3d.cs index c1c8135..0d4f20e 100644 --- a/Scripts/Camera3d.cs +++ b/Scripts/UI/Common/Camera3d.cs @@ -1,4 +1,3 @@ -using System; using Godot; using static GameData; @@ -8,13 +7,9 @@ public partial class Camera3d : Camera3D [Export] public float MouseSensitivity = 0.2f; [Export] public float ScrollStrength = 5.0f; - private bool isShowingMap = false; - - private Vector2 _mouseDelta; - public override void _Ready() { - Position = new Vector3(0, 0, tileWidth/2); + Position = new Vector3(0, 0, tileWidth / 2); } public override void _Process(double delta) @@ -26,12 +21,10 @@ public partial class Camera3d : Camera3D { float d = (float)delta; - var rotation = RotationDegrees; + Vector3 rotation = RotationDegrees; rotation.X = Mathf.Clamp(rotation.X, -90f, 90f); RotationDegrees = rotation; - _mouseDelta = Vector2.Zero; - Vector3 direction = Vector3.Zero; if (Input.IsActionPressed("move_forward") && Position.Z > 0) direction += Transform.Basis.Z; if (Input.IsActionPressed("move_backward") && Position.Z < layerSize * 6) direction -= Transform.Basis.Z; diff --git a/Scripts/Camera3d.cs.uid b/Scripts/UI/Common/Camera3d.cs.uid similarity index 100% rename from Scripts/Camera3d.cs.uid rename to Scripts/UI/Common/Camera3d.cs.uid diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/UI/Common/UIHandler.cs similarity index 74% rename from Scripts/Helpers/UIHandler.cs rename to Scripts/UI/Common/UIHandler.cs index dc47c54..ccc2fd2 100644 --- a/Scripts/Helpers/UIHandler.cs +++ b/Scripts/UI/Common/UIHandler.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Threading.Tasks; using Godot; public partial class UIHandler : Control @@ -19,27 +17,22 @@ public partial class UIHandler : Control [Export] ResearchList researchList; [Export] TextureRect robotAlarm; - bool receivedRobotJumpSignal = false; + private bool receivedRobotJumpSignal = false; public override void _Ready() { - + robotList.OnRobotJumpTo += OnRobotJumpTo; + } + + public override void _ExitTree() + { + robotList.OnRobotJumpTo -= OnRobotJumpTo; } - // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { DisplayStats(); DisplayRobotAlarm(); - robotList.OnRobotJumpTo += (robot) => - { - if(receivedRobotJumpSignal) return; - receivedRobotJumpSignal = true; - mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f); - codingWindow.SetRobot(robot); - OpenUIElement(codingWindow); - }; - //Enable user to write in input fields Control focused = GetViewport().GuiGetFocusOwner(); if (focused is LineEdit || focused is TextEdit) @@ -50,7 +43,6 @@ public partial class UIHandler : Control if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton(); if (Input.IsActionJustPressed("inventory")) HandleInventoryButton(); if (Input.IsActionJustPressed("research")) HandleResearchButton(); - } public void HandleMenuButton() @@ -58,10 +50,20 @@ public partial class UIHandler : Control OpenUIElement(menu); } + public void HandleMenu() + { + HandleMenuButton(); + } + + public void ShowOptions() + { + OpenUIElement(options); + } + public void HandleMapButton() { OpenUIElement(map); - if(map.Visible) map.ShowMap(); + if (map.Visible) map.ShowMap(); } public void HandleRobotListButton() @@ -78,7 +80,7 @@ public partial class UIHandler : Control public void HandleResearchButton() { OpenUIElement(researchList); - if(researchList.Visible) researchList.SetupGraph(); + if (researchList.Visible) researchList.SetupGraph(); } public void DisplayStats() @@ -121,15 +123,22 @@ public partial class UIHandler : Control string messages = ""; foreach (Robot robot in GameData.robots) { - if(robot.currentMessage.Length > 0) + if (robot.currentMessage.Length > 0) { - messages += $"{robot.Name}: {robot.currentMessage}"; + messages += $"{robot.Name}: {robot.currentMessage}\r"; } } robotAlarm.Visible = messages.Length > 0; - if (messages.Length >= 0) - { - robotAlarm.TooltipText = messages; - } + robotAlarm.TooltipText = messages; + } + + private void OnRobotJumpTo(Robot robot) + { + if (receivedRobotJumpSignal) return; + + receivedRobotJumpSignal = true; + mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f); + codingWindow.SetRobot(robot); + OpenUIElement(codingWindow); } } diff --git a/Scripts/Helpers/UIHandler.cs.uid b/Scripts/UI/Common/UIHandler.cs.uid similarity index 100% rename from Scripts/Helpers/UIHandler.cs.uid rename to Scripts/UI/Common/UIHandler.cs.uid diff --git a/Scripts/DSL/CodingWindow.cs b/Scripts/UI/DSL/CodingWindow.cs similarity index 73% rename from Scripts/DSL/CodingWindow.cs rename to Scripts/UI/DSL/CodingWindow.cs index 00e1598..6a733e0 100644 --- a/Scripts/DSL/CodingWindow.cs +++ b/Scripts/UI/DSL/CodingWindow.cs @@ -1,34 +1,24 @@ using Godot; -using System; using System.Collections.Generic; public partial class CodingWindow : PanelContainer { - //General - Robot robot; - //Scripting + private Robot robot; + [Export] VBoxContainer codeBlocks; [Export] VBoxContainer editorWindow; - public Dictionary DSLNodes; [Export] OptionButton availableScripts; [Export] LineEdit scriptName; - - //Renaming [Export] LineEdit nameInput; - // Called when the node enters the scene tree for the first time. + public Dictionary DSLNodes; + public override void _Ready() { DSLNodes = ResourceLoader.LoadDSLNodes(); GenerateCodingBlocks(); } - // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(double delta) - { - - } - public override void _Notification(int id) { if (id == NotificationVisibilityChanged) @@ -39,6 +29,8 @@ public partial class CodingWindow : PanelContainer private void LoadWindow() { + if (robot == null) return; + nameInput.Text = robot.Name; SetupScriptOptions(); ClearWindow(); @@ -58,6 +50,8 @@ public partial class CodingWindow : PanelContainer public void SaveRobotName() { + if (robot == null) return; + robot.Name = nameInput.Text; } @@ -69,26 +63,32 @@ public partial class CodingWindow : PanelContainer public void GenerateCodingBlocks() { NodeDisplay nodeDisplay; - foreach (ProgramNode node in DSLNodes.Keys) + foreach (ProgramNode nodeTemplate in DSLNodes.Keys) { - nodeDisplay = DSLNodes[node].Instantiate(); - nodeDisplay.node = node; + nodeDisplay = DSLNodes[nodeTemplate].Instantiate(); + nodeDisplay.node = nodeTemplate; codeBlocks.AddChild(nodeDisplay); nodeDisplay.ShowListDisplay(); nodeDisplay.listDisplay.Pressed += () => { - NodeDisplay editorDisplay = DSLNodes[node].Instantiate(); - editorDisplay.node = node; - editorWindow.AddChild(editorDisplay); - editorDisplay.ShowEditorDisplay(); - editorDisplay.OnDeleteNode += () => - { - editorWindow.RemoveChild(editorDisplay); - }; + AddEditorNode(DSLNodes[nodeTemplate], nodeTemplate.Duplicate()); }; } } + private void AddEditorNode(PackedScene prefab, ProgramNode node) + { + NodeDisplay editorDisplay = prefab.Instantiate(); + editorDisplay.node = node; + editorWindow.AddChild(editorDisplay); + editorDisplay.ShowEditorDisplay(); + editorDisplay.OnDeleteNode += () => + { + editorWindow.RemoveChild(editorDisplay); + editorDisplay.QueueFree(); + }; + } + public void ClearWindow() { foreach (Node node in editorWindow.GetChildren()) @@ -105,14 +105,16 @@ public partial class CodingWindow : PanelContainer for (int i = 0; i < editorWindow.GetChildCount(); i++) { - editorWindow.GetChild(i).node.ReadParameters(editorWindow.GetChild(i)); - nodes.Add(editorWindow.GetChild(i).node.Duplicate()); + NodeDisplay nodeDisplay = editorWindow.GetChild(i); + nodeDisplay.node.ReadParameters(nodeDisplay); + nodes.Add(nodeDisplay.node.Duplicate()); if (i != 0) { nodes[i - 1].nextNode = nodes[i]; } } + if (robot == null) return; if (nodes.Count > 0) robot.SetupExecution(nodes); robot.currentProgram = scriptName.Text.Length <= 0 ? $"Script{availableScripts.ItemCount}" : scriptName.Text; } @@ -137,6 +139,7 @@ public partial class CodingWindow : PanelContainer nodeDisplay.OnDeleteNode += () => { editorWindow.RemoveChild(nodeDisplay); + nodeDisplay.QueueFree(); }; } } @@ -149,8 +152,9 @@ public partial class CodingWindow : PanelContainer string result = ""; for (int i = 0; i < editorWindow.GetChildCount(); i++) { - editorWindow.GetChild(i).node.ReadParameters(editorWindow.GetChild(i)); - result += editorWindow.GetChild(i).node.Save(); + NodeDisplay nodeDisplay = editorWindow.GetChild(i); + nodeDisplay.node.ReadParameters(nodeDisplay); + result += nodeDisplay.node.Save(); result += ";\r\n"; } if (result.Length <= 0) return; diff --git a/Scripts/DSL/CodingWindow.cs.uid b/Scripts/UI/DSL/CodingWindow.cs.uid similarity index 100% rename from Scripts/DSL/CodingWindow.cs.uid rename to Scripts/UI/DSL/CodingWindow.cs.uid diff --git a/Scripts/DSL/NodeDisplay.cs b/Scripts/UI/DSL/NodeDisplay.cs similarity index 70% rename from Scripts/DSL/NodeDisplay.cs rename to Scripts/UI/DSL/NodeDisplay.cs index 3765893..b57c3cb 100644 --- a/Scripts/DSL/NodeDisplay.cs +++ b/Scripts/UI/DSL/NodeDisplay.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using Godot; @@ -18,14 +17,11 @@ public partial class NodeDisplay : PanelContainer public override void _Ready() { + if (node == null) return; + node.Setup(this); } - public override void _Process(double delta) - { - - } - public void ShowListDisplay() { editorDisplay.Visible = false; @@ -45,54 +41,56 @@ public partial class NodeDisplay : PanelContainer public static NodeDisplay Load(string content, Dictionary 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(); + string nodeSanitized = content.Replace("\r\n", "").Trim(); + if (nodeSanitized.Length <= 0) return null; + + string nodeName = nodeSanitized.Split(",")[0].Replace("Name: ", "").ToLower(); + PackedScene prefab = GetPrefab(nodeName, DSLNodes); + if (prefab == null) return null; + + NodeDisplay result = prefab.Instantiate(); + + switch (nodeName) + { + case "move": + result.node = new MoveNode(); + result.LoadMove(nodeSanitized); + break; + case "harvest": + result.node = new HarvestNode(); + result.LoadHarvest(nodeSanitized); + break; + case "explore": + result.node = new ExploreNode(); + result.LoadExplore(nodeSanitized); + break; + case "craft": + result.node = new CraftNode(); + result.LoadCraft(nodeSanitized); + break; + default: + result.QueueFree(); + return null; + } + + return result; + } + + private static PackedScene GetPrefab(string nodeName, Dictionary DSLNodes) + { foreach (ProgramNode programNode in DSLNodes.Keys) { if (programNode.DisplayText.ToLower() == nodeName) { - prefab = DSLNodes[programNode]; - break; + return DSLNodes[programNode]; } } - switch (nodeName) - { - case "move": - program = new MoveNode(); - result = prefab.Instantiate(); - result.node = program; - result.LoadMove(nodeSanitized); - break; - case "harvest": - program = new HarvestNode(); - result = prefab.Instantiate(); - result.node = program; - result.LoadHarvest(nodeSanitized); - break; - case "explore": - program = new ExploreNode(); - result = prefab.Instantiate(); - result.node = program; - result.LoadExplore(nodeSanitized); - break; - case "craft": - program = new CraftNode(); - result = prefab.Instantiate(); - result.node = program; - result.LoadCraft(nodeSanitized); - break; - } - return result; + + return null; } public void LoadHarvest(string content) { - //Currently does nothing } public void LoadMove(string content) @@ -107,12 +105,15 @@ public partial class NodeDisplay : PanelContainer valueContainer.GetNode("./CoordinateY").Value = posY; valueContainer.GetNode("./CoordinateZ").Value = posZ; - (node as MoveNode).targetPosition = new Vector3I(posX, posY, posZ); + MoveNode moveNode = node as MoveNode; + if (moveNode != null) + { + moveNode.targetPosition = new Vector3I(posX, posY, posZ); + } } public void LoadExplore(string content) { - //Currently does nothing } public void LoadCraft(string content) @@ -122,7 +123,11 @@ public partial class NodeDisplay : PanelContainer string itemString = parts[1].Replace("Item: ", "").Replace(" ", ""); if (itemString.ToLower() != "empty") { - (node as CraftNode).selectedItem = new Item { data = GameData.availableItems[itemString] }; + CraftNode craftNode = node as CraftNode; + if (craftNode != null) + { + craftNode.selectedItem = new Item { data = GameData.availableItems[itemString] }; + } } string amountString = parts[2].Replace("Amount: ", ""); valueContainer.GetNode("./Amount").Value = int.Parse(amountString); diff --git a/Scripts/DSL/NodeDisplay.cs.uid b/Scripts/UI/DSL/NodeDisplay.cs.uid similarity index 100% rename from Scripts/DSL/NodeDisplay.cs.uid rename to Scripts/UI/DSL/NodeDisplay.cs.uid diff --git a/Scripts/Crafting/InventoryDisplay.cs b/Scripts/UI/Inventory/InventoryDisplay.cs similarity index 82% rename from Scripts/Crafting/InventoryDisplay.cs rename to Scripts/UI/Inventory/InventoryDisplay.cs index 0d81031..1b2b1a7 100644 --- a/Scripts/Crafting/InventoryDisplay.cs +++ b/Scripts/UI/Inventory/InventoryDisplay.cs @@ -3,7 +3,7 @@ using Godot; public partial class InventoryDisplay : PanelContainer { - PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay(); + private PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay(); [Export] VBoxContainer itemList; [Export] RichTextLabel inventorySpace; @@ -12,12 +12,19 @@ public partial class InventoryDisplay : PanelContainer GameData.inventory.OnInventoryUpdate += OnInventoryUpdate; } + public override void _ExitTree() + { + GameData.inventory.OnInventoryUpdate -= OnInventoryUpdate; + } + public override void _Notification(int id) { if (id == NotificationVisibilityChanged) { - if (Visible) ReloadItems(); - if (Visible) UpdateInventorySpace(); + if (!Visible) return; + + ReloadItems(); + UpdateInventorySpace(); } } @@ -33,6 +40,7 @@ public partial class InventoryDisplay : PanelContainer itemList.RemoveChild(node); node.QueueFree(); } + ItemDisplay display; foreach (Item item in GameData.inventory.items) diff --git a/Scripts/Crafting/InventoryDisplay.cs.uid b/Scripts/UI/Inventory/InventoryDisplay.cs.uid similarity index 100% rename from Scripts/Crafting/InventoryDisplay.cs.uid rename to Scripts/UI/Inventory/InventoryDisplay.cs.uid diff --git a/Scripts/UI/Inventory/ItemDisplay.cs b/Scripts/UI/Inventory/ItemDisplay.cs new file mode 100644 index 0000000..5220079 --- /dev/null +++ b/Scripts/UI/Inventory/ItemDisplay.cs @@ -0,0 +1,9 @@ +using Godot; + +public partial class ItemDisplay : PanelContainer +{ + [Export] public TextureRect texture; + [Export] public RichTextLabel text; + [Export] public RichTextLabel amount; + public Item item; +} diff --git a/Scripts/Crafting/ItemDisplay.cs.uid b/Scripts/UI/Inventory/ItemDisplay.cs.uid similarity index 100% rename from Scripts/Crafting/ItemDisplay.cs.uid rename to Scripts/UI/Inventory/ItemDisplay.cs.uid diff --git a/Scripts/UI/Menus/MainMenu.cs b/Scripts/UI/Menus/MainMenu.cs new file mode 100644 index 0000000..3ea3b20 --- /dev/null +++ b/Scripts/UI/Menus/MainMenu.cs @@ -0,0 +1,14 @@ +using Godot; + +public partial class MainMenu : Control +{ + public void OnPlayPressed() + { + GetTree().ChangeSceneToFile("res://Scenes/Game.tscn"); + } + + public void OnQuitPressed() + { + GetTree().Quit(); + } +} diff --git a/Scripts/Menus/MainMenu.cs.uid b/Scripts/UI/Menus/MainMenu.cs.uid similarity index 100% rename from Scripts/Menus/MainMenu.cs.uid rename to Scripts/UI/Menus/MainMenu.cs.uid diff --git a/Scripts/Research/ResearchList.cs b/Scripts/UI/Research/ResearchList.cs similarity index 69% rename from Scripts/Research/ResearchList.cs rename to Scripts/UI/Research/ResearchList.cs index ecd1c39..5d596b9 100644 --- a/Scripts/Research/ResearchList.cs +++ b/Scripts/UI/Research/ResearchList.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Godot; using Godot.Collections; @@ -7,17 +5,14 @@ public partial class ResearchList : PanelContainer { [Export] private GraphEdit researchGraph; - private List reloadKeys = new List(); - public override void _Ready() { RecalculateResearchStates(); - if(Visible) SetupGraph(); + if (Visible) SetupGraph(); } public void SetupGraph() { - reloadKeys = new List(); ClearGraph(); CreateResearchNodes(); CreateResearchConnections(); @@ -67,11 +62,9 @@ public partial class ResearchList : PanelContainer string prerequisite = research.data.Research; string current = research.data.Id; - if (string.IsNullOrEmpty(prerequisite)) - continue; + if (string.IsNullOrEmpty(prerequisite)) continue; - if (!researchGraph.HasNode(prerequisite) || !researchGraph.HasNode(current)) - continue; + if (!researchGraph.HasNode(prerequisite) || !researchGraph.HasNode(current)) continue; researchGraph.ConnectNode( prerequisite, @@ -135,46 +128,44 @@ public partial class ResearchList : PanelContainer private void RecalculateResearchStates() { - bool changedState; - foreach (string key in GameData.availableResearch.Keys) + bool changedState = true; + + while (changedState) { changedState = false; - if (reloadKeys.Contains(key)) continue; - reloadKeys.Add(key); - //Already researched - if (GameData.availableResearch[key].state == ResearchState.RESEARCHED) + foreach (Research research in GameData.availableResearch.Values) { + ResearchState newState = GetUpdatedResearchState(research); + + if (research.state == newState) continue; + + research.state = newState; changedState = true; } - - //No previous research needed - if (GameData.availableResearch[key].data.Research.Length <= 0) - { - GameData.availableResearch[key].state = ResearchState.RESEARCHED; - changedState = true; - } - - //Previous research is unlocked - if (!changedState && GameData.availableResearch[GameData.availableResearch[key].data.Research].state == ResearchState.RESEARCHED) - { - GameData.availableResearch[key].state = ResearchState.AVAILABLE; - changedState = true; - } - - if (!changedState) - { - //All others are locked - GameData.availableResearch[key].state = ResearchState.LOCKED; - } - - if (reloadKeys.Count != GameData.availableResearch.Keys.Count) - { - RecalculateResearchStates(); - } } } + private ResearchState GetUpdatedResearchState(Research research) + { + if (research.state == ResearchState.RESEARCHED) + { + return ResearchState.RESEARCHED; + } + + if (research.data.Research.Length <= 0) + { + return ResearchState.RESEARCHED; + } + + if (GameData.availableResearch[research.data.Research].state == ResearchState.RESEARCHED) + { + return ResearchState.AVAILABLE; + } + + return ResearchState.LOCKED; + } + private Color GetColorByState(ResearchState state) { return state switch diff --git a/Scripts/Research/ResearchList.cs.uid b/Scripts/UI/Research/ResearchList.cs.uid similarity index 100% rename from Scripts/Research/ResearchList.cs.uid rename to Scripts/UI/Research/ResearchList.cs.uid diff --git a/Scripts/Robot/RobotDisplay.cs b/Scripts/UI/Robots/RobotDisplay.cs similarity index 69% rename from Scripts/Robot/RobotDisplay.cs rename to Scripts/UI/Robots/RobotDisplay.cs index db25257..66a6031 100644 --- a/Scripts/Robot/RobotDisplay.cs +++ b/Scripts/UI/Robots/RobotDisplay.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Godot; public partial class RobotDisplay : PanelContainer @@ -8,16 +7,13 @@ public partial class RobotDisplay : PanelContainer [Signal] public delegate void OnRobotJumpToEventHandler(Robot robot); public Robot robot; - public override void _Ready() - { - - } public override void _Process(double delta) { - if (robot.currentProgram != currentScript.Text) + string programName = robot.currentProgram ?? ""; + if (programName != currentScript.Text) { - currentScript.Text = robot.currentProgram; + currentScript.Text = programName; } } diff --git a/Scripts/Robot/RobotDisplay.cs.uid b/Scripts/UI/Robots/RobotDisplay.cs.uid similarity index 100% rename from Scripts/Robot/RobotDisplay.cs.uid rename to Scripts/UI/Robots/RobotDisplay.cs.uid diff --git a/Scripts/Robot/RobotList.cs b/Scripts/UI/Robots/RobotList.cs similarity index 78% rename from Scripts/Robot/RobotList.cs rename to Scripts/UI/Robots/RobotList.cs index 3bfce06..6109717 100644 --- a/Scripts/Robot/RobotList.cs +++ b/Scripts/UI/Robots/RobotList.cs @@ -1,24 +1,17 @@ using Godot; -using System; public partial class RobotList : PanelContainer { [Export] VBoxContainer robotList; [Signal] public delegate void OnRobotJumpToEventHandler(Robot robot); - public PackedScene robotDisplayPrefab; - // Called when the node enters the scene tree for the first time. + private PackedScene robotDisplayPrefab; + public override void _Ready() { robotDisplayPrefab = ResourceLoader.LoadRobotDisplay(); } - // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(double delta) - { - - } - public override void _Notification(int id) { if (id == NotificationVisibilityChanged) diff --git a/Scripts/Robot/RobotList.cs.uid b/Scripts/UI/Robots/RobotList.cs.uid similarity index 100% rename from Scripts/Robot/RobotList.cs.uid rename to Scripts/UI/Robots/RobotList.cs.uid diff --git a/Scripts/WorldGeneration/Layer.cs b/Scripts/World/Layer.cs similarity index 81% rename from Scripts/WorldGeneration/Layer.cs rename to Scripts/World/Layer.cs index 2a70bb9..ca74d93 100644 --- a/Scripts/WorldGeneration/Layer.cs +++ b/Scripts/World/Layer.cs @@ -1,25 +1,25 @@ using Godot; -using System; using System.Collections.Generic; -using System.Linq; using static WFC; + public partial class Layer : Node3D { + private const int MaxGenerationAttempts = 1000; + private static readonly Vector2I NoPosition = new Vector2I(-100, -100); + private Node3D decorationRoot; public Tile[,] tiles; - int layerSize; - Tile tile; - int level; - bool updateFailed = false; + private int layerSize; + private int level; + private bool updateFailed = false; public bool hasContentGenerated = false; public Vector2I gateCoordinate; public List currentResources; public bool isGateOpen = false; - // Called when the node enters the scene tree for the first time. public override void _Ready() { - currentResources = new(); + currentResources = new List(); decorationRoot = new Node3D { Name = "Decorations" @@ -27,15 +27,9 @@ public partial class Layer : Node3D AddChild(decorationRoot); } - // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(double delta) - { - - } - public void ClearDecorations() { - foreach (var tile in tiles) + foreach (Tile tile in tiles) { foreach (Node child in tile.ContentNode.GetChildren()) { @@ -49,14 +43,16 @@ public partial class Layer : Node3D this.layerSize = layerSize; this.level = level; tiles = new Tile[layerSize, layerSize]; + GenerateBaseStructure(tileMeshes); + int safetyCounter = 0; while (true) { if (GenerateLayer(collapseOrigin)) break; ResetLayer(tileMeshes); safetyCounter++; - if (safetyCounter > 1000) break; + if (safetyCounter > MaxGenerationAttempts) break; } CreateTileNodes(); } @@ -74,7 +70,7 @@ public partial class Layer : Node3D { offsetZ = y * GameData.tileWidth; position = new Vector3(offsetX, offsetY, offsetZ); - tile = new Tile(); + Tile tile = new Tile(); tile.SetMeshes(tileMeshes); tile.Position = position; tile.GridPosition = new Vector2I(x, y); @@ -85,9 +81,9 @@ public partial class Layer : Node3D private void CreateTileNodes() { - foreach (var tile in tiles) + foreach (Tile tile in tiles) { - var node = new Node3D + Node3D node = new Node3D { Position = tile.Position, Visible = tile.collapsedMesh != null && tile.collapsedMesh == "gate" @@ -100,6 +96,8 @@ public partial class Layer : Node3D private void ResetLayer(Dictionary tileMeshes) { + updateFailed = false; + for (int x = 0; x < layerSize; x++) { for (int y = 0; y < layerSize; y++) @@ -115,13 +113,12 @@ public partial class Layer : Node3D { for (int z = 0; z < layerSize; z++) { - //Exclude spawn from border generation - if(x == 0 && z == 0 && level == 0) continue; + if (x == 0 && z == 0 && level == 0) continue; if (!IsBorder(x, z)) continue; - var tile = tiles[x, z]; - var possibilities = GetBorderPossibilities(x, z); + Tile tile = tiles[x, z]; + List possibilities = GetBorderPossibilities(x, z); if (possibilities.Count == 0) continue; @@ -142,10 +139,10 @@ public partial class Layer : Node3D //Generate spawn only in the first layer if (level == 0) { - tiles[0,0].Collapse("spawn"); + tiles[0, 0].Collapse("spawn"); Propagate(new Vector2I()); } - //Randomly position the gate to the next layer + int posX, posY; while (true) { @@ -162,13 +159,10 @@ public partial class Layer : Node3D break; } } - - } public bool GenerateLayer(Vector2I collapseOrigin) { - bool result = true; int safetyCounter = 0; GenerateBorder(); @@ -183,7 +177,7 @@ public partial class Layer : Node3D Propagate(position); if (updateFailed) break; position = GetSmallestPossibilities(); - if (position == new Vector2(-100, -100)) + if (position == NoPosition) { break; } @@ -193,10 +187,8 @@ public partial class Layer : Node3D if (safetyCounter == layerSize * layerSize) return false; } if (updateFailed) return false; - //Player has over 80% of tiles available without destroying walls => Results in about 95% success rate - //Not necessarily needed but improves the overall generation percentage at a low resource cost if (!WFC.IsMapConnected(tiles, 0.8f)) return false; - return result; + return true; } private void Propagate(Vector2I startPos) @@ -209,8 +201,7 @@ public partial class Layer : Node3D Vector2I currentPos = queue.Dequeue(); Tile currentTile = tiles[currentPos.X, currentPos.Y]; - // Use CURRENT state of tile - var currentPossibilities = currentTile.collapsedMesh != null + HashSet currentPossibilities = currentTile.collapsedMesh != null ? new HashSet { currentTile.collapsedMesh } : new HashSet(currentTile.tileMeshes.Keys); @@ -243,7 +234,6 @@ public partial class Layer : Node3D return; } - // ONLY enqueue if something changed if (updateCount > 0) { queue.Enqueue(newPos); @@ -255,7 +245,7 @@ public partial class Layer : Node3D private Vector2I GetSmallestPossibilities() { - Vector2I result = new Vector2I(-100, -100); + Vector2I result = NoPosition; int lowest = 100; int current; for (int x = 0; x < layerSize; x++) diff --git a/Scripts/WorldGeneration/Layer.cs.uid b/Scripts/World/Layer.cs.uid similarity index 100% rename from Scripts/WorldGeneration/Layer.cs.uid rename to Scripts/World/Layer.cs.uid diff --git a/Scripts/Helpers/LightHandler.cs b/Scripts/World/LightHandler.cs similarity index 59% rename from Scripts/Helpers/LightHandler.cs rename to Scripts/World/LightHandler.cs index 36d1b96..543e278 100644 --- a/Scripts/Helpers/LightHandler.cs +++ b/Scripts/World/LightHandler.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; public class LightHandler { - public static List lights = new (); + public static List lights = new List(); public static void RedrawLights(Color color) { - List availableLights = new(); - foreach(OmniLight3D light in lights) + List availableLights = new List(); + + foreach (OmniLight3D light in lights) { if (GodotObject.IsInstanceValid(light)) { @@ -16,6 +17,7 @@ public class LightHandler availableLights.Add(light); } } - lights = [..availableLights]; + + lights = availableLights; } -} \ No newline at end of file +} diff --git a/Scripts/Helpers/LightHandler.cs.uid b/Scripts/World/LightHandler.cs.uid similarity index 100% rename from Scripts/Helpers/LightHandler.cs.uid rename to Scripts/World/LightHandler.cs.uid diff --git a/Scripts/WorldGeneration/Map.cs b/Scripts/World/Map.cs similarity index 60% rename from Scripts/WorldGeneration/Map.cs rename to Scripts/World/Map.cs index db269ab..42cc257 100644 --- a/Scripts/WorldGeneration/Map.cs +++ b/Scripts/World/Map.cs @@ -7,79 +7,32 @@ public partial class Map : PanelContainer [Export] GridContainer grid; private HashSet handledTiles = new HashSet(); private Dictionary textureMap = new Dictionary(); - // Called when the node enters the scene tree for the first time. + public override void _Ready() { grid.Columns = GameData.layerSize + 1; } - // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(double delta) - { - } - public void ShowMap() { if (!Visible) return; - foreach (Node node in grid.GetChildren()) - { - grid.RemoveChild(node); - node.QueueFree(); - } - TextureRect texture; - Label label; + + ClearGrid(); + Tile[,] tiles = GameData.map[GameData.currentLayer].tiles; int size = GameData.layerSize; + for (int z = -1; z < size; z++) { for (int x = -1; x < size; x++) { if (z == -1 || x == -1) { - label = new Label - { - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - - SizeFlagsHorizontal = SizeFlags.ExpandFill, - SizeFlagsVertical = SizeFlags.ExpandFill - }; - if (z == -1 && x == -1) - { - label.Text = "\u2193 Z | \u2192 X"; - } - else if (z == -1) - { - label.Text = x.ToString(); - } - else - { - label.Text = z.ToString(); - } - grid.AddChild(label); + grid.AddChild(CreateHeaderLabel(x, z)); continue; } - texture = new TextureRect(); - if (tiles[x, z].wasVisited || GameData.DEBUGMODE) - { - if (tiles[x, z].containsResource) - { - texture.Texture = ResourceDistributor.resources[tiles[x, z].resource.name]; - texture.TooltipText = tiles[x, z].resource.item.GetReadableName() + $"\r(X: {x},Y: {GameData.currentLayer},Z: {z})"; - } - else - { - texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 0)); - texture.TooltipText = ""; - } - } - else - { - texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 1)); - texture.TooltipText = "Not explored"; - } - + TextureRect texture = CreateTileTexture(tiles[x, z]); textureMap[tiles[x, z]] = texture; if (!handledTiles.Contains(tiles[x, z])) @@ -93,11 +46,49 @@ public partial class Map : PanelContainer texture.StretchMode = TextureRect.StretchModeEnum.Scale; grid.AddChild(texture); - } } } + private void ClearGrid() + { + foreach (Node node in grid.GetChildren()) + { + grid.RemoveChild(node); + node.QueueFree(); + } + } + + private Label CreateHeaderLabel(int x, int z) + { + Label label = new Label + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + SizeFlagsHorizontal = SizeFlags.ExpandFill, + SizeFlagsVertical = SizeFlags.ExpandFill + }; + + if (z == -1 && x == -1) label.Text = "\u2193 Z | \u2192 X"; + else if (z == -1) label.Text = x.ToString(); + else label.Text = z.ToString(); + + return label; + } + + private TextureRect CreateTileTexture(Tile tile) + { + TextureRect texture = new TextureRect + { + SizeFlagsHorizontal = SizeFlags.ExpandFill, + SizeFlagsVertical = SizeFlags.ExpandFill, + StretchMode = TextureRect.StretchModeEnum.Scale + }; + + UpdateTileTexture(tile, texture); + return texture; + } + private void OnTileVisited(object sender, EventArgs e) { Tile tile = sender as Tile; @@ -115,7 +106,17 @@ public partial class Map : PanelContainer { if (!IsInstanceValid(texture)) return; - if (tile.containsResource) + UpdateTileTexture(tile, texture); + } + + private void UpdateTileTexture(Tile tile, TextureRect texture) + { + if (!tile.wasVisited && !GameData.debugMode) + { + texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 1)); + texture.TooltipText = "Not explored"; + } + else if (tile.containsResource) { texture.Texture = ResourceDistributor.resources[tile.resource.name]; texture.TooltipText = tile.resource.item.GetReadableName() + $"\r(X: {tile.GridPosition.X},Y: {GameData.currentLayer},Z: {tile.GridPosition.Y})"; @@ -129,9 +130,7 @@ public partial class Map : PanelContainer public Texture2D GenerateTexture(int size, Color fillColor) { - Image image = Image.CreateEmpty(size, size, false, Image.Format.Rgba8); - image.Fill(fillColor); return ImageTexture.CreateFromImage(image); diff --git a/Scripts/WorldGeneration/Map.cs.uid b/Scripts/World/Map.cs.uid similarity index 100% rename from Scripts/WorldGeneration/Map.cs.uid rename to Scripts/World/Map.cs.uid diff --git a/Scripts/World/MultimeshHandler.cs b/Scripts/World/MultimeshHandler.cs new file mode 100644 index 0000000..129534e --- /dev/null +++ b/Scripts/World/MultimeshHandler.cs @@ -0,0 +1,45 @@ +using Godot; +using System.Collections.Generic; + +public class MultiMeshHandler +{ + private readonly Dictionary multiMeshes; + + public MultiMeshHandler(Dictionary multiMeshes) + { + this.multiMeshes = multiMeshes; + } + + public void Build(List tiles) + { + foreach (MultiMeshInstance3D multiMeshInstance in multiMeshes.Values) + { + multiMeshInstance.Multimesh.InstanceCount = 0; + } + + Dictionary> batches = new Dictionary>(); + + foreach (TileRenderData tile in tiles) + { + if (!batches.ContainsKey(tile.MeshKey)) + { + batches[tile.MeshKey] = new List(); + } + + batches[tile.MeshKey].Add(tile.Transform); + } + + foreach (KeyValuePair> kvp in batches) + { + MultiMesh multiMesh = multiMeshes[kvp.Key].Multimesh; + List transforms = kvp.Value; + + multiMesh.InstanceCount = transforms.Count; + + for (int i = 0; i < transforms.Count; i++) + { + multiMesh.SetInstanceTransform(i, transforms[i]); + } + } + } +} diff --git a/Scripts/Helpers/MultimeshHandler.cs.uid b/Scripts/World/MultimeshHandler.cs.uid similarity index 100% rename from Scripts/Helpers/MultimeshHandler.cs.uid rename to Scripts/World/MultimeshHandler.cs.uid diff --git a/Scripts/WorldGeneration/Pathfinding.cs b/Scripts/World/Pathfinding.cs similarity index 80% rename from Scripts/WorldGeneration/Pathfinding.cs rename to Scripts/World/Pathfinding.cs index adde9ac..471807a 100644 --- a/Scripts/WorldGeneration/Pathfinding.cs +++ b/Scripts/World/Pathfinding.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; -using System.Linq; using Godot; public class Pathfinding { private static AStar3D aStar = new AStar3D(); - private static Dictionary coordToId = new(); - private static Dictionary idToCoord = new(); + private static Dictionary coordToId = new Dictionary(); + private static Dictionary idToCoord = new Dictionary(); private static long nextId = 1; - private static Dictionary verticalConnections = new(); + private static Dictionary verticalConnections = new Dictionary(); private static long GetOrCreateId(Vector3I coord) { @@ -39,8 +38,7 @@ public class Pathfinding Vector3I coord = new Vector3I(x, y, z); Tile tile = GameData.map[y].tiles[x, z]; - if (tile == null || tile.collapsedMesh == null) - continue; + if (tile == null || tile.collapsedMesh == null) continue; long id = GetOrCreateId(coord); @@ -49,24 +47,22 @@ public class Pathfinding } } - foreach (var kvp in coordToId) + foreach (KeyValuePair kvp in coordToId) { Vector3I from = kvp.Key; long fromId = kvp.Value; foreach (Vector3I offset in WFC.offsets3D) { - var to = new Vector3I( + Vector3I to = new Vector3I( from.X + offset.X, from.Y + offset.Y, from.Z + offset.Z ); - if (!coordToId.ContainsKey(to)) - continue; + if (!coordToId.ContainsKey(to)) continue; - if (!WFC.CanWalk3D(from, to)) - continue; + if (!WFC.CanWalk3D(from, to)) continue; long toId = coordToId[to]; @@ -98,36 +94,38 @@ public class Pathfinding public static void UpdateGatePoint(int layer, bool isOpen) { - if (!verticalConnections.ContainsKey(layer)) - return; + if (!verticalConnections.ContainsKey(layer)) return; - var (fromId, toId) = verticalConnections[layer]; + (long fromId, long toId) = verticalConnections[layer]; if (isOpen) { if (!aStar.ArePointsConnected(fromId, toId)) + { aStar.ConnectPoints(fromId, toId, true); + } } else { if (aStar.ArePointsConnected(fromId, toId)) + { aStar.DisconnectPoints(fromId, toId); + } } } public static List GetPath(Vector3I start, Vector3I end) { - if (!coordToId.ContainsKey(start) || !coordToId.ContainsKey(end)) - return new List(); + if (!coordToId.ContainsKey(start) || !coordToId.ContainsKey(end)) return new List(); long startId = coordToId[start]; long endId = coordToId[end]; - return aStar.GetPointPath(startId, endId).ToList(); + return new List(aStar.GetPointPath(startId, endId)); } public static Vector3I GetClosestStartPoint(Vector3 robotPosition) { return idToCoord[aStar.GetClosestPoint(robotPosition)]; } -} \ No newline at end of file +} diff --git a/Scripts/WorldGeneration/Pathfinding.cs.uid b/Scripts/World/Pathfinding.cs.uid similarity index 100% rename from Scripts/WorldGeneration/Pathfinding.cs.uid rename to Scripts/World/Pathfinding.cs.uid diff --git a/Scripts/Helpers/Placeholder.cs b/Scripts/World/Placeholder.cs similarity index 74% rename from Scripts/Helpers/Placeholder.cs rename to Scripts/World/Placeholder.cs index 203ff84..525b307 100644 --- a/Scripts/Helpers/Placeholder.cs +++ b/Scripts/World/Placeholder.cs @@ -5,8 +5,9 @@ public class Placeholder public string name; public Transform3D transform; - public Placeholder(string name, Transform3D transform){ + public Placeholder(string name, Transform3D transform) + { this.name = name.Split("_")[0].ToLower(); this.transform = transform; } -} \ No newline at end of file +} diff --git a/Scripts/Helpers/Placeholder.cs.uid b/Scripts/World/Placeholder.cs.uid similarity index 100% rename from Scripts/Helpers/Placeholder.cs.uid rename to Scripts/World/Placeholder.cs.uid diff --git a/Scripts/World/ResourceDistributor.cs b/Scripts/World/ResourceDistributor.cs new file mode 100644 index 0000000..af94223 --- /dev/null +++ b/Scripts/World/ResourceDistributor.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using Godot; + +public class ResourceDistributor +{ + public static Dictionary resources = ResourceLoader.LoadResourceSymbols(); + + public static string GetResource(List current) + { + List availableResources = GetUnusedResources(current); + if (availableResources.Count <= 0) + { + availableResources = new List(resources.Keys); + } + + return availableResources[GameData.rand.Next(availableResources.Count)]; + } + + private static List GetUnusedResources(List current) + { + List result = new List(); + + foreach (string resource in resources.Keys) + { + if (!current.Contains(resource)) + { + result.Add(resource); + } + } + + return result; + } +} diff --git a/Scripts/WorldGeneration/ResourceDistributor.cs.uid b/Scripts/World/ResourceDistributor.cs.uid similarity index 100% rename from Scripts/WorldGeneration/ResourceDistributor.cs.uid rename to Scripts/World/ResourceDistributor.cs.uid diff --git a/Scripts/WorldGeneration/Tile.cs b/Scripts/World/Tile.cs similarity index 96% rename from Scripts/WorldGeneration/Tile.cs rename to Scripts/World/Tile.cs index efa870e..89d6546 100644 --- a/Scripts/WorldGeneration/Tile.cs +++ b/Scripts/World/Tile.cs @@ -16,7 +16,6 @@ public partial class Tile public bool wasVisited; public event EventHandler OnTileVisited; - public void SetMeshes(Dictionary tileMeshes) { this.tileMeshes = new Dictionary(tileMeshes); @@ -26,6 +25,7 @@ public partial class Tile { if (collapsedMesh != null) return ""; if (tileMeshes.Keys.Count <= 0) return "ERR"; + collapsedMesh = (tile.Length > 0) ? tile : ChooseWeighted(); tileMeshes.Clear(); return collapsedMesh; @@ -74,6 +74,11 @@ public partial class Tile public void Reset(Dictionary tileMeshes) { collapsedMesh = null; + containsLight = false; + containsDecoration = false; + containsResource = false; + resource = null; + wasVisited = false; SetMeshes(tileMeshes); } @@ -127,16 +132,13 @@ public partial class Tile foreach (string key in contentMeshes.Keys) { if (key.ToLower() != placeholder.name) continue; + MeshInstance3D decoration = new MeshInstance3D { Mesh = contentMeshes[key].Mesh, Position = placeholder.transform.Origin }; ContentNode.AddChild(decoration); - if (!key.ToLower().Contains("gate")) - { - //decoration.LookAt(transform.Origin, Vector3.Up); - } } } diff --git a/Scripts/WorldGeneration/Tile.cs.uid b/Scripts/World/Tile.cs.uid similarity index 100% rename from Scripts/WorldGeneration/Tile.cs.uid rename to Scripts/World/Tile.cs.uid diff --git a/Scripts/Structs/TileRenderData.cs b/Scripts/World/TileRenderData.cs similarity index 100% rename from Scripts/Structs/TileRenderData.cs rename to Scripts/World/TileRenderData.cs diff --git a/Scripts/Structs/TileRenderData.cs.uid b/Scripts/World/TileRenderData.cs.uid similarity index 100% rename from Scripts/Structs/TileRenderData.cs.uid rename to Scripts/World/TileRenderData.cs.uid diff --git a/Scripts/WorldGeneration/WFC.cs b/Scripts/World/WFC.cs similarity index 62% rename from Scripts/WorldGeneration/WFC.cs rename to Scripts/World/WFC.cs index c19306e..a4c0f75 100644 --- a/Scripts/WorldGeneration/WFC.cs +++ b/Scripts/World/WFC.cs @@ -47,31 +47,31 @@ public class WFC public static Dictionary> tileConnections = new Dictionary> { - ["t_right"] = new() { Direction.Backward, Direction.Forward, Direction.Right, Direction.Up }, - ["t_left"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Up }, - ["t_up"] = new() { Direction.Left, Direction.Right, Direction.Backward, Direction.Up }, - ["t_down"] = new() { Direction.Left, Direction.Right, Direction.Forward, Direction.Up }, + ["t_right"] = new HashSet { Direction.Backward, Direction.Forward, Direction.Right, Direction.Up }, + ["t_left"] = new HashSet { Direction.Backward, Direction.Forward, Direction.Left, Direction.Up }, + ["t_up"] = new HashSet { Direction.Left, Direction.Right, Direction.Backward, Direction.Up }, + ["t_down"] = new HashSet { Direction.Left, Direction.Right, Direction.Forward, Direction.Up }, - ["end_up"] = new() { Direction.Backward, Direction.Up }, - ["end_down"] = new() { Direction.Forward, Direction.Up }, - ["end_left"] = new() { Direction.Left, Direction.Up }, - ["end_right"] = new() { Direction.Right, Direction.Up }, + ["end_up"] = new HashSet { Direction.Backward, Direction.Up }, + ["end_down"] = new HashSet { Direction.Forward, Direction.Up }, + ["end_left"] = new HashSet { Direction.Left, Direction.Up }, + ["end_right"] = new HashSet { Direction.Right, Direction.Up }, - ["straight_left_right"] = new() { Direction.Left, Direction.Right, Direction.Up }, - ["straight_up_down"] = new() { Direction.Backward, Direction.Forward, Direction.Up }, + ["straight_left_right"] = new HashSet { Direction.Left, Direction.Right, Direction.Up }, + ["straight_up_down"] = new HashSet { Direction.Backward, Direction.Forward, Direction.Up }, - ["corner_up_left"] = new() { Direction.Backward, Direction.Left, Direction.Up }, - ["corner_up_right"] = new() { Direction.Backward, Direction.Right, Direction.Up }, - ["corner_down_left"] = new() { Direction.Forward, Direction.Left, Direction.Up }, - ["corner_down_right"] = new() { Direction.Forward, Direction.Right, Direction.Up }, + ["corner_up_left"] = new HashSet { Direction.Backward, Direction.Left, Direction.Up }, + ["corner_up_right"] = new HashSet { Direction.Backward, Direction.Right, Direction.Up }, + ["corner_down_left"] = new HashSet { Direction.Forward, Direction.Left, Direction.Up }, + ["corner_down_right"] = new HashSet { Direction.Forward, Direction.Right, Direction.Up }, - ["junction"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up }, - ["gate"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up, Direction.Down }, + ["junction"] = new HashSet { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up }, + ["gate"] = new HashSet { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up, Direction.Down }, - ["spawn"] = new() { Direction.Forward, Direction.Left }, + ["spawn"] = new HashSet { Direction.Forward, Direction.Left }, }; - public static Dictionary weights = new() + public static Dictionary weights = new Dictionary() { ["junction"] = 3f, ["t_up"] = 3f, @@ -112,8 +112,8 @@ public class WFC public static bool CanConnect(string a, string b, Direction direction, bool checkWalking) { - var aDirs = tileConnections[a]; - var bDirs = tileConnections[b]; + HashSet aDirs = tileConnections[a]; + HashSet bDirs = tileConnections[b]; bool aOpen = aDirs.Contains(direction); bool bOpen = bDirs.Contains(Opposite(direction)); @@ -126,15 +126,15 @@ public class WFC public static void FillAdjacencies() { - foreach (var tile in tileConnections.Keys) + foreach (string tile in tileConnections.Keys) { adjacency[tile] = new Dictionary>(); foreach (Direction dir in Enum.GetValues(typeof(Direction))) { - var valid = new List(); + List valid = new List(); - foreach (var other in tileConnections.Keys) + foreach (string other in tileConnections.Keys) { if (CanConnect(tile, other, dir, false)) valid.Add(other); @@ -147,14 +147,14 @@ public class WFC public static bool IsWalkable(Tile tile) { - var dirs = tileConnections[tile.collapsedMesh]; - return dirs.Count > 0 && !dirs.Contains(Direction.None); + HashSet connections = tileConnections[tile.collapsedMesh]; + return connections.Count > 0 && !connections.Contains(Direction.None); } public static bool CanWalk(Tile[,] layer, Vector2I from, Vector2I to, Direction dir) { - var fromTile = layer[from.X, from.Y]; - var toTile = layer[to.X, to.Y]; + Tile fromTile = layer[from.X, from.Y]; + Tile toTile = layer[to.X, to.Y]; if (!IsWalkable(toTile)) return false; @@ -226,7 +226,7 @@ public class WFC if (!visited.Add(position)) continue; for (int i = 0; i < offsets2D.Length; i++) { - var next = position + offsets2D[i]; + Vector2I next = position + offsets2D[i]; if (!InBounds(next, layer.GetLength(0))) continue; @@ -263,18 +263,16 @@ public class WFC bool top = z == 0; bool bottom = z == GameData.layerSize - 1; - // Corners - if (left && top) return new() { "corner_down_right" }; - if (left && bottom) return new() { "corner_up_right" }; - if (right && top) return new() { "corner_down_left" }; - if (right && bottom) return new() { "corner_up_left" }; + if (left && top) return new List { "corner_down_right" }; + if (left && bottom) return new List { "corner_up_right" }; + if (right && top) return new List { "corner_down_left" }; + if (right && bottom) return new List { "corner_up_left" }; - // Edges - if (top) return new() { "straight_left_right", "t_down" }; - if (bottom) return new() { "straight_left_right", "t_up" }; - if (left) return new() { "straight_up_down", "t_right" }; - if (right) return new() { "straight_up_down", "t_left" }; + if (top) return new List { "straight_left_right", "t_down" }; + if (bottom) return new List { "straight_left_right", "t_up" }; + if (left) return new List { "straight_up_down", "t_right" }; + if (right) return new List { "straight_up_down", "t_left" }; - return new(); + return new List(); } } diff --git a/Scripts/WorldGeneration/WFC.cs.uid b/Scripts/World/WFC.cs.uid similarity index 100% rename from Scripts/WorldGeneration/WFC.cs.uid rename to Scripts/World/WFC.cs.uid diff --git a/Scripts/WorldGeneration/World.cs b/Scripts/World/World.cs similarity index 81% rename from Scripts/WorldGeneration/World.cs rename to Scripts/World/World.cs index 67bc3d7..01db278 100644 --- a/Scripts/WorldGeneration/World.cs +++ b/Scripts/World/World.cs @@ -1,7 +1,5 @@ using Godot; -using System; using System.Collections.Generic; -using System.Linq; using static GameData; public partial class World : Node3D @@ -9,11 +7,9 @@ public partial class World : Node3D public Dictionary tileMeshes; public Dictionary contentMeshes; public Dictionary> tilePlaceholders; - PackedScene layerPrefab = ResourceLoader.LoadLayerPrefab(); - private Dictionary multiMeshes = new(); - private Dictionary meshLibrary = new(); - Layer layerNode; - Pathfinding pathfinding; + private PackedScene layerPrefab = ResourceLoader.LoadLayerPrefab(); + private Dictionary multiMeshes = new Dictionary(); + private Dictionary meshLibrary = new Dictionary(); private MultiMeshHandler multiMeshHandler; @@ -26,9 +22,10 @@ public partial class World : Node3D tilePlaceholders = new Dictionary>(); - foreach (var kvp in tileMeshes) + foreach (KeyValuePair kvp in tileMeshes) { tilePlaceholders[kvp.Key] = new List(); + foreach (Node3D child in kvp.Value.GetChildren()) { tilePlaceholders[kvp.Key].Add(new Placeholder(child.Name, child.Transform)); @@ -56,19 +53,19 @@ public partial class World : Node3D private Dictionary CreateMultiMeshes(Dictionary meshLibrary) { - var result = new Dictionary(); + Dictionary result = new Dictionary(); - foreach (var kvp in meshLibrary) + foreach (KeyValuePair kvp in meshLibrary) { - var mm = new MultiMesh + MultiMesh multiMesh = new MultiMesh { Mesh = kvp.Value, TransformFormat = MultiMesh.TransformFormatEnum.Transform3D }; - var instance = new MultiMeshInstance3D + MultiMeshInstance3D instance = new MultiMeshInstance3D { - Multimesh = mm + Multimesh = multiMesh }; AddChild(instance); @@ -79,17 +76,16 @@ public partial class World : Node3D return result; } - // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { if (!canMove) return; + if (Input.IsActionJustPressed("layer_up") && currentLayer > 0) currentLayer--; if (Input.IsActionJustPressed("layer_down") && currentLayer < ruinSize - 1 && map[currentLayer].isGateOpen) currentLayer++; + if (currentLayer != visibleLayer) { - map[visibleLayer].ClearDecorations(); - HandleRenderData(BuildRenderData(currentLayer)); - visibleLayer = currentLayer; + ShowLayer(currentLayer); } } @@ -97,8 +93,9 @@ public partial class World : Node3D { for (int layer = 0; layer < ruinSize; layer++) { - layerNode = layerPrefab.Instantiate(); + Layer layerNode = layerPrefab.Instantiate(); AddChild(layerNode); + if (layer == 0) { layerNode.SetupLayer(layerSize, layer, tileMeshes, new Vector2I()); @@ -113,6 +110,13 @@ public partial class World : Node3D SetupSpawn(); } + private void ShowLayer(int layer) + { + map[visibleLayer].ClearDecorations(); + HandleRenderData(BuildRenderData(layer)); + visibleLayer = layer; + } + private void SetupSpawn() { map[0].tiles[0, 0].wasVisited = true; @@ -122,14 +126,9 @@ public partial class World : Node3D map[0].tiles[0, 0].ContentNode.Visible = true; } - private void HandleTileVisit(int level) - { - HandleRenderData(BuildRenderData(level)); - } - private List BuildRenderData(int layerIndex) { - var result = new List(); + List result = new List(); Layer layer = map[layerIndex]; layer.ClearDecorations(); @@ -168,9 +167,9 @@ public partial class World : Node3D { posX = rand.Next(layerSize); posY = rand.Next(layerSize); - //Skip already placed lights and skip junction and gate as they do not contain lights - if (layer.tiles[posX, posY].collapsedMesh == "junction" || layer.tiles[posX, posY].collapsedMesh == "gate") continue; + if (CannotContainLight(layer.tiles[posX, posY])) continue; if (layer.tiles[posX, posY].containsLight) continue; + layer.tiles[posX, posY].containsLight = true; currentLight++; } @@ -180,6 +179,7 @@ public partial class World : Node3D posX = rand.Next(layerSize); posY = rand.Next(layerSize); if (layer.tiles[posX, posY].containsDecoration) continue; + layer.tiles[posX, posY].containsDecoration = true; currentDecoration++; } @@ -189,6 +189,7 @@ public partial class World : Node3D posX = rand.Next(layerSize); posY = rand.Next(layerSize); if (layer.tiles[posX, posY].containsResource) continue; + layer.tiles[posX, posY].containsResource = true; layer.tiles[posX, posY].resource = new GameResource(ResourceDistributor.GetResource(layer.currentResources)); layer.currentResources.Add(layer.tiles[posX, posY].resource.name); @@ -196,6 +197,11 @@ public partial class World : Node3D } } + private bool CannotContainLight(Tile tile) + { + return tile.collapsedMesh == "junction" || tile.collapsedMesh == "gate"; + } + private void HandleRenderData(List renderData) { multiMeshHandler.Build(renderData); diff --git a/Scripts/WorldGeneration/World.cs.uid b/Scripts/World/World.cs.uid similarity index 100% rename from Scripts/WorldGeneration/World.cs.uid rename to Scripts/World/World.cs.uid diff --git a/Scripts/WorldGeneration/ResourceDistributor.cs b/Scripts/WorldGeneration/ResourceDistributor.cs deleted file mode 100644 index a90d7ef..0000000 --- a/Scripts/WorldGeneration/ResourceDistributor.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Godot; - -public class ResourceDistributor -{ - public static Dictionary resources = ResourceLoader.LoadResourceSymbols(); - - public static string GetResource(List current) - { - List diff = resources.Keys.Except(current).ToList(); - if (diff.Count <= 0) - { - return resources.Keys.ToList()[GameData.rand.Next(resources.Keys.Count)]; - } - else - { - return diff[GameData.rand.Next(diff.Count)]; - } - } -} \ No newline at end of file