Cleaned up project with better structure.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
public class FileHandler
|
||||
{
|
||||
private const string ScriptDirectory = "user://scripts";
|
||||
private const string ScriptExtension = ".dsl";
|
||||
|
||||
public static void CreateScriptDirectory()
|
||||
{
|
||||
DirAccess.MakeDirRecursiveAbsolute(ScriptDirectory);
|
||||
}
|
||||
|
||||
public static void SaveProgram(string filename, string content)
|
||||
{
|
||||
CreateScriptDirectory();
|
||||
string path = GetProgramPath(filename);
|
||||
|
||||
FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
|
||||
file.StoreString(content);
|
||||
}
|
||||
|
||||
public static List<string> LoadProgramNames()
|
||||
{
|
||||
CreateScriptDirectory();
|
||||
List<string> programs = new List<string>();
|
||||
|
||||
DirAccess dir = DirAccess.Open(ScriptDirectory);
|
||||
if (dir == null)
|
||||
{
|
||||
return programs;
|
||||
}
|
||||
|
||||
dir.ListDirBegin();
|
||||
while (true)
|
||||
{
|
||||
string fileName = dir.GetNext();
|
||||
if (fileName == "")
|
||||
break;
|
||||
|
||||
if (!dir.CurrentIsDir() && fileName.EndsWith(ScriptExtension))
|
||||
{
|
||||
programs.Add(fileName.Replace(ScriptExtension, ""));
|
||||
}
|
||||
}
|
||||
dir.ListDirEnd();
|
||||
|
||||
return programs;
|
||||
}
|
||||
|
||||
public static string LoadProgram(string name)
|
||||
{
|
||||
CreateScriptDirectory();
|
||||
string path = GetProgramPath(name);
|
||||
|
||||
if (!FileAccess.FileExists(path))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
|
||||
return file.GetAsText();
|
||||
}
|
||||
|
||||
private static string GetProgramPath(string filename)
|
||||
{
|
||||
return $"{ScriptDirectory}/{filename}{ScriptExtension}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://y6p1ybasi0c2
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
public partial class GameData
|
||||
{
|
||||
public static bool debugMode = false;
|
||||
public static Random rand = new Random(seed);
|
||||
public static Layer[] map;
|
||||
|
||||
public static int currentLayer = 0;
|
||||
public static int visibleLayer = 0;
|
||||
public static int lowestLayer = 0;
|
||||
|
||||
public static bool canMove = true;
|
||||
public static int maxRobotCount = 1000;
|
||||
public static List<Robot> robots = new List<Robot>();
|
||||
public static float robotSpeed = 20f;
|
||||
public static float tileWidth = 6;
|
||||
public static float tileHeight = 4;
|
||||
public static SortedDictionary<string, ItemData> availableItems = ResourceLoader.LoadItems();
|
||||
public static Dictionary<string, Research> availableResearch = ResourceLoader.LoadResearch();
|
||||
|
||||
public static Color primaryColor = new Color("#276ac2");
|
||||
public static Color lightColor = new Color("#7efff5");
|
||||
|
||||
public static int ruinSize = 10;
|
||||
public static int layerSize = 20;
|
||||
public static int seed = 12345;
|
||||
|
||||
public static Inventory inventory = new Inventory();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dgebbx4nkktu6
|
||||
@@ -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<PackedScene>(LayerPrefabPath);
|
||||
}
|
||||
|
||||
public static PackedScene LoadRobotPrefab()
|
||||
{
|
||||
return GD.Load<PackedScene>(RobotPrefabPath);
|
||||
}
|
||||
|
||||
public static PackedScene LoadRobotDisplay()
|
||||
{
|
||||
return GD.Load<PackedScene>(RobotDisplayPath);
|
||||
}
|
||||
|
||||
public static PackedScene LoadItemDisplay()
|
||||
{
|
||||
return GD.Load<PackedScene>(ItemDisplayPath);
|
||||
}
|
||||
|
||||
public static Texture2D LoadPath(string path)
|
||||
{
|
||||
return GD.Load<Texture2D>(path);
|
||||
}
|
||||
|
||||
public static Dictionary<string, MeshInstance3D> LoadTiles()
|
||||
{
|
||||
Dictionary<string, MeshInstance3D> tileMeshes = new Dictionary<string, MeshInstance3D>();
|
||||
PackedScene tileCollection = GD.Load<PackedScene>($"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<string, MeshInstance3D> LoadDecorations()
|
||||
{
|
||||
Dictionary<string, MeshInstance3D> decorationMeshes = new Dictionary<string, MeshInstance3D>();
|
||||
PackedScene decorationCollection = GD.Load<PackedScene>($"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<ProgramNode, PackedScene> LoadDSLNodes()
|
||||
{
|
||||
Dictionary<ProgramNode, PackedScene> nodes = new Dictionary<ProgramNode, PackedScene>()
|
||||
{
|
||||
{ new MoveNode(), GD.Load<PackedScene>("res://Prefabs/DSL/MoveNode.tscn") },
|
||||
{ new HarvestNode(), GD.Load<PackedScene>("res://Prefabs/DSL/HarvestNode.tscn") },
|
||||
{ new CraftNode(), GD.Load<PackedScene>("res://Prefabs/DSL/CraftNode.tscn") },
|
||||
{ new ExploreNode(), GD.Load<PackedScene>("res://Prefabs/DSL/ExploreNode.tscn") }
|
||||
};
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public static Dictionary<string, Texture2D> LoadResourceSymbols()
|
||||
{
|
||||
Dictionary<string, Texture2D> symbols = new Dictionary<string, Texture2D>()
|
||||
{
|
||||
{ "iron_ore", GD.Load<Texture2D>("res://Assets/Images/Resources/IronSymbol.png") },
|
||||
{ "tin_ore", GD.Load<Texture2D>("res://Assets/Images/Resources/TinSymbol.png") },
|
||||
{ "copper_ore", GD.Load<Texture2D>("res://Assets/Images/Resources/CopperSymbol.png") },
|
||||
{ "mushroom", GD.Load<Texture2D>("res://Assets/Images/Resources/MushroomSymbol.png") },
|
||||
{ "spider_silk", GD.Load<Texture2D>("res://Assets/Images/Resources/SpiderSilkSymbol.png") },
|
||||
{ "coal", GD.Load<Texture2D>("res://Assets/Images/Resources/CoalSymbol.png") },
|
||||
{ "water", GD.Load<Texture2D>("res://Assets/Images/Resources/WaterSymbol.png") },
|
||||
{ "stone", GD.Load<Texture2D>("res://Assets/Images/Resources/StoneSymbol.png") },
|
||||
};
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public static SortedDictionary<string, ItemData> LoadItems()
|
||||
{
|
||||
|
||||
FileAccess file = FileAccess.Open(RecipesPath, FileAccess.ModeFlags.Read);
|
||||
string json = file.GetAsText();
|
||||
|
||||
SortedDictionary<string, ItemData> result = new SortedDictionary<string, ItemData>();
|
||||
|
||||
List<ItemData> items = JsonSerializer.Deserialize<List<ItemData>>(json);
|
||||
if (items == null) return result;
|
||||
|
||||
foreach (ItemData item in items)
|
||||
{
|
||||
result.Add(item.Id, item);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Dictionary<string, Research> LoadResearch()
|
||||
{
|
||||
|
||||
FileAccess file = FileAccess.Open(ResearchPath, FileAccess.ModeFlags.Read);
|
||||
string json = file.GetAsText();
|
||||
|
||||
Dictionary<string, Research> result = new Dictionary<string, Research>();
|
||||
|
||||
List<ResearchData> researches = JsonSerializer.Deserialize<List<ResearchData>>(json);
|
||||
if (researches == null) return result;
|
||||
|
||||
foreach (ResearchData research in researches)
|
||||
{
|
||||
result.Add(research.Id, new Research(research));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cdhftg7wcgyis
|
||||
@@ -0,0 +1,38 @@
|
||||
using Godot;
|
||||
using GodotSteam;
|
||||
|
||||
public partial class SteamworksHandler : Node
|
||||
{
|
||||
[Export] private bool enableSteam = false;
|
||||
private bool isSteamInitialized = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (!enableSteam) return;
|
||||
|
||||
SteamInitExStatus status = Steam.SteamInitEx(false).Status;
|
||||
if (status != 0)
|
||||
{
|
||||
GD.Print("Steam not initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dqrdb3bvws6b6
|
||||
Reference in New Issue
Block a user