Exemple #1
0
        public override void Save(SampleBlock block, IBlockEntity entity)
        {
            // By default 'BlockHandlerBase<TBlock>' stores block instance data as JSON in the 'Model' field of the 'PageStoryBlock' table.
            // You can, however, store data anywhere you like and override persistance behaviour in this method.

            base.Save(block, entity);
        }
Exemple #2
0
        public virtual void Save(T block, IBlockEntity entity)
        {
            Guard.NotNull(entity, nameof(entity));

            if (block == null)
            {
                return;
            }

            var settings = new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.Objects,
                ReferenceLoopHandling  = ReferenceLoopHandling.Ignore,
                ObjectCreationHandling = ObjectCreationHandling.Replace,
                NullValueHandling      = NullValueHandling.Ignore
            };

            entity.Model = JsonConvert.SerializeObject(block, Formatting.None, settings);

            // save BindEntintyName & BindEntintyId
            if (block is IBindableBlock bindableBlock)
            {
                entity.BindEntityId   = bindableBlock.BindEntityId;
                entity.BindEntityName = bindableBlock.BindEntityName;
            }
        }
        public Task SetEntity(IBlockEntity furnaceEntity)
        {
            SlotAreas.Clear();
            _properties.Clear();

            SlotAreas.Add(new FurnaceSlotArea(furnaceEntity, this, GrainFactory));
            SlotAreas.Add(new InventorySlotArea(this, GrainFactory));
            SlotAreas.Add(new HotbarSlotArea(this, GrainFactory));
            _furnaceEntity = furnaceEntity;
            return(Task.CompletedTask);
        }
Exemple #4
0
        private async Task <IBlockEntity> FindMasterEntity(IBlockEntity neighborEntity)
        {
            if (NeighborEntity == null)
            {
                return(AttachedObject.AsReference <IBlockEntity>());
            }

            async Task <(IBlockEntity entity, BlockWorldPos position)> GetPosition(IBlockEntity entity) =>
            (entity, await entity.GetPosition());

            // 按 X, Z 排序取最小
            return((from e in await Task.WhenAll(new[] { GetPosition(AttachedObject.AsReference <IBlockEntity>()), GetPosition(NeighborEntity) })
                    orderby e.position.X, e.position.Z
                    select e.entity).First());
        }
Exemple #5
0
        public virtual T Load(IBlockEntity entity, StoryViewMode viewMode)
        {
            Guard.NotNull(entity, nameof(entity));

            var block = Create(entity);
            var json  = entity.Model;

            if (json.IsEmpty())
            {
                return(block);
            }

            JsonConvert.PopulateObject(json, block);

            if (block is IBindableBlock bindableBlock)
            {
                bindableBlock.BindEntityName = entity.BindEntityName;
                bindableBlock.BindEntityId   = entity.BindEntityId;
            }

            return(block);
        }
Exemple #6
0
        internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, ref string fileName, string blockName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            fileName = DSGeometryExtension.LocateFile(fileName);
            if (!File.Exists(fileName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, fileName), "fileName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            IBlockEntity entity = helper.InsertBlockFromFile(contextCoordinateSystem.CSEntity, fileName, blockName);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
Exemple #7
0
        public override SampleBlock Load(IBlockEntity entity, StoryViewMode viewMode)
        {
            var block = base.Load(entity, viewMode);

            // By default 'BlockHandlerBase<TBlock>' stores block instance data as JSON in the 'Model' field of the 'PageStoryBlock' table.
            // You can, however, store data anywhere you like and override loading behaviour in this method.

            if (viewMode == StoryViewMode.Edit)
            {
                // You can prepare your model especially for the edit mode of the block,
                // e.g. add some SelectListItems for dropdownmenus which you will only need in the edit mode of the block
                block.MyProperties.Add(new SelectListItem {
                    Text = "Item1", Value = "1"
                });
            }
            else if (viewMode == StoryViewMode.GridEdit)
            {
                // Manipulate properties especially for the grid edit mode e.g. turn of any animation which could distract the user from editing the grid.
                //block.Autoplay = false;
            }

            return(block);
        }
Exemple #8
0
        internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, string blockName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            if (!helper.BlockExistsInCurrentDocument(blockName))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.DoesNotExist, "DSBlock : " + blockName));
            }

            IBlockEntity entity = helper.InsertBlockFromCurrentDocument(contextCoordinateSystem.CSEntity, blockName);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
Exemple #9
0
 protected virtual void AppendBlock(T entity, IBlockEntity block)
 {
 }
Exemple #10
0
 private DSBlockInstance(IBlockEntity entity, bool persist = false)
     : base(entity, persist)
 {
     InitializeGuaranteedProperties();
 }
Exemple #11
0
 public virtual void AfterSave(IBlockContainer container, IBlockEntity entity)
 {
     // Default impl does nothing.
 }
 protected override void AppendBlock(Category entity, IBlockEntity block)
 {
     entity.Blocks.Add((CategoryBlock)block);
     base.AppendBlock(entity, block);
 }
 protected override void RemoveBlock(Category entity, IBlockEntity block)
 {
     entity.Blocks.Remove((CategoryBlock)block);
     DataModelContext.Set <CategoryBlock>().Remove((CategoryBlock)block);
     base.RemoveBlock(entity, block);
 }
 public FurnaceSlotArea(IBlockEntity furnaceEntity, WindowGrain window, IGrainFactory grainFactory)
     : base(FurnaceSlotsCount, window, grainFactory)
 {
     _furnaceEntity = furnaceEntity;
 }
Exemple #15
0
 public virtual string Clone(IBlockEntity sourceEntity, IBlockEntity clonedEntity)
 {
     return(sourceEntity.Model);
 }
Exemple #16
0
 protected override void AppendBlock(Location entity, IBlockEntity block)
 {
     entity.Blocks.Add((LocationBlock)block);
     base.AppendBlock(entity, block);
 }
Exemple #17
0
 public virtual T Create(IBlockEntity entity)
 {
     return(Activator.CreateInstance <T>());
 }
Exemple #18
0
 protected virtual void RemoveBlock(T entity, IBlockEntity block)
 {
 }
Exemple #19
0
 private BlockInstance(IBlockEntity entity, bool persist = false)
     : base(entity, persist)
 {
     InitializeGuaranteedProperties();
 }
Exemple #20
0
 protected override void RemoveBlock(Location entity, IBlockEntity block)
 {
     entity.Blocks.Remove((LocationBlock)block);
     DataModelContext.Set <LocationBlock>().Remove((LocationBlock)block);
     base.RemoveBlock(entity, block);
 }