Exemple #1
0
 public void Save(string fileName)
 {
     using (Stream stream = File.Create(fileName))
     {
         SimulationSerializer.Save(stream, this);
     }
 }
        private void SetupDropDown()
        {
            var filenames = SimulationSerializer.GetEvolutionSaveFilenames();

            var saveFiles = new List <string>();

            if (filenames.Count == 0)
            {
                saveFiles.Add(NO_SAVE_FILES);
            }
            else
            {
                //saveFilesExists = true;
            }

            foreach (var name in filenames)
            {
                saveFiles.Add(name.Replace(".txt", ""));
            }

            dropdown.ClearOptions();
            dropdown.AddOptions(saveFiles);

            if (filenames.Count > 0)
            {
                dropdown.Show();
            }
        }
Exemple #3
0
        private void OpenFile(string fileName)
        {
            try
            {
                if (string.Equals(Path.GetExtension(fileName), ".js"))
                {
                    scriptTextBox.Text = File.ReadAllText(fileName);

                    tabControl.SelectedTab = scriptTabPage;

                    _scriptFileName = fileName;
                }
                else
                {
                    _simulation = SimulationSerializer.LoadFrom(fileName);
                    _fileName   = fileName;
                }

                this.UpdateUi();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to open file. {0}", ex.GetBaseException().Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private IEnumerator LoadOnNextFrame(string filename)
        {
            yield return(new WaitForEndOfFrame());

            var simulationData = SimulationSerializer.LoadSimulationData(filename);

            editor.StartSimulation(simulationData);
        }
Exemple #5
0
        public void DeleteButtonClicked(FileSelectionViewController controller)
        {
            var filename = filenames[selectedIndex];

            SimulationSerializer.DeleteSaveFile(filename);
            selectedIndex = 0;
            RefreshCache();
        }
Exemple #6
0
        public void ExportButtonClicked(FileSelectionViewController controller)
        {
            var    name = filenames[selectedIndex];
            string path = SimulationSerializer.PathToSimulationSave(name);

            FileToSave file = new FileToSave(path, CustomEvolutionFileType.evol);

            NativeFileSO.NativeFileSO.shared.SaveFile(file);
        }
Exemple #7
0
        public string SaveSimulation()
        {
            var savefileName = SimulationSerializer.SaveSimulation(SimulationData);

            this.LastSavedGeneration = currentGenerationNumber;
            if (SimulationWasSaved != null)
            {
                SimulationWasSaved();
            }
            return(savefileName);
        }
Exemple #8
0
        public void DidEditTitleAtIndex(FileSelectionViewController controller, int index, string newName)
        {
            if (!IsNameAvailable(controller, newName))
            {
                return;
            }

            var currentName = filenames[index];

            SimulationSerializer.RenameSimulationSave(currentName, newName);
            RefreshCache();
        }
Exemple #9
0
        public void LoadTest()
        {
            // arrange
            Simulation expected;
            Simulation actual;

            expected = new Simulation();

            // act
            actual = SimulationSerializer.LoadFrom(this.GetDataFileName("default.sim"));

            // assert
            SimulationAssert.AreEqual(expected, actual);
        }
Exemple #10
0
        public void LoadAdvancedTest()
        {
            // arrange
            Simulation expected;
            Simulation actual;

            expected = this.CreateDemonstrationSimulation();

            // act
            actual = SimulationSerializer.LoadFrom(this.GetDataFileName("advanced.sim"));

            // assert
            SimulationAssert.AreEqual(expected, actual);
        }
        public void PromptSavefileDelete()
        {
            var filename = dropdown.options[dropdown.value].text;

            if (filename == NO_SAVE_FILES)
            {
                return;
            }

            filename += ".txt";

            //deleteConfirmation.ConfirmDeletionFor(filename);
            deleteConfirmation.ConfirmDeletionFor(filename, delegate(string name) {
                SimulationSerializer.DeleteSaveFile(filename);

                SetupDropDown();
                dropdown.value = 0;
            });
        }
Exemple #12
0
        private void TryImport(OpenedFile[] files)
        {
            // Whether at least one file was successfully imported
            var successfulImport = false;
            // Whether at least one .evol file failed to be imported
            var failedImport = false;

            foreach (OpenedFile file in files)
            {
                var extension = file.Extension.ToLower();
                if (extension.Equals(".evol"))
                {
                    var encoded = file.ToUTF8String();
                    try {
                        var simulationData = SimulationSerializer.ParseSimulationData(encoded, file.Name);
                        // SimulationSerializer.SaveSimulation(simulationData);
                    } catch {
                        failedImport = true;
                        Debug.LogError(string.Format("Failed to parse .evol file contents: {0}", encoded));
                        continue;
                    }
                    SimulationSerializer.SaveSimulationFile(file.Name, encoded, false);
                    successfulImport = true;
                }
            }
            RefreshCache();
            try {
                viewController.Refresh();
            } catch {
                DelayExtensions.Delay(this, 0.2f, delegate() { viewController.Refresh(); });
            }
            if (successfulImport)
            {
                importIndicator.FadeInOut();
            }
            if (failedImport)
            {
                failedImportIndicator.FadeInOut(1.8f);
            }
        }
Exemple #13
0
        public void SaveTest()
        {
            // arrange
            Simulation   simulation;
            string       expected;
            string       actual;
            StringWriter writer;

            simulation = new Simulation();

            expected = File.ReadAllText(this.GetDataFileName("default.sim"));

            writer = new StringWriter();

            // act
            SimulationSerializer.Save(writer, simulation);

            // assert
            actual = writer.ToString();
            // File.WriteAllText(@"D:\Checkout\trunk\cyotek\source\demo\ChemotaxisSimulation\tests\data\default.sim", actual);
            Assert.AreEqual(expected, actual);
        }
Exemple #14
0
 public bool IsNameAvailable(FileSelectionViewController controller, string newName)
 {
     return(!SimulationSerializer.SimulationSaveExists(newName));
 }
Exemple #15
0
 private void RefreshCache()
 {
     filenames = SimulationSerializer.GetEvolutionSaveFilenames()
                 .Select(filename => SimulationSerializer.EXTENSION_PATTERN.Replace(filename, ""))
                 .ToList();
 }