public void saveButton()
    {
        //saves the current state of all the terminals

        string path = Application.dataPath + "/Default/Resources/Default/Saves";

        EnterTextContent saveContent = new EnterTextContent("Enter in the name for your save", (string enteredText) => {
            string illegal     = enteredText + "~" + System.DateTime.Now.ToString();
            string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
            Regex r            = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
            illegal            = r.Replace(illegal, " ");

            Save.makeDirectory(path, illegal);

            path += "/" + illegal + "/";

            string terminalFolder = "Terminals";
            Save.makeDirectory(path, terminalFolder);

            path += "/" + terminalFolder;


            foreach (TerminalController ter in this.terminalManager.TerminalControllers)
            {
                //makes terminal directory
                Save.makeDirectory(path, ter.Terminal.Name);
                string tempPath = path + "/" + ter.Terminal.Name + "/";

                //saves terminal json
                Save.saveJson <TerminalData>(new TerminalData(ter.Terminal), tempPath, ter.Terminal.Name + ".json");

                //saves the connections
                Save.saveJson <TExtensionConnectionsData>(new TExtensionConnectionsData(ter.Terminal), tempPath, typeof(TExtensionConnectionsData).ToString() + ".json");

                //makes directory for logic graphs
                Save.makeDirectory(tempPath, "LogicGraphs");
                tempPath += "/LogicGraphs";

                for (int i = 0; i < ter.Terminal.extensionLength(); i++)
                {
                    TExtension extension = ter.Terminal.extensionAt(i);
                    if (extension.GetType() == typeof(LogicChip))
                    {
                        string name = extension.Name + ".json";

                        LogicChip lg = (LogicChip)extension;
                        Save.saveJson <LogicGraphData>(new LogicGraphData(lg), tempPath, name);
                    }
                }
            }
        }, () => { }, 50);

        WindowManager.Instance.spawnWindow(new Window("Save Game", 200, 200, saveContent));
    }
Exemplo n.º 2
0
 public bool Equals(TExtension?x, TExtension?y) => object.Equals(x?.GetType(), y?.GetType());