Esempio n. 1
0
        public void RefreshGameObjectTable()
        {
            GameObjectTable.Clear();

            Dictionary <GameObjectType, Dictionary <string, int> > nextX     = new Dictionary <GameObjectType, Dictionary <string, int> >();
            Dictionary <GameObjectType, Dictionary <string, int> > nextY     = new Dictionary <GameObjectType, Dictionary <string, int> >();
            Dictionary <GameObjectType, Dictionary <string, int> > maxHeight = new Dictionary <GameObjectType, Dictionary <string, int> >();

            foreach (GameObject gameObject in _project.GameObjects.Where(g => g != null).OrderBy(g => g.Name))
            {
                if (!nextX.ContainsKey(gameObject.GameObjectType))
                {
                    nextX[gameObject.GameObjectType]     = new Dictionary <string, int>();
                    nextY[gameObject.GameObjectType]     = new Dictionary <string, int>();
                    maxHeight[gameObject.GameObjectType] = new Dictionary <string, int>();
                }

                if (!nextX[gameObject.GameObjectType].ContainsKey(gameObject.Group))
                {
                    nextX[gameObject.GameObjectType][gameObject.Group]     = 0;
                    nextY[gameObject.GameObjectType][gameObject.Group]     = 0;
                    maxHeight[gameObject.GameObjectType][gameObject.Group] = 0;
                }

                var nextObject = new LevelObject()
                {
                    GameObjectId = gameObject.GameId,
                    GameObject   = gameObject,
                    X            = nextX[gameObject.GameObjectType][gameObject.Group],
                    Y            = nextY[gameObject.GameObjectType][gameObject.Group]
                };

                Rect rect = nextObject.CalcBoundBox();

                int actualX = (int)(rect.X / 16);
                int actualY = (int)(rect.Y / 16);

                if (nextObject.X - actualX >= 1)
                {
                    if (nextObject.X == 0)
                    {
                        nextObject.X += nextObject.X - actualX;
                    }
                    else
                    {
                        nextObject.X += (nextObject.X - actualX - 1);
                    }

                    rect = nextObject.CalcBoundBox();
                }

                if (nextObject.Y - actualY >= 1)
                {
                    nextObject.Y += (nextObject.Y - actualY - 1);
                    rect          = nextObject.CalcBoundBox();
                }

                if ((int)(rect.Height / 16) > maxHeight[gameObject.GameObjectType][gameObject.Group])
                {
                    maxHeight[gameObject.GameObjectType][gameObject.Group] = (int)(rect.Height / 16);
                }

                if (rect.X + rect.Width > 256)
                {
                    nextX[gameObject.GameObjectType][gameObject.Group] = nextObject.X = 0;
                    nextY[gameObject.GameObjectType][gameObject.Group] = nextObject.Y += maxHeight[gameObject.GameObjectType][gameObject.Group] + 1;
                    rect = nextObject.CalcBoundBox();
                }

                nextX[gameObject.GameObjectType][gameObject.Group] += (int)(rect.Width / 16) + (rect.Width % 16 > 0 ? 2 : 1);

                GameObjectTable.AddObject(gameObject.GameObjectType, gameObject.Group, nextObject);
            }
        }