Ejemplo n.º 1
0
        /// <summary>
        /// Clears current loaded dimension.
        /// </summary>
        /// <param name="synchronizePrevious">Should be the previous dimension synchronized with changing in the world.</param>
        public void ClearDimension(bool synchronizePrevious = true)
        {
            if (synchronizePrevious)
            {
                SynchronizeDimension();
            }

            DimensionHelpers.ClearDimension(CurrentEntity);

            CurrentEntity = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load (inject) dimension into the world. Set the <see cref="LocationToLoad"/> to specify loading position.
        /// </summary>
        /// <param name="type">The type of the dimension.</param>
        /// <param name="id">The identifier for the dimension. By default will be equals to the type.</param>
        /// <param name="synchronizePrevious">Should be the previous dimension synchronized with changing in the world.</param>
        public void LoadDimension(string type, string id = default, bool synchronizePrevious = true)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            ClearDimension(synchronizePrevious);

            CurrentEntity          = DimensionRegister.Instance.GetStorage(type).LoadInternal(id);
            CurrentEntity.Location = new Point(LocationToLoad.X, LocationToLoad.Y - CurrentEntity.Height);

            DimensionHelpers.LoadDimension(CurrentEntity);
        }
Ejemplo n.º 3
0
        public override TagCompound Serialize(SingleEntryDimension entry)
        {
            if (!DimensionHelpers.ValidateDimension(entry.CurrentEntity))
            {
                return(null);
            }

            var tag = new TagCompound
            {
                { nameof(entry.EntryName), entry.EntryName },
                { nameof(entry.LocationToLoad), entry.LocationToLoad }
            };

            if (TryGetSerializer(typeof(DimensionEntity), out var serializer))
            {
                tag.Add(nameof(entry.CurrentEntity), serializer.Serialize(entry.CurrentEntity));
            }

            return(tag);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Synchronizes current loaded dimension.
 /// Directly call is might be useful for very specific cases, usually <see cref = "LoadDimension" /> is sufficient.
 /// </summary>
 public void SynchronizeDimension()
 {
     DimensionHelpers.SynchronizeDimension(CurrentEntity);
 }
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 => DimensionHelpers.GetDimensionOrDefault((string)value);