コード例 #1
0
        static void HeadlessSimulation(Options options)
        {
            if (options.StatFilePath is null || options.SettingsPath is null)
            {
                Console.WriteLine("Must provide 'statoutfile' and 'config'");
                return;
            }

            bool error = false;
            SimulationSettings       settings = DefaultSimulationSettings.GetSettings();
            EntityDefinitionDatabase database = new EntityDefinitionDatabase();

            if (!(options.SettingsPath is null))
            {
                try
                {
                    settings = LocalStorage.LoadSettingsFile(options.SettingsPath);
                }
                catch (Exception)
                {
                    error = true;
                    Console.WriteLine("Failed to load settings file.");
                }
            }
            if (!(options.SettingsPath is null))
            {
                try
                {
                    database = LocalStorage.GetDefinitionDatabase(options.EntityFolderPath);
                }
                catch (Exception)
                {
                    error = true;
                    Console.WriteLine("Failed to load entity definition database folder.");
                }
            }
            if (error)
            {
                return;
            }

            Simulation simulation = new Simulation(settings, database);

            simulation.SetUp();
        }
コード例 #2
0
ファイル: EditorForm.cs プロジェクト: aszpreece/SoupV2
        public EditorForm()
        {
            InitializeComponent();

            treeView1.AfterSelect += TreeView1_AfterSelect;

            // Default entity
            soupGraphicControl1.GraphicsInitialized += SoupGraphicControl1_GraphicsInitialized;

            // Add in drop down buttons for built in entities
            openBuiltIn.DropDownItems.AddRange(
                EntityDefinitionDatabase.DefaultEntities
                .Select((name) => new ToolStripMenuItem(name, null,
                                                        (s, a) =>
            {
                var db         = new EntityDefinitionDatabase();
                var definition = db.GetEntityDefinition(name);
                OpenEntity(definition);
            }))
                .ToArray());
        }
コード例 #3
0
ファイル: LocalStorage.cs プロジェクト: aszpreece/SoupV2
        /// <summary>
        /// Loads the entity definitions present at the given path.
        /// </summary>
        /// <returns></returns>
        public static EntityDefinitionDatabase GetDefinitionDatabase(string path)
        {
            EntityDefinitionDatabase database = new EntityDefinitionDatabase();

            if (!Directory.Exists(path))
            {
                throw new Exception("Entity definition path does not exist");
            }
            foreach (string entityPath in Directory.GetFiles(path, $"*.{EntityFileExtension}"))
            {
                // Definition id is declared as the name of the file.
                string definitionId = Path.GetFileName(entityPath);

                using (StreamReader reader = new(entityPath))
                {
                    string json = reader.ReadToEnd();
                    database.AddDefinition(definitionId, new SoupV2.EntityComponentSystem.EntityDefinition(json));
                }
            }

            return database;
        }