Esempio n. 1
0
        public bool Execute(IDebugConsole console, params string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                console.AddLine("Must pass exactly 2 or 3 arguments", Color.Red);
                return(false);
            }

            var            gridID     = new GridId(int.Parse(args[0], CultureInfo.InvariantCulture));
            var            indexSplit = args[1].Split(',');
            var            x          = int.Parse(indexSplit[0], CultureInfo.InvariantCulture);
            var            y          = int.Parse(indexSplit[1], CultureInfo.InvariantCulture);
            var            indices    = new MapIndices(x, y);
            SnapGridOffset offset     = SnapGridOffset.Center;

            if (args.Length == 3)
            {
                offset = (SnapGridOffset)Enum.Parse(typeof(SnapGridOffset), args[2]);
            }

            var mapMan = IoCManager.Resolve <IMapManager>();
            var grid   = mapMan.GetGrid(gridID);

            foreach (var entity in grid.GetSnapGridCell(indices, offset))
            {
                console.AddLine(entity.Owner.Uid.ToString());
            }

            return(false);
        }
Esempio n. 2
0
        public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IMapGrid grid,
                                                   SnapGridOffset offset = SnapGridOffset.Center)
        {
            var tileSize = grid.TileSize;

            var localPos = coordinates.Position;

            var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / (offset == SnapGridOffset.Center ? 2f : 0f);
            var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / (offset == SnapGridOffset.Center ? 2f : 0f);

            return(new EntityCoordinates(coordinates.EntityId, x, y));
        }
            public MapIndices SnapGridCellFor(GridLocalCoordinates worldPos, SnapGridOffset offset)
            {
                var local = worldPos.ConvertToGrid(this);

                if (offset == SnapGridOffset.Edge)
                {
                    local = local.Offset(new Vector2(TileSize / 2f, TileSize / 2f));
                }
                var x = (int)Math.Floor(local.X / TileSize);
                var y = (int)Math.Floor(local.Y / TileSize);

                return(new MapIndices(x, y));
            }
Esempio n. 4
0
        /// <inheritdoc />
        public void AddToSnapGridCell(ushort xCell, ushort yCell, SnapGridOffset offset, SnapGridComponent snap)
        {
            if (xCell >= ChunkSize)
            {
                throw new ArgumentOutOfRangeException(nameof(xCell), "Tile indices out of bounds.");
            }

            if (yCell >= ChunkSize)
            {
                throw new ArgumentOutOfRangeException(nameof(yCell), "Tile indices out of bounds.");
            }

            ref var cell = ref _snapGrid[xCell, yCell];
Esempio n. 5
0
        public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates,
                                                   SnapGridOffset offset = SnapGridOffset.Center, IEntityManager?entityManager = null, IMapManager?mapManager = null)
        {
            entityManager ??= IoCManager.Resolve <IEntityManager>();
            mapManager ??= IoCManager.Resolve <IMapManager>();

            var gridId = coordinates.GetGridId(entityManager);

            var tileSize = 1f;

            if (gridId.IsValid())
            {
                var grid = mapManager.GetGrid(gridId);
                tileSize = grid.TileSize;
            }

            var localPos = coordinates.Position;

            var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / (offset == SnapGridOffset.Center ? 2f : 0f);
            var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / (offset == SnapGridOffset.Center ? 2f : 0f);

            return(new EntityCoordinates(coordinates.EntityId, x, y));
        }
Esempio n. 6
0
 public static void SnapToGrid(this IEntity entity, SnapGridOffset offset = SnapGridOffset.Center, IEntityManager?entityManager = null, IMapManager?mapManager = null)
 {
     entity.Transform.Coordinates = entity.Transform.Coordinates.SnapToGrid(offset, entityManager, mapManager);
 }
 public void AddToSnapGridCell(ushort xCell, ushort yCell, SnapGridOffset offset, SnapGridComponent snap)
 {
     ref var cell = ref _snapGrid[xCell, yCell];
            public IEnumerable <SnapGridComponent> GetSnapGridCell(ushort xCell, ushort yCell, SnapGridOffset offset)
            {
                var cell = _snapGrid[xCell, yCell];
                List <SnapGridComponent> list;

                if (offset == SnapGridOffset.Center)
                {
                    list = cell.Center;
                }
                else
                {
                    list = cell.Edge;
                }

                if (list != null)
                {
                    foreach (var element in list)
                    {
                        yield return(element);
                    }
                }
            }
 public void RemoveFromSnapGridCell(GridLocalCoordinates worldPos, SnapGridOffset offset, SnapGridComponent snap)
 {
     RemoveFromSnapGridCell(SnapGridCellFor(worldPos, offset), offset, snap);
 }
 public void RemoveFromSnapGridCell(MapIndices pos, SnapGridOffset offset, SnapGridComponent snap)
 {
     var(chunk, chunkTile) = ChunkAndOffsetForTile(pos);
     chunk.RemoveFromSnapGridCell((ushort)chunkTile.X, (ushort)chunkTile.Y, offset, snap);
 }
 public void AddToSnapGridCell(GridLocalCoordinates worldPos, SnapGridOffset offset, SnapGridComponent snap)
 {
     AddToSnapGridCell(SnapGridCellFor(worldPos, offset), offset, snap);
 }
 public IEnumerable <SnapGridComponent> GetSnapGridCell(MapIndices pos, SnapGridOffset offset)
 {
     var(chunk, chunkTile) = ChunkAndOffsetForTile(pos);
     return(chunk.GetSnapGridCell((ushort)chunkTile.X, (ushort)chunkTile.Y, offset));
 }
 public IEnumerable <SnapGridComponent> GetSnapGridCell(GridLocalCoordinates worldPos, SnapGridOffset offset)
 {
     return(GetSnapGridCell(SnapGridCellFor(worldPos, offset), offset));
 }
Esempio n. 14
0
        /// <inheritdoc />
        public IEnumerable <SnapGridComponent> GetSnapGridCell(ushort xCell, ushort yCell, SnapGridOffset offset)
        {
            if (xCell >= ChunkSize)
            {
                throw new ArgumentOutOfRangeException(nameof(xCell), "Tile indices out of bounds.");
            }

            if (yCell >= ChunkSize)
            {
                throw new ArgumentOutOfRangeException(nameof(yCell), "Tile indices out of bounds.");
            }

            var cell = _snapGrid[xCell, yCell];
            var list = offset == SnapGridOffset.Center ? cell.Center : cell.Edge;

            if (list == null)
            {
                return(Array.Empty <SnapGridComponent>());
            }

            return(list);
        }
Esempio n. 15
0
        /// <inheritdoc />
        public IEnumerable <SnapGridComponent> GetSnapGridCell(ushort xCell, ushort yCell, SnapGridOffset offset)
        {
            if (xCell >= ChunkSize)
            {
                throw new ArgumentOutOfRangeException(nameof(xCell), "Tile indices out of bounds.");
            }

            if (yCell >= ChunkSize)
            {
                throw new ArgumentOutOfRangeException(nameof(yCell), "Tile indices out of bounds.");
            }

            var cell = _snapGrid[xCell, yCell];
            var list = offset == SnapGridOffset.Center ? cell.Center : cell.Edge;

            if (list == null)
            {
                yield break;
            }

            foreach (var element in list)
            {
                yield return(element);
            }
        }