예제 #1
0
        SdfFile(XmlNode node)
        {
            List <Model> models = new List <Model>();
            List <World> worlds = new List <World>();
            List <Light> lights = new List <Light>();

            Models = models.AsReadOnly();
            Lights = lights.AsReadOnly();
            Worlds = worlds.AsReadOnly();

            foreach (XmlNode child in node.ChildNodes)
            {
                switch (child.Name)
                {
                case "world":
                    worlds.Add(new World(child));
                    break;

                case "model":
                    models.Add(new Model(child));
                    break;

                case "light":
                    lights.Add(new Light(child));
                    break;
                }
            }

            HasIncludes = Worlds.Any(world => world.HasIncludes) || Models.Any(model => model.HasIncludes);
        }
예제 #2
0
 /// <summary>
 /// Adds a world to this level.
 /// </summary>
 public void AddWorld(World world)
 {
     if (Worlds.Any(w => w.Name.ToUpper() == world.Name.ToUpper()))
     {
         throw new InvalidOperationException("A world with the same name already exists in this level.");
     }
     Worlds.Add(world);
 }
예제 #3
0
        /// <summary>
        /// Creates and adds a world to this level, with the given name.
        /// </summary>
        public void AddWorld(string name, IWorldGenerator worldGenerator = null)
        {
            if (Worlds.Any(w => w.Name.ToUpper() == name.ToUpper()))
            {
                throw new InvalidOperationException("A world with the same name already exists in this level.");
            }
            var world = new World(name);

            if (worldGenerator == null)
            {
                world.WorldGenerator = WorldGenerator;
            }
            else
            {
                world.WorldGenerator = worldGenerator;
            }
            Worlds.Add(world);
        }