/// <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; }
/// <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); }
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); }
/// <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);