95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
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<PackedScene>($"res://Prefabs/Layer.tscn");
|
|
}
|
|
|
|
public static PackedScene LoadRobotPrefab()
|
|
{
|
|
return GD.Load<PackedScene>($"res://Prefabs/Robot/Robot.tscn");
|
|
}
|
|
|
|
public static PackedScene LoadRobotDisplay()
|
|
{
|
|
return GD.Load<PackedScene>($"res://Prefabs/Robot/RobotDisplay.tscn");
|
|
}
|
|
|
|
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()
|
|
{
|
|
{ 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()
|
|
{
|
|
{ "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 Dictionary<string, ItemData> LoadItems()
|
|
{
|
|
|
|
FileAccess file = FileAccess.Open("res://Assets/Recipes.json", FileAccess.ModeFlags.Read);
|
|
string json = file.GetAsText();
|
|
|
|
Dictionary<string, ItemData> result = new();
|
|
|
|
List<ItemData> items = JsonSerializer.Deserialize<List<ItemData>>(json);
|
|
foreach (ItemData item in items)
|
|
{
|
|
result.Add(item.Id, item);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|