Exemple #1
0
        public void InitalizeFilter(BlockLocation block1, BlockLocation block2, Material newBlock)
        {
            center   = new Vector3();
            center.x = block1.x + block2.x;
            center.y = block1.y + block2.y;
            center.z = block1.z + block2.z;
            center  /= 2f;

            size   = new Vector3();
            size.x = Mathf.Max(block1.x, block2.x) - Mathf.Min(block1.x, block2.x) + 1;
            size.y = Mathf.Max(block1.y, block2.y) - Mathf.Min(block1.y, block2.y) + 1;
            size.z = Mathf.Max(block1.z, block2.z) - Mathf.Min(block1.z, block2.z) + 1;
            size  /= 2f;
        }
Exemple #2
0
        public void Modify(BlockLocation Location, byte blockId, IWorld world)
        {
            if (m_Helpers.TryGetValue(Location.ChunkInWorld.Value, out var Chunkhelper))
            {
                Chunkhelper.Modify(Location.SecInChunk, Location.BlkInSec, blockId);
            }
            else
            {
                m_Changes.Add(new ChunkChange(Location.ChunkInWorld.Value));
                Chunkhelper = new SaveHelper_Chunk(m_Changes[m_Changes.Count - 1]);

                m_Helpers.Add(Location.ChunkInWorld.Value, Chunkhelper);
                Chunkhelper.Modify(Location.SecInChunk, Location.BlkInSec, blockId);
            }
        }
            public override void Visit(Node root)
            {
                CanInsert = false;

                /// Блок можно вставить как новый корень, если он
                /// охватывает область, соответствующую корню, или если корень - это Any
                if (BlockLocation.Includes(root.Location) || root.Symbol == Grammar.ANY_TOKEN_NAME)
                {
                    CanInsert = true;
                }
                else
                {
                    VisitInner(root);
                }
            }
            public void VisitInner(Node node)
            {
                /// Потомки, вложенные в область блока или совпадающие с ним
                var included = node.Children.Where(c => BlockLocation.Includes(c.Location)).ToList();
                /// Потомки, строго пересекающиеся с блоком
                var overlapped = node.Children.Where(c => BlockLocation.Overlaps(c.Location)).ToList();
                /// Потомки, охватывающие область блока, но не совпадающие с ним
                var outer = node.Children.Where(c => c.Location != null &&
                                                c.Location.Includes(BlockLocation) && !c.Location.Equals(BlockLocation)).ToList();

                if (outer.Count == 1)
                {
                    /// Если блок вложен в Any, его можно сделать
                    /// дочерним по отношению к Any
                    if (outer[0].Symbol == Grammar.ANY_TOKEN_NAME)
                    {
                        CanInsert = true;
                    }
                    else
                    {
                        VisitInner(outer[0]);
                    }
                }
                else if (overlapped.Count == 1 && included.Count == 0)
                {
                    /// Если блок перекрывает Any и ничего не включает в себя,
                    /// его можно сделать дочерним по отношению к Any
                    if (overlapped[0].Symbol == Grammar.ANY_TOKEN_NAME)
                    {
                        CanInsert = true;
                    }
                    else
                    {
                        VisitInner(overlapped[0]);
                    }
                }
                /// Если блок включает в себя некоторое количество
                /// дочерних узлов текущего узла и ничего не перекрывает,
                /// им можно заменить эти дочерние узлы;
                /// если блок вообще ничего не перекрывает и ни с чем не пересекается,
                /// его можно вставить между дочерними узлами
                else if (included.Count > 0 && overlapped.Count == 0 ||
                         included.Count == 0 && overlapped.Count == 0)
                {
                    CanInsert = true;
                }
            }
Exemple #5
0
        public float AvoidInerSection_Down(float velocity, Vector3 CurPosition)
        {
            BlockLocation DownLoc;
            float         unitV = velocity - (int)velocity;

            for (float j = 0; j < -velocity; ++j)
            {
                DownLoc = new BlockLocation(CurPosition + new Vector3(0, unitV - j, 0), m_World);
                if (DownLoc.HasObstacle())
                {
                    m_Communicator.Publish(new E_Cha_Collision());
                    m_Communicator.Publish(new E_Cha_TouchGround());
                    return
                        (DownLoc.Bound.max.y - CurPosition.y);
                }
            }
            return(velocity);
        }
Exemple #6
0
        public void onBlockChange(int x, int y, int z, int blockID)
        {
            String        key = x + ":" + y + ":" + z;
            BlockLocation loc = new BlockLocation();

            loc.x       = x;
            loc.y       = y;
            loc.z       = z;
            loc.blockID = blockID;
            if (this.blockLocations.ContainsKey(key))
            {
                this.blockLocations[key] = loc;
            }
            else
            {
                this.blockLocations.Add(key, loc);
            }
        }
Exemple #7
0
            private BlockLocation[] MockBlockLocations(long size, long splitSize)
            {
                int numLocations = (int)(size / splitSize);

                if (size % splitSize != 0)
                {
                    numLocations++;
                }
                BlockLocation[] blockLocations = new BlockLocation[numLocations];
                for (int i = 0; i < numLocations; i++)
                {
                    string[] names = new string[] { "b" + i };
                    string[] hosts = new string[] { "host" + i };
                    blockLocations[i] = new BlockLocation(names, hosts, i * splitSize, Math.Min(splitSize
                                                                                                , size - (splitSize * i)));
                }
                return(blockLocations);
            }
Exemple #8
0
        protected internal virtual int GetBlockIndex(BlockLocation[] blkLocations, long offset
                                                     )
        {
            for (int i = 0; i < blkLocations.Length; i++)
            {
                // is the offset inside this block?
                if ((blkLocations[i].GetOffset() <= offset) && (offset < blkLocations[i].GetOffset
                                                                    () + blkLocations[i].GetLength()))
                {
                    return(i);
                }
            }
            BlockLocation last       = blkLocations[blkLocations.Length - 1];
            long          fileLength = last.GetOffset() + last.GetLength() - 1;

            throw new ArgumentException("Offset " + offset + " is outside of file (0.." + fileLength
                                        + ")");
        }
Exemple #9
0
        public float AvoidInerSection_Up(float velocity, Vector3 CurPosition)
        {
            BlockLocation UpLoc;
            float         unitV = velocity - (int)velocity;

            for (float j = 0; j < velocity; ++j)
            {
                UpLoc = new BlockLocation(CurPosition + new Vector3(0, m_BodyHeight + unitV + j, 0), m_World);

                if (UpLoc.HasObstacle())
                {
                    m_Communicator.Publish(new E_Cha_Collision());
                    m_Communicator.Publish(new E_Cha_TouchUpsideBlock());

                    return
                        (UpLoc.Bound.min.y - CurPosition.y - m_BodyHeight);
                }
            }
            return(velocity);
        }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="blockId">The block id.</param>
        protected void ShowEdit(BlockLocation location, int blockId)
        {
            using (var rockContext = new RockContext())
            {
                BlockService     blockService = new BlockService(rockContext);
                Rock.Model.Block block        = blockService.Get(blockId);
                hfBlockLocation.Value = location.ConvertToString();

                if (block != null)
                {
                    lAction.Text               = "Edit ";
                    hfBlockId.Value            = block.Id.ToString();
                    ddlBlockType.SelectedValue = block.BlockType.Id.ToString();
                    tbBlockName.Text           = block.Name;
                }
                else
                {
                    lAction.Text    = "Add ";
                    hfBlockId.Value = "0";

                    // Select HTML Content block by default
                    var blockType = new Rock.Model.BlockTypeService(rockContext)
                                    .GetByGuid(new Guid(Rock.SystemGuid.BlockType.HTML_CONTENT));
                    if (blockType != null)
                    {
                        ddlBlockType.SelectedValue = blockType.Id.ToString();
                    }
                    else
                    {
                        ddlBlockType.SelectedIndex = -1;
                    }

                    tbBlockName.Text = string.Empty;
                }
            }

            lAction.Text += hfBlockLocation.Value;

            pnlLists.Visible   = false;
            pnlDetails.Visible = true;
        }
Exemple #11
0
        public float AvoidInerSection_Left(float velocity, Vector3 CurPosition)
        {
            BlockLocation LeftLoc;
            float         unitV = velocity - (int)velocity;

            for (float j = 0; j < -velocity; ++j)
            {
                for (int i = 0; i < m_BodyHeight; ++i)
                {
                    LeftLoc = new BlockLocation(CurPosition + new Vector3(-m_BodyWidth_Half + unitV - j, i, 0), m_World);

                    if (LeftLoc.HasObstacle())
                    {
                        m_Communicator.Publish(new E_Cha_Collision());
                        return
                            (LeftLoc.Bound.max.x - CurPosition.x + m_BodyWidth_Half);
                    }
                }
            }
            return(velocity);
        }
Exemple #12
0
        public float AvoidInerSection_Front(float velocity, Vector3 CurPosition)
        {
            BlockLocation FrontLoc;
            float         unitV = velocity - (int)velocity;

            for (float j = 0; j < velocity; ++j)
            {
                for (int i = 0; i < m_BodyHeight; ++i)
                {
                    FrontLoc = new BlockLocation(CurPosition + new Vector3(0, i, m_BodyWidth_Half + unitV + j), m_World);

                    if (FrontLoc.HasObstacle())
                    {
                        m_Communicator.Publish(new E_Cha_Collision());
                        return
                            (FrontLoc.Bound.min.z - CurPosition.z - m_BodyWidth_Half);
                    }
                }
            }
            return(velocity);
        }
        public static BlockFaceVisibility GetVisibleFaces(Block block)
        {
            BlockFaceVisibility visibility = new BlockFaceVisibility();
            Chunk         chunk            = block.Location.Chunk;
            BlockLocation location         = block.Location;

            Block left = chunk.GetBlockAt(location.X - 1, location.Y, location.Z);
            Block righ = chunk.GetBlockAt(location.X + 1, location.Y, location.Z);
            Block topp = chunk.GetBlockAt(location.X, location.Y + 1, location.Z);
            Block botm = chunk.GetBlockAt(location.X, location.Y - 1, location.Z);
            Block back = chunk.GetBlockAt(location.X, location.Y, location.Z - 1);
            Block frnt = chunk.GetBlockAt(location.X, location.Y, location.Z + 1);

            visibility.Left   = (left == null || left.IsEmpty() || left.IsTransparent);
            visibility.Right  = (righ == null || righ.IsEmpty() || righ.IsTransparent);
            visibility.Top    = (topp == null || topp.IsEmpty() || topp.IsTransparent);
            visibility.Bottom = (botm == null || botm.IsEmpty() || botm.IsTransparent);
            visibility.Back   = (back == null || back.IsEmpty() || back.IsTransparent);
            visibility.Front  = (frnt == null || frnt.IsEmpty() || frnt.IsTransparent);
            return(visibility);
        }
 public static void DrawChunkBBB(PlayerCamera camera, Chunk chunk)
 {
     foreach (Block block in chunk.Blocks.Values)
     {
         if (block.ShouldRender)
         {
             BlockLocation blockLocation = block.Location.GetWorldLocation(chunk.Location);
             if (!block.IsEmpty())
             {
                 //DebugDraw.DrawCube(camera, GridLatch.GetBlockWorldSpace(blockLocation), GridLatch.BlockScale);
                 //DebugDraw.DrawAABB(camera, block.BoundingBox);
                 DrawBlock(
                     block,
                     blockLocation.X,
                     blockLocation.Y,
                     blockLocation.Z,
                     camera);
             }
         }
     }
 }
Exemple #15
0
        private void _FigureOutPickPutLocation()
        {
            m_Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            _CheckIfPickIsValid();

            if (m_bIsPickValid)
            {
                if (_CheckRayHitSide(out Vector3Int HitSide))
                {
                    m_PutLoc = m_PickLoc.Offset_Blk(HitSide, m_World);

                    m_bIsPutValid = m_PutLoc.IsPutable(m_World) && !m_Player.IntersectWithBound(m_PickLoc.Bound);
                }
                else
                {
                    m_bIsPutValid = false;
                }
            }
            else
            {
                m_bIsPutValid = false;
            }
        }
        //---------------------------------------------------------------------

        public T this[int row,
                      int column]
        {
            get {
                int           index;
                BlockLocation desiredBlockLoc = GetBlockLocation(row,
                                                                 column,
                                                                 out index);
                if (desiredBlockLoc != currentBlockLoc)
                {
                    Gdal.CPLErr result = gdalBand.RasterIO(Gdal.RWFlag.Read,
                                                           column - 1,
                                                           row - 1,
                                                           BlockXSize,
                                                           BlockYSize,
                                                           buffer,
                                                           BlockXSize,
                                                           BlockYSize,
                                                           PixelType.GDALType,
                                                           0,                      // pixelSpace
                                                           0);                     // lineSpace
                    // Will the call above work for a partial block?  e.g.,
                    // raster's XSize does not divide evenly by BlockXSize
                    if (result != Gdal.CPLErr.None)
                    {
                        throw new System.ApplicationException();
                    }
                    //  TODO: define a Landis.Raster.Exception class
                    //  TODO: maybe create a function to create a
                    //		  Landis.Raster.Exception, and fills it in
                    //		  with info from CPLGetLastError[No|Type|Msg]
                    currentBlockLoc = desiredBlockLoc;
                }
                return(fromBytes(buffer, index));;
            }
        }
Exemple #17
0
 public bool IsEmpty(BlockLocation position)
 {
     return this._blocks[position].IsEmpty;
 }
Exemple #18
0
        private static void GetOp <T>(BlockLocation location, out T op) where T : unmanaged
        {
            ulong rawOp = location.Block.OpCodes[location.Index].RawOpCode;

            op = Unsafe.As <ulong, T>(ref rawOp);
        }
Exemple #19
0
        public void UploadSchematic(BlockWorld world, BlockLocation block1, BlockLocation block2)
        {
            int minX = Mathf.Min(block1.x, block2.x);
            int minY = Mathf.Min(block1.y, block2.y);
            int minZ = Mathf.Min(block1.z, block2.z);
            int maxX = Mathf.Min(block1.x, block2.x);
            int maxY = Mathf.Min(block1.y, block2.y);
            int maxZ = Mathf.Min(block1.z, block2.z);

            int minChunkX = minX >> 4;
            int minChunkY = minY >> 4;
            int minChunkZ = minZ >> 4;
            int maxChunkX = maxX >> 4;
            int maxChunkY = maxY >> 4;
            int maxChunkZ = maxZ >> 4;

            sizeX = maxX - minX + 1;
            sizeY = maxY - minY + 1;
            sizeZ = maxZ - minZ + 1;

            blocks = new ushort[sizeX * sizeY * sizeZ];

            Chunk chunk;
            int   a, b, c, x, y, z;
            int   minX2, minY2, minZ2;
            int   maxX2, maxY2, maxZ2;

            for (a = minChunkX; a <= maxChunkX; a++)
            {
                for (b = minChunkY; b <= maxChunkY; b++)
                {
                    for (c = minChunkZ; c <= maxChunkZ; c++)
                    {
                        chunk = world.GetChunkByCoords(a, b, c, false);
                        if (chunk == null)
                        {
                            continue;
                        }

                        minX2 = Mathf.Max(minX, chunk.chunkX * 16);
                        minY2 = Mathf.Max(minY, chunk.chunkY * 16);
                        minZ2 = Mathf.Max(minZ, chunk.chunkZ * 16);
                        maxX2 = Mathf.Min(maxX, chunk.chunkX * 16 + 15);
                        maxY2 = Mathf.Min(maxY, chunk.chunkY * 16 + 15);
                        maxZ2 = Mathf.Min(maxZ, chunk.chunkZ * 16 + 15);

                        for (x = minX2; x <= maxX2; x++)
                        {
                            for (y = minY2; y <= maxY2; y++)
                            {
                                for (z = minZ2; z <= maxZ2; z++)
                                {
                                    blocks[(x - minX) * sizeY * sizeZ + (y - minY) * sizeZ + (z - minZ)]
                                        = chunk.GetBlockId(x & 15, y & 15, z & 15);
                                }
                            }
                        }
                    }
                }
            }

            ArrayList materialList = new ArrayList();

            for (int i = 0; i < blocks.Length; i++)
            {
                if (blocks[i] == 0)
                {
                    continue;
                }

                if (!materialList.Contains(blocks[i]))
                {
                    materialList.Add(blocks[i]);
                }
                blocks[i] = (ushort)(materialList.IndexOf(blocks[i]) + 1);
            }

            materials = new Material[materialList.Count];
            for (int i = 0; i < materials.Length; i++)
            {
                materials[i] = materialList[i] as Material;
            }
        }
Exemple #20
0
        public void DownloadSchematic(BlockWorld world, BlockLocation minEdge)
        {
            if (blocks == null || materials == null || world == null)
            {
                return;
            }

            int minX = minEdge.x;
            int minY = minEdge.y;
            int minZ = minEdge.z;
            int maxX = minEdge.x + sizeX - 1;
            int maxY = minEdge.y + sizeY - 1;
            int maxZ = minEdge.z + sizeZ - 1;

            int minChunkX = minX >> 4;
            int minChunkY = minY >> 4;
            int minChunkZ = minZ >> 4;
            int maxChunkX = maxX >> 4;
            int maxChunkY = maxY >> 4;
            int maxChunkZ = maxZ >> 4;

            Chunk chunk;
            int   a, b, c, x, y, z;
            int   minX2, minY2, minZ2;
            int   maxX2, maxY2, maxZ2;
            int   index;

            for (a = minChunkX; a <= maxChunkX; a++)
            {
                for (b = minChunkY; b <= maxChunkY; b++)
                {
                    for (c = minChunkZ; c <= maxChunkZ; c++)
                    {
                        chunk = world.GetChunkByCoords(a, b, c, true);

                        minX2 = Mathf.Max(minX, chunk.chunkX * 16);
                        minY2 = Mathf.Max(minY, chunk.chunkY * 16);
                        minZ2 = Mathf.Max(minZ, chunk.chunkZ * 16);
                        maxX2 = Mathf.Min(maxX, chunk.chunkX * 16 + 15);
                        maxY2 = Mathf.Min(maxY, chunk.chunkY * 16 + 15);
                        maxZ2 = Mathf.Min(maxZ, chunk.chunkZ * 16 + 15);

                        for (x = minX2; x <= maxX2; x++)
                        {
                            for (y = minY2; y <= maxY2; y++)
                            {
                                for (z = minZ2; z <= maxZ2; z++)
                                {
                                    index = (x - minX) * sizeY * sizeZ + (y - minY) * sizeZ + (z - minZ);
                                    chunk.SetBlock(x & 15, y & 15, z & 15, blocks[index] == 0 ? null : materials[blocks[index] - 1]);
                                }
                            }
                        }
                    }
                }
            }

            if (world.autoRemesh)
            {
                world.UpdateAllChunks();
            }
        }
 public void SaveBlock(BlockLocation Location, byte blockId)
 {
     m_SaveHelper.Modify(Location, blockId, m_WorldMng.WorldServ);
 }
Exemple #22
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            Rock.Model.Block block;

            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);

            int blockId = hfBlockId.ValueAsInt();

            if (blockId == 0)
            {
                block = new Rock.Model.Block();

                BlockLocation location = hfBlockLocation.Value.ConvertToEnum <BlockLocation>();
                if (location == BlockLocation.Layout)
                {
                    block.LayoutId = page.LayoutId;
                    block.PageId   = null;
                }
                else
                {
                    block.LayoutId = null;
                    block.PageId   = page.Id;
                }

                block.Zone = zoneName;

                Rock.Model.Block lastBlock = blockService.GetByPageAndZone(page.Id, zoneName).OrderByDescending(b => b.Order).FirstOrDefault();

                if (lastBlock != null)
                {
                    block.Order = lastBlock.Order + 1;
                }
                else
                {
                    block.Order = 0;
                }

                blockService.Add(block);
            }
            else
            {
                block = blockService.Get(blockId);
            }

            block.Name        = tbBlockName.Text;
            block.BlockTypeId = Convert.ToInt32(ddlBlockType.SelectedValue);

            rockContext.SaveChanges();

            Rock.Security.Authorization.CopyAuthorization(page, block);

            if (block.Layout != null)
            {
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.LayoutId);
            }
            else
            {
                page.FlushBlocks();
            }

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }
Exemple #23
0
 /// <exception cref="System.IO.IOException"/>
 internal OneFileInfo(FileStatus stat, Configuration conf, bool isSplitable, Dictionary
                      <string, IList <CombineFileInputFormat.OneBlockInfo> > rackToBlocks, Dictionary <CombineFileInputFormat.OneBlockInfo
                                                                                                       , string[]> blockToNodes, Dictionary <string, ICollection <CombineFileInputFormat.OneBlockInfo
                                                                                                                                                                  > > nodeToBlocks, Dictionary <string, ICollection <string> > rackToNodes, long maxSize
                      )
 {
     // size of the file
     // all blocks in this file
     this.fileSize = 0;
     // get block locations from file system
     BlockLocation[] locations;
     if (stat is LocatedFileStatus)
     {
         locations = ((LocatedFileStatus)stat).GetBlockLocations();
     }
     else
     {
         FileSystem fs = stat.GetPath().GetFileSystem(conf);
         locations = fs.GetFileBlockLocations(stat, 0, stat.GetLen());
     }
     // create a list of all block and their locations
     if (locations == null)
     {
         blocks = new CombineFileInputFormat.OneBlockInfo[0];
     }
     else
     {
         if (locations.Length == 0 && !stat.IsDirectory())
         {
             locations = new BlockLocation[] { new BlockLocation() };
         }
         if (!isSplitable)
         {
             // if the file is not splitable, just create the one block with
             // full file length
             blocks    = new CombineFileInputFormat.OneBlockInfo[1];
             fileSize  = stat.GetLen();
             blocks[0] = new CombineFileInputFormat.OneBlockInfo(stat.GetPath(), 0, fileSize,
                                                                 locations[0].GetHosts(), locations[0].GetTopologyPaths());
         }
         else
         {
             AList <CombineFileInputFormat.OneBlockInfo> blocksList = new AList <CombineFileInputFormat.OneBlockInfo
                                                                                 >(locations.Length);
             for (int i = 0; i < locations.Length; i++)
             {
                 fileSize += locations[i].GetLength();
                 // each split can be a maximum of maxSize
                 long left     = locations[i].GetLength();
                 long myOffset = locations[i].GetOffset();
                 long myLength = 0;
                 do
                 {
                     if (maxSize == 0)
                     {
                         myLength = left;
                     }
                     else
                     {
                         if (left > maxSize && left < 2 * maxSize)
                         {
                             // if remainder is between max and 2*max - then
                             // instead of creating splits of size max, left-max we
                             // create splits of size left/2 and left/2. This is
                             // a heuristic to avoid creating really really small
                             // splits.
                             myLength = left / 2;
                         }
                         else
                         {
                             myLength = Math.Min(maxSize, left);
                         }
                     }
                     CombineFileInputFormat.OneBlockInfo oneblock = new CombineFileInputFormat.OneBlockInfo
                                                                        (stat.GetPath(), myOffset, myLength, locations[i].GetHosts(), locations[i].GetTopologyPaths
                                                                            ());
                     left     -= myLength;
                     myOffset += myLength;
                     blocksList.AddItem(oneblock);
                 }while (left > 0);
             }
             blocks = Sharpen.Collections.ToArray(blocksList, new CombineFileInputFormat.OneBlockInfo
                                                  [blocksList.Count]);
         }
         PopulateBlockInfo(blocks, rackToBlocks, blockToNodes, nodeToBlocks, rackToNodes);
     }
 }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool newBlock = false;

            Rock.Model.Block block = null;

            using (var rockContext = new RockContext())
            {
                BlockService blockService = new BlockService(rockContext);

                int blockId = hfBlockId.ValueAsInt();

                if (blockId != 0)
                {
                    block = blockService.Get(blockId);
                }

                if (block == null)
                {
                    newBlock = true;
                    block    = new Rock.Model.Block();
                    blockService.Add(block);

                    BlockLocation location = hfBlockLocation.Value.ConvertToEnum <BlockLocation>();
                    switch (location)
                    {
                    case BlockLocation.Site:
                        block.LayoutId = null;
                        block.PageId   = null;
                        block.SiteId   = _Page.SiteId;
                        break;

                    case BlockLocation.Layout:
                        block.LayoutId = _Page.LayoutId;
                        block.PageId   = null;
                        block.SiteId   = null;
                        break;

                    case BlockLocation.Page:
                        block.LayoutId = null;
                        block.PageId   = _Page.Id;
                        block.SiteId   = null;
                        break;
                    }


                    block.Zone = _ZoneName;

                    Rock.Model.Block lastBlock = blockService.GetByPageAndZone(_Page.Id, _ZoneName).OrderByDescending(b => b.Order).FirstOrDefault();
                    var maxOrder = blockService.GetMaxOrder(block);

                    if (lastBlock != null)
                    {
                        block.Order = lastBlock.Order + 1;
                    }
                    else
                    {
                        block.Order = 0;
                    }
                }

                block.Name        = tbBlockName.Text;
                block.BlockTypeId = Convert.ToInt32(ddlBlockType.SelectedValue);

                rockContext.SaveChanges();

                if (newBlock)
                {
                    Rock.Security.Authorization.CopyAuthorization(_Page, block, rockContext);
                }

                if (block.Layout != null)
                {
                    Rock.Web.Cache.PageCache.FlushLayoutBlocks(_Page.LayoutId);
                }
                else
                {
                    _Page.FlushBlocks();
                }
            }

            PageUpdated = true;

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }
Exemple #25
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="blockId">The block id.</param>
        protected void ShowEdit( BlockLocation location, int blockId )
        {
            using ( var rockContext = new RockContext() )
            {
                BlockService blockService = new BlockService( rockContext );
                Rock.Model.Block block = blockService.Get( blockId );
                hfBlockLocation.Value = location.ConvertToString();

                if ( block != null )
                {
                    lAction.Text = "Edit ";
                    hfBlockId.Value = block.Id.ToString();
                    ddlBlockType.SelectedValue = block.BlockType.Id.ToString();
                    tbBlockName.Text = block.Name;
                }
                else
                {
                    lAction.Text = "Add ";
                    hfBlockId.Value = "0";

                    // Select HTML Content block by default
                    var blockType = new Rock.Model.BlockTypeService( rockContext )
                        .GetByGuid( new Guid( Rock.SystemGuid.BlockType.HTML_CONTENT ) );
                    if ( blockType != null )
                    {
                        ddlBlockType.SelectedValue = blockType.Id.ToString();
                    }
                    else
                    {
                        ddlBlockType.SelectedIndex = -1;
                    }

                    tbBlockName.Text = string.Empty;
                }
            }

            lAction.Text += hfBlockLocation.Value;

            pnlLists.Visible = false;
            pnlDetails.Visible = true;
        }
Exemple #26
0
 //Constructor
 public Com_ModifyBlock(ref BlockLocation blkloc, byte blkID)
 {
     m_BlkLoc     = blkloc;
     m_ToModifyID = blkID;
     m_PreBlkID   = m_BlkLoc.CurBlockID;
 }
Exemple #27
0
    public void Read(TProtocol iprot)
    {
        iprot.IncrementRecursionDepth();
        try
        {
            TField field;
            iprot.ReadStructBegin();
            while (true)
            {
                field = iprot.ReadFieldBegin();
                if (field.Type == TType.Stop)
                {
                    break;
                }
                switch (field.ID)
                {
                case 1:
                    if (field.Type == TType.I64)
                    {
                        BlockId = iprot.ReadI64();
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 2:
                    if (field.Type == TType.I64)
                    {
                        Length = iprot.ReadI64();
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 3:
                    if (field.Type == TType.List)
                    {
                        {
                            Locations = new List <BlockLocation>();
                            TList _list0 = iprot.ReadListBegin();
                            for (int _i1 = 0; _i1 < _list0.Count; ++_i1)
                            {
                                BlockLocation _elem2;
                                _elem2 = new BlockLocation();
                                _elem2.Read(iprot);
                                Locations.Add(_elem2);
                            }
                            iprot.ReadListEnd();
                        }
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                default:
                    TProtocolUtil.Skip(iprot, field.Type);
                    break;
                }
                iprot.ReadFieldEnd();
            }
            iprot.ReadStructEnd();
        }
        finally
        {
            iprot.DecrementRecursionDepth();
        }
    }
Exemple #28
0
 public bool CanPlaceBlock(Material oldBlock, BlockLocation loc)
 {
     return(loc.x == block1.x || loc.x == block2.x ||
            loc.z == block1.z || loc.z == block2.z);
 }
Exemple #29
0
 public Block(BlockLocation location)
 {
     this.Location = location;
     this.IsEmpty = true;
 }
Exemple #30
0
 public Block(BlockLocation location, BlockColor color)
 {
     this.Location = location;
     this.Color = color;
     this.IsEmpty = false;
 }
Exemple #31
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Rock.Model.Block block;

            int blockId = 0;

            if (!Int32.TryParse(hfBlockId.Value, out blockId))
            {
                blockId = 0;
            }

            if (blockId == 0)
            {
                block = new Rock.Model.Block();

                BlockLocation location = hfBlockLocation.Value.ConvertToEnum <BlockLocation>();
                if (location == BlockLocation.Layout)
                {
                    block.Layout = _page.Layout;
                    block.PageId = null;
                }
                else
                {
                    block.Layout = null;
                    block.PageId = _page.Id;
                }

                block.Zone = _zoneName;

                Rock.Model.Block lastBlock =
                    blockService.GetByLayoutAndPageIdAndZone(null, _page.Id, _zoneName).
                    OrderByDescending(b => b.Order).FirstOrDefault();

                if (lastBlock != null)
                {
                    block.Order = lastBlock.Order + 1;
                }
                else
                {
                    block.Order = 0;
                }

                blockService.Add(block, CurrentPersonId);
            }
            else
            {
                block = blockService.Get(blockId);
            }

            block.Name        = tbBlockName.Text;
            block.BlockTypeId = Convert.ToInt32(ddlBlockType.SelectedValue);

            blockService.Save(block, CurrentPersonId);

            Rock.Security.Authorization.CopyAuthorization(_page, block, CurrentPersonId);

            if (block.Layout != null)
            {
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(_page.Layout);
            }
            else
            {
                _page.FlushBlocks();
            }

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }
Exemple #32
0
 public static Vector3 WTMGetWorldBlock(ChunkLocation chunk, BlockLocation location)
 {
     return(WTMGetChunk(chunk) + WTMGetBlock(location) - ChunkScale);
 }
Exemple #33
0
 public void InitalizeFilter(BlockLocation block1, BlockLocation block2, Material newBlock)
 {
     this.block1 = block1;
     this.block2 = block2;
 }
Exemple #34
0
 static GridLatch()
 {
     TempB = new BlockLocation(0, 0, 0);
     TempC = new ChunkLocation(0, 0);
 }