コード例 #1
0
        /// <summary>
        /// Public Interface, for loading all the entities.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <EntityData> LoadEntities()
        {
            if (!_fileOpened)
            {
                DefaultLogger.WriteExceptionThenQuit(MessageType.FileIOError,
                                                     new InvalidOperationException("EntityParser cannot load entities before file has been opened."));
            }

            // otherwise file is open
            return(ParseEntities(_xmlDoc.Descendants("Entity")));
        }
コード例 #2
0
        public void RemoveEntity(IEntity entity)
        {
            if (!_context.Entities.Contains(entity))
            {
                DefaultLogger.WriteExceptionThenQuit(
                    MessageType.RuntimeException,
                    new InvalidOperationException(
                        string.Format("Attempting to remove entity {0} which is not in the entity repository.",
                                      entity.ToString()))
                    );
            }

            // safe to remove entity
            _context.Entities.Remove(entity);
        }
コード例 #3
0
        public void InsertEntity(IEntity entity)
        {
            if (_context.Entities.Contains(entity))
            {
                DefaultLogger.WriteExceptionThenQuit(
                    MessageType.RuntimeException,
                    new InvalidOperationException(
                        string.Format("Attempting to add already existing entity {0} to entity repository",
                                      entity.ToString()))
                    );
            }

            // safe to add entity
            _context.Entities.Add(entity);
        }
コード例 #4
0
ファイル: Entity.cs プロジェクト: bjadamson/Smashteroids
        public void RemoveComponent(Component component)
        {
            if (!ContainsComponent(component))
            {
                DefaultLogger.WriteExceptionThenQuit(
                    MessageType.RuntimeException,
                    new InvalidOperationException(
                        string.Format("Attempting to remove non-existing component {0} to entity {1}.",
                                      component.ToString(), this.ToString()))
                    );
            }

            // safe to remove component
            _components.Remove(component);

            //ResolveComponentDependencies();
        }
コード例 #5
0
ファイル: Entity.cs プロジェクト: bjadamson/Smashteroids
        //private void ResolveComponentDependencies()
        //{
        //    var r = Components.Where(c => c.GetType() == typeof(RenderableComponent));
        //    var p = Components.Where(c => c.GetType() == typeof(PlayerComponent));

        //    // if the entity has both renderable component and a player component
        //    if (r.Any() && p.Any())
        //    {
        //        (p.FirstOrDefault() as PlayerComponent).Player.Sprite = (r.FirstOrDefault() as RenderableComponent).Sprite;
        //    }

        //    // otherwise we need to check if we need to remove any dependences (ie when removing a component dynamically)
        //    else
        //    {
        //        // if there is a player, and no renderable component
        //        // NOTE: the !r.any() is unnecessary for now, but leaving it in for when we expand this system.
        //        if (p.Any() && !r.Any())
        //        {
        //            (r.FirstOrDefault() as RenderableComponent).Sprite = null;
        //        }
        //    }
        //}

        #endregion

        #region IEntity Members

        public void AddComponent(Component component)
        {
            if (ContainsComponent(component))
            {
                DefaultLogger.WriteExceptionThenQuit(
                    MessageType.RuntimeException,
                    new InvalidOperationException(
                        string.Format("Attempting to add already existing component {0} to entity {1}",
                                      component.ToString(), this.ToString()))
                    );
            }

            // safe to attach component to entity
            _components.Add(component);

            //ResolveComponentDependencies();
        }
コード例 #6
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Instance instance = new Instance())
     {
         try
         {
             instance.Run();
         }
         catch (Exception e)
         {
             if (EntityIoLogger.FatalExceptionCaught)
             {
                 DefaultLogger.WriteExceptionThenQuit(MessageType.UncaughtRuntimeException, e, "Caught in main program.cs");
                 DefaultLogger.Close();
                 instance.Exit();
             }
         }
     }
 }
コード例 #7
0
        public Texture2D GetTextureByFilename(string filename)
        {
            if (ContainsTextureWithFilename(filename))
            {
                return(_textures[filename]);
            }

            try
            {
                // texture is not already present, ok to add
                Texture2D texture = _contentManager.Load <Texture2D>("./images/" + filename);

                DefaultLogger.WriteLine(MessageType.Information, string.Format("Texture {0} loaded into texture repository. Texture width: {1}, height {2}.",
                                                                               texture.Name, texture.Width, texture.Height));

                _textures.Add(filename, texture);
                return(texture);
            }
            catch (ContentLoadException cle)
            {
                DefaultLogger.WriteExceptionThenQuit(MessageType.RuntimeException, cle);
                return(default(Texture2D));
            }
        }