Exemplo n.º 1
0
        /// <summary>
        /// Handles the Save click event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The args.</param>
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DefinitionSerializer.ReserializeToFiles(
                    new DefinitionCollection(this.context.Definitions.Select(x => x.BaseDefinition)));
            }
#pragma warning disable CA1031 // Do not catch general exception types. Intentional to ensure data is not lost.
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                System.Windows.MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the context object.
        /// </summary>
        /// <returns>THe context object.</returns>
        public static Context InitContext()
        {
            int worldSeed = 915434125;

            ConditionCompiler <BaseGlobalVariables> processor =
                new ConditionCompiler <BaseGlobalVariables>(new BaseGlobalVariables()
            {
                World = new World(),
            });
            Definitions  definitions = DefinitionSerializer.DeserializeFromDirectory(processor, "Definitions");
            ThingFactory factory     = new ThingFactory(definitions);

            HistoryGenerator history = new HistoryGenerator(factory, definitions);

            WorldGen.WorldGenerator worldGen = new WorldGen.WorldGenerator(worldSeed, factory);
            int   width  = 200;
            int   height = 200;
            World world  = worldGen.GenerateWorld(width, height);

            processor.UpdateGlobalVariables(g => g.World = world);

            Random rdm = new Random(worldSeed);

            for (int i = 0; i < 100; i++)
            {
                int  x        = rdm.Next(0, width - 1);
                int  y        = rdm.Next(0, height - 1);
                Site cityInst = factory.CreateSite(rdm, x, y, "City");
                world.Grid.AddThing(cityInst);
            }

            foreach (var thing in world.Grid.AllGridEntries.SelectMany(x => x.Square.GetThings()))
            {
                thing.FinalizeConstruction(new Random());
            }

            Context.Instance.Attach(history, world, processor);

            return(Context.Instance);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HistoryGenerator"/> class.
 /// </summary>
 /// <param name="compiler">THe condition compiler to use.</param>
 /// <param name="definitionDirectory">A directory full of definition json files.</param>
 /// <param name="additionalDefinitionDirectories">Optional additional directories to get definition json files from.</param>
 public HistoryGenerator(IConditionCompiler compiler, string definitionDirectory, params string[] additionalDefinitionDirectories)
     : this(DefinitionSerializer.DeserializeFromDirectory(compiler, definitionDirectory)
            .Combine(additionalDefinitionDirectories.Select(d => DefinitionSerializer.DeserializeFromDirectory(compiler, d)).ToArray()))
 {
 }