2020-08-27 02:08:41 -04:00
|
|
|
|
using UnityEngine;
|
2020-08-29 02:15:38 -04:00
|
|
|
|
using System;
|
2020-09-12 01:34:31 -04:00
|
|
|
|
using System.Linq;
|
2020-08-27 02:08:41 -04:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-12 01:34:31 -04:00
|
|
|
|
using System.IO;
|
2020-08-27 02:08:41 -04:00
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! This class contains GameObject dictionaries for easily referencing different machines and other blocks.
|
2020-09-07 03:40:28 -04:00
|
|
|
|
public class BlockDictionary
|
2020-08-27 02:08:41 -04:00
|
|
|
|
{
|
2020-09-07 03:40:28 -04:00
|
|
|
|
private PlayerController playerController;
|
2020-08-27 05:06:16 -04:00
|
|
|
|
public Dictionary<string, GameObject> machineDictionary;
|
|
|
|
|
public Dictionary<string, GameObject> blockDictionary;
|
2021-05-16 14:12:13 -05:00
|
|
|
|
public Dictionary<string, Mesh> meshDictionary;
|
|
|
|
|
public Dictionary<string, Type> typeDictionary;
|
2020-08-27 02:08:41 -04:00
|
|
|
|
|
2020-09-07 03:40:28 -04:00
|
|
|
|
public BlockDictionary(PlayerController playerController)
|
2020-08-27 02:08:41 -04:00
|
|
|
|
{
|
2020-09-07 03:40:28 -04:00
|
|
|
|
this.playerController = playerController;
|
|
|
|
|
Init();
|
|
|
|
|
}
|
2020-08-27 05:06:16 -04:00
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Gets description for a specfic machine.
|
2020-09-13 02:45:50 -04:00
|
|
|
|
public string GetMachineDescription(string machineName)
|
|
|
|
|
{
|
|
|
|
|
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
2020-09-23 00:59:36 -04:00
|
|
|
|
Directory.CreateDirectory(modPath);
|
2020-09-13 02:45:50 -04:00
|
|
|
|
string[] modDirs = Directory.GetDirectories(modPath);
|
|
|
|
|
foreach (string path in modDirs)
|
|
|
|
|
{
|
|
|
|
|
string machinePath = path + "/Machines/";
|
2020-09-24 03:36:17 -04:00
|
|
|
|
Directory.CreateDirectory(machinePath);
|
2020-09-13 02:45:50 -04:00
|
|
|
|
DirectoryInfo d = new DirectoryInfo(machinePath);
|
|
|
|
|
foreach (FileInfo file in d.GetFiles("*.qe"))
|
|
|
|
|
{
|
|
|
|
|
string filePath = machinePath + file.Name;
|
|
|
|
|
string fileContents = File.ReadAllText(filePath);
|
|
|
|
|
string fileName = file.Name.Remove(file.Name.Length - 3);
|
|
|
|
|
if (fileName == machineName)
|
|
|
|
|
{
|
2020-09-13 19:21:06 -04:00
|
|
|
|
string modName = new DirectoryInfo(path).Name;
|
2020-09-13 02:45:50 -04:00
|
|
|
|
return fileContents.Split(']')[0].Substring(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-13 19:21:06 -04:00
|
|
|
|
Debug.Log("Failed to get description for [" + machineName + "]");
|
2020-09-13 02:45:50 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Gets recipes for a specfic machine.
|
2020-09-12 01:34:31 -04:00
|
|
|
|
public BasicMachineRecipe[] GetMachineRecipes(string machineName)
|
|
|
|
|
{
|
2021-04-05 02:59:40 -04:00
|
|
|
|
StateManager stateManager = GameObject.Find("GameManager").GetComponent<StateManager>();
|
2020-09-12 01:34:31 -04:00
|
|
|
|
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
2020-09-23 00:59:36 -04:00
|
|
|
|
Directory.CreateDirectory(modPath);
|
2020-09-12 01:34:31 -04:00
|
|
|
|
string[] modDirs = Directory.GetDirectories(modPath);
|
|
|
|
|
foreach (string path in modDirs)
|
|
|
|
|
{
|
|
|
|
|
string machinePath = path + "/Machines/";
|
2020-09-24 03:36:17 -04:00
|
|
|
|
Directory.CreateDirectory(machinePath);
|
2020-09-12 01:34:31 -04:00
|
|
|
|
DirectoryInfo d = new DirectoryInfo(machinePath);
|
|
|
|
|
foreach (FileInfo file in d.GetFiles("*.qe"))
|
|
|
|
|
{
|
|
|
|
|
string filePath = machinePath + file.Name;
|
|
|
|
|
string fileContents = File.ReadAllText(filePath);
|
2020-09-13 02:45:50 -04:00
|
|
|
|
string fileName = file.Name.Remove(file.Name.Length - 3);
|
|
|
|
|
if (fileName == machineName)
|
2020-09-12 01:34:31 -04:00
|
|
|
|
{
|
2020-09-13 02:45:50 -04:00
|
|
|
|
string recipeContents = fileContents.Split(']')[1];
|
|
|
|
|
string[] machineContents = recipeContents.Split('}');
|
|
|
|
|
BasicMachineRecipe[] machineRecipes = new BasicMachineRecipe[machineContents.Length - 1];
|
|
|
|
|
for (int i = 0; i < machineRecipes.Length; i++)
|
2020-09-12 01:34:31 -04:00
|
|
|
|
{
|
|
|
|
|
string input = machineContents[i].Split(':')[0];
|
|
|
|
|
string output = machineContents[i].Split(':')[1];
|
|
|
|
|
machineRecipes[i] = new BasicMachineRecipe(input, output);
|
|
|
|
|
}
|
2020-09-13 19:21:06 -04:00
|
|
|
|
string modName = new DirectoryInfo(path).Name;
|
2021-04-05 02:59:40 -04:00
|
|
|
|
if (!stateManager.modRecipeList.Contains(machineName))
|
|
|
|
|
{
|
|
|
|
|
stateManager.modRecipeList.Add(machineName);
|
|
|
|
|
Debug.Log("Mod "+"["+modName+"]"+" added recipes for [" + machineName + "]");
|
|
|
|
|
}
|
2020-09-12 01:34:31 -04:00
|
|
|
|
return machineRecipes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Adds machines from mods to the game.
|
2020-09-12 01:34:31 -04:00
|
|
|
|
public void AddModMachines(Dictionary<string, GameObject> dictionary)
|
|
|
|
|
{
|
|
|
|
|
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
2020-09-23 00:59:36 -04:00
|
|
|
|
Directory.CreateDirectory(modPath);
|
2020-09-12 01:34:31 -04:00
|
|
|
|
string[] modDirs = Directory.GetDirectories(modPath);
|
|
|
|
|
foreach (string path in modDirs)
|
|
|
|
|
{
|
|
|
|
|
string machinePath = path + "/Machines/";
|
2020-09-24 03:36:17 -04:00
|
|
|
|
Directory.CreateDirectory(machinePath);
|
2020-09-12 01:34:31 -04:00
|
|
|
|
DirectoryInfo d = new DirectoryInfo(machinePath);
|
|
|
|
|
foreach (FileInfo file in d.GetFiles("*.qe"))
|
|
|
|
|
{
|
|
|
|
|
string filePath = machinePath + file.Name;
|
|
|
|
|
string fileContents = File.ReadAllText(filePath);
|
2020-09-13 02:45:50 -04:00
|
|
|
|
string machineName = file.Name.Remove(file.Name.Length - 3);
|
|
|
|
|
if (!dictionary.ContainsKey(machineName))
|
|
|
|
|
{
|
|
|
|
|
dictionary.Add(machineName, playerController.modMachine);
|
|
|
|
|
List<string> objList = playerController.blockSelector.objectNames.ToList();
|
|
|
|
|
objList.Add(machineName);
|
|
|
|
|
playerController.blockSelector.objectNames = objList.ToArray();
|
2020-09-13 19:21:06 -04:00
|
|
|
|
string modName = new DirectoryInfo(path).Name;
|
2021-04-05 02:59:40 -04:00
|
|
|
|
Debug.Log("Mod "+"["+modName+"]"+" created a new machine: [" + machineName + "]");
|
2020-09-13 02:45:50 -04:00
|
|
|
|
}
|
2020-09-12 01:34:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 14:12:13 -05:00
|
|
|
|
//! Adds blocks from mods to the game.
|
|
|
|
|
public void AddModBlocks(Dictionary<string, GameObject> dictionary)
|
|
|
|
|
{
|
|
|
|
|
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
|
|
|
|
Directory.CreateDirectory(modPath);
|
|
|
|
|
string[] modDirs = Directory.GetDirectories(modPath);
|
|
|
|
|
foreach (string path in modDirs)
|
|
|
|
|
{
|
|
|
|
|
string blockPath = path + "/Blocks/";
|
|
|
|
|
Directory.CreateDirectory(blockPath);
|
|
|
|
|
DirectoryInfo d = new DirectoryInfo(blockPath);
|
|
|
|
|
foreach (FileInfo file in d.GetFiles("*.qe"))
|
|
|
|
|
{
|
|
|
|
|
string filePath = blockPath + file.Name;
|
|
|
|
|
string fileContents = File.ReadAllText(filePath);
|
|
|
|
|
string blockName = file.Name.Remove(file.Name.Length - 3);
|
|
|
|
|
if (!dictionary.ContainsKey(blockName))
|
|
|
|
|
{
|
|
|
|
|
dictionary.Add(blockName, playerController.modBlock);
|
|
|
|
|
List<string> objList = playerController.blockSelector.objectNames.ToList();
|
|
|
|
|
objList.Add(blockName);
|
|
|
|
|
playerController.blockSelector.objectNames = objList.ToArray();
|
|
|
|
|
string modName = new DirectoryInfo(path).Name;
|
|
|
|
|
playerController.gameManager.modBlockNames.Add(blockName);
|
|
|
|
|
Debug.Log("Mod "+"["+modName+"]"+" created a new block: [" + blockName + "]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
playerController.gameManager.InitModBlocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Adds blocks from mods to the game.
|
|
|
|
|
public void AddModMeshes(Dictionary<string, Mesh> dictionary)
|
|
|
|
|
{
|
|
|
|
|
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
|
|
|
|
Directory.CreateDirectory(modPath);
|
|
|
|
|
string[] modDirs = Directory.GetDirectories(modPath);
|
|
|
|
|
foreach (string path in modDirs)
|
|
|
|
|
{
|
|
|
|
|
string meshPath = path + "/Models/";
|
|
|
|
|
Directory.CreateDirectory(meshPath);
|
|
|
|
|
DirectoryInfo d = new DirectoryInfo(meshPath);
|
|
|
|
|
foreach (FileInfo file in d.GetFiles("*.obj"))
|
|
|
|
|
{
|
|
|
|
|
string filePath = meshPath + file.Name;
|
|
|
|
|
string meshName = file.Name.Remove(file.Name.Length - 4);
|
|
|
|
|
if (!dictionary.ContainsKey(meshName))
|
|
|
|
|
{
|
|
|
|
|
ObjImporter importer = new ObjImporter();
|
|
|
|
|
Mesh newMesh = importer.ImportFile(filePath);
|
|
|
|
|
dictionary.Add(meshName, newMesh);
|
|
|
|
|
string modName = new DirectoryInfo(path).Name;
|
|
|
|
|
Debug.Log("Mod "+"["+modName+"]"+" created a new mesh: [" + meshName + "]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
playerController.gameManager.InitModBlocks();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Initializes variables.
|
2020-09-07 03:40:28 -04:00
|
|
|
|
private void Init()
|
|
|
|
|
{
|
2021-05-16 14:12:13 -05:00
|
|
|
|
meshDictionary = new Dictionary<string, Mesh>();
|
|
|
|
|
|
2020-08-27 05:06:16 -04:00
|
|
|
|
blockDictionary = new Dictionary<string, GameObject>
|
|
|
|
|
{
|
|
|
|
|
{ "Brick", playerController.brick },
|
|
|
|
|
{ "Glass Block", playerController.glass },
|
|
|
|
|
{ "Iron Block", playerController.ironBlock },
|
|
|
|
|
{ "Iron Ramp", playerController.ironRamp },
|
|
|
|
|
{ "Steel Block", playerController.steel },
|
|
|
|
|
{ "Steel Ramp", playerController.steelRamp }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
machineDictionary = new Dictionary<string, GameObject>
|
2020-08-27 02:08:41 -04:00
|
|
|
|
{
|
2021-05-16 14:12:13 -05:00
|
|
|
|
{ "Quantum Hatchway", playerController.quantumHatchway },
|
|
|
|
|
{ "Door", playerController.door },
|
2020-08-27 02:08:41 -04:00
|
|
|
|
{ "Alloy Smelter", playerController.alloySmelter },
|
|
|
|
|
{ "Auger", playerController.auger },
|
|
|
|
|
{ "Auto Crafter", playerController.autoCrafter },
|
|
|
|
|
{ "Dark Matter Collector", playerController.darkMatterCollector },
|
|
|
|
|
{ "Dark Matter Conduit", playerController.darkMatterConduit },
|
|
|
|
|
{ "Electric Light", playerController.electricLight },
|
|
|
|
|
{ "Extruder", playerController.extruder },
|
|
|
|
|
{ "Gear Cutter", playerController.gearCutter },
|
|
|
|
|
{ "Generator", playerController.generator },
|
|
|
|
|
{ "Heat Exchanger", playerController.heatExchanger },
|
|
|
|
|
{ "Nuclear Reactor", playerController.nuclearReactor },
|
|
|
|
|
{ "Power Conduit", playerController.powerConduit },
|
|
|
|
|
{ "Press", playerController.press },
|
|
|
|
|
{ "Rail Cart", playerController.railCart },
|
|
|
|
|
{ "Rail Cart Hub", playerController.railCartHub },
|
|
|
|
|
{ "Reactor Turbine", playerController.reactorTurbine },
|
|
|
|
|
{ "Retriever", playerController.retriever },
|
|
|
|
|
{ "Smelter", playerController.smelter },
|
|
|
|
|
{ "Solar Panel", playerController.solarPanel },
|
|
|
|
|
{ "Storage Computer", playerController.storageComputer },
|
2020-08-27 05:06:16 -04:00
|
|
|
|
{ "Storage Container", playerController.storageContainer },
|
|
|
|
|
{ "Turret", playerController.turret },
|
2021-04-03 23:02:09 -04:00
|
|
|
|
{ "Missile Turret", playerController.missileTurret },
|
2020-08-27 02:08:41 -04:00
|
|
|
|
{ "Universal Conduit", playerController.universalConduit },
|
|
|
|
|
{ "Universal Extractor", playerController.universalExtractor }
|
|
|
|
|
};
|
2021-05-16 14:12:13 -05:00
|
|
|
|
|
|
|
|
|
typeDictionary = new Dictionary<string, Type>
|
|
|
|
|
{
|
|
|
|
|
{ "Door", typeof (Door) },
|
|
|
|
|
{ "Quantum Hatchway", typeof (Door) },
|
|
|
|
|
{ "Alloy Smelter", typeof (AlloySmelter) },
|
|
|
|
|
{ "Auger", typeof (Auger) },
|
|
|
|
|
{ "Auto Crafter", typeof (AutoCrafter) },
|
|
|
|
|
{ "Dark Matter Collector", typeof (DarkMatterCollector) },
|
|
|
|
|
{ "Dark Matter Conduit", typeof (DarkMatterConduit) },
|
|
|
|
|
{ "Electric Light", typeof (ElectricLight) },
|
|
|
|
|
{ "Extruder", typeof (Extruder) },
|
|
|
|
|
{ "Gear Cutter", typeof (GearCutter) },
|
|
|
|
|
{ "Generator", typeof (PowerSource) },
|
|
|
|
|
{ "Heat Exchanger", typeof (HeatExchanger) },
|
|
|
|
|
{ "Nuclear Reactor", typeof (NuclearReactor) },
|
|
|
|
|
{ "Power Conduit", typeof (PowerConduit) },
|
|
|
|
|
{ "Press", typeof (Press) },
|
|
|
|
|
{ "Rail Cart", typeof (RailCart) },
|
|
|
|
|
{ "Rail Cart Hub", typeof (RailCartHub) },
|
|
|
|
|
{ "Reactor Turbine", typeof (PowerSource) },
|
|
|
|
|
{ "Retriever", typeof (Retriever) },
|
|
|
|
|
{ "Smelter", typeof (Smelter) },
|
|
|
|
|
{ "Solar Panel", typeof (PowerSource) },
|
|
|
|
|
{ "Storage Computer", typeof (StorageComputer) },
|
|
|
|
|
{ "Storage Container", typeof (InventoryManager) },
|
|
|
|
|
{ "Turret", typeof (Turret) },
|
|
|
|
|
{ "Universal Conduit", typeof (UniversalConduit) },
|
|
|
|
|
{ "Universal Extractor", typeof (UniversalExtractor) },
|
|
|
|
|
{ "Brick", typeof (Brick) },
|
|
|
|
|
{ "Glass Block", typeof (Glass) },
|
|
|
|
|
{ "Iron Block", typeof (IronBlock) },
|
|
|
|
|
{ "Iron Ramp", typeof (IronBlock) },
|
|
|
|
|
{ "Steel Block", typeof (Steel) },
|
|
|
|
|
{ "Steel Ramp", typeof (Steel) }
|
|
|
|
|
};
|
2020-08-27 02:08:41 -04:00
|
|
|
|
}
|
|
|
|
|
}
|