mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Added a generic version of IGenericDataHolder.SetData
This commit is contained in:
parent
e5cfebef3b
commit
d72b094a7a
3 changed files with 28 additions and 5 deletions
|
@ -30,6 +30,7 @@ Improvements
|
||||||
- Allow specifying percentage-based padding for a NinePatch
|
- Allow specifying percentage-based padding for a NinePatch
|
||||||
- Improved the way InputHandler down time calculation works
|
- Improved the way InputHandler down time calculation works
|
||||||
- Allow explicitly specifying each region for extended auto tiles
|
- Allow explicitly specifying each region for extended auto tiles
|
||||||
|
- Added a generic version of IGenericDataHolder.SetData
|
||||||
- **Drastically improved StaticSpriteBatch batching performance**
|
- **Drastically improved StaticSpriteBatch batching performance**
|
||||||
- **Made GenericFont and TokenizedString support UTF-32 characters like emoji**
|
- **Made GenericFont and TokenizedString support UTF-32 characters like emoji**
|
||||||
|
|
||||||
|
@ -87,7 +88,6 @@ Improvements
|
||||||
- Added trimming and AOT annotations and made MLEM.Data trimmable
|
- Added trimming and AOT annotations and made MLEM.Data trimmable
|
||||||
- Store a RuntimeTexturePacker packed texture region's source region
|
- Store a RuntimeTexturePacker packed texture region's source region
|
||||||
- Use JSON.NET attributes in favor of DataContract and DataMember
|
- Use JSON.NET attributes in favor of DataContract and DataMember
|
||||||
- Allow adding JsonTypeSafeWrapper instances to JsonTypeSafeGenericDataHolder directly
|
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed data texture atlases not allowing most characters in their region names
|
- Fixed data texture atlases not allowing most characters in their region names
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
@ -19,14 +20,21 @@ namespace MLEM.Data.Json {
|
||||||
private Dictionary<string, JsonTypeSafeWrapper> data;
|
private Dictionary<string, JsonTypeSafeWrapper> data;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[Obsolete("This method will be removed in a future update in favor of the generic SetData<T>.")]
|
||||||
public void SetData(string key, object data) {
|
public void SetData(string key, object data) {
|
||||||
if (data == default) {
|
this.SetData<object>(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void SetData<T>(string key, T data) {
|
||||||
|
if (EqualityComparer<T>.Default.Equals(data, default)) {
|
||||||
if (this.data != null)
|
if (this.data != null)
|
||||||
this.data.Remove(key);
|
this.data.Remove(key);
|
||||||
} else {
|
} else {
|
||||||
if (this.data == null)
|
if (this.data == null)
|
||||||
this.data = new Dictionary<string, JsonTypeSafeWrapper>();
|
this.data = new Dictionary<string, JsonTypeSafeWrapper>();
|
||||||
this.data[key] = data as JsonTypeSafeWrapper ?? JsonTypeSafeWrapper.Of(data);
|
// if types already match exactly, we don't need to use Of (which requires dynamic code)
|
||||||
|
this.data[key] = data.GetType() == typeof(T) ? new JsonTypeSafeWrapper<T>(data) : JsonTypeSafeWrapper.Of(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MLEM.Misc {
|
namespace MLEM.Misc {
|
||||||
|
@ -12,8 +13,14 @@ namespace MLEM.Misc {
|
||||||
private Dictionary<string, object> data;
|
private Dictionary<string, object> data;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[Obsolete("This method will be removed in a future update in favor of the generic SetData<T>.")]
|
||||||
public void SetData(string key, object data) {
|
public void SetData(string key, object data) {
|
||||||
if (data == default) {
|
this.SetData<object>(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void SetData<T>(string key, T data) {
|
||||||
|
if (EqualityComparer<T>.Default.Equals(data, default)) {
|
||||||
if (this.data != null)
|
if (this.data != null)
|
||||||
this.data.Remove(key);
|
this.data.Remove(key);
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,8 +57,16 @@ namespace MLEM.Misc {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The key to store the data by</param>
|
/// <param name="key">The key to store the data by</param>
|
||||||
/// <param name="data">The data to store in the object</param>
|
/// <param name="data">The data to store in the object</param>
|
||||||
|
[Obsolete("This method will be removed in a future update in favor of the generic SetData<T>.")]
|
||||||
void SetData(string key, object data);
|
void SetData(string key, object data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Store a piece of generic data on this object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key to store the data by</param>
|
||||||
|
/// <param name="data">The data to store in the object</param>
|
||||||
|
void SetData<T>(string key, T data);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a piece of generic data of the given type on this object.
|
/// Returns a piece of generic data of the given type on this object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in a new issue