1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-10-31 21:00:51 +01:00

added the ability to convert texture atlases to collections

This commit is contained in:
Ell 2022-11-23 12:14:08 +01:00
parent 92353e40e6
commit 9919ee4a97
3 changed files with 37 additions and 0 deletions

View file

@ -17,6 +17,7 @@ Additions
- Added GetFlags and GetUniqueFlags to EnumHelper
- Added GetDownTime, GetUpTime, GetTimeSincePress, WasModifierDown and WasDown to Keybind and Combination
- Added the ability for UniformTextureAtlases to have padding for each region
- Added UniformTextureAtlas methods ToList and ToDictionary
- **Added the ability to find paths to one of multiple goals using AStar**
Improvements
@ -73,6 +74,7 @@ Additions
- Added data, from, and copy instructions to DataTextureAtlas
- Added the ability to add additional regions to a RuntimeTexturePacker after packing
- Added GetFlags, GetUniqueFlags and IsDefined to DynamicEnum
- Added DataTextureAtlas.ToDictionary
Improvements
- Allow data texture atlas pivots and offsets to be negative

View file

@ -72,6 +72,15 @@ namespace MLEM.Data {
this.Texture = texture;
}
/// <summary>
/// Converts this data texture atlas to a <see cref="Dictionary{TKey,TValue}"/> and returns the result.
/// The resulting dictionary will contain all named regions that this data texture atlas contains.
/// </summary>
/// <returns>The dictionary representation of this data texture atlas.</returns>
public Dictionary<string, TextureRegion> ToDictionary() {
return new Dictionary<string, TextureRegion>(this.regions);
}
/// <summary>
/// Loads a <see cref="DataTextureAtlas"/> from the given loaded texture and texture data file.
/// For more information on data texture atlases, see the <see cref="DataTextureAtlas"/> type documentation.

View file

@ -94,6 +94,32 @@ namespace MLEM.Textures {
public UniformTextureAtlas(Texture2D texture, int regionAmountX, int regionAmountY, int regionPadding = 0) :
this(new TextureRegion(texture), regionAmountX, regionAmountY, regionPadding) {}
/// <summary>
/// Converts this uniform texture atlas to a <see cref="List{T}"/> and returns the result.
/// The resulting list will contain all square 1x1 regions that this uniform texture atlas contains, based on <see cref="RegionAmountX"/> and <see cref="RegionAmountY"/>, with each index containing the <see cref="TextureRegion"/> at <see cref="this[int]"/>.
/// </summary>
/// <returns>The list representation of this uniform texture atlas.</returns>
public List<TextureRegion> ToList() {
var ret = new List<TextureRegion>();
for (var i = 0; i < this.RegionAmountX * this.RegionAmountY; i++)
ret.Add(this[i]);
return ret;
}
/// <summary>
/// Converts this uniform texture atlas to a <see cref="Dictionary{TKey,TValue}"/> and returns the result.
/// The resulting dictionary will contain all square 1x1 regions that this uniform texture atlas contains, based on <see cref="RegionAmountX"/> and <see cref="RegionAmountY"/>, wich each key containing the <see cref="TextureRegion"/> at <see cref="this[Point]"/>.
/// </summary>
/// <returns>The dictionary representation of this uniform texture atlas.</returns>
public Dictionary<Point, TextureRegion> ToDictionary() {
var ret = new Dictionary<Point, TextureRegion>();
for (var x = 0; x < this.RegionAmountX; x++) {
for (var y = 0; y < this.RegionAmountY; y++)
ret.Add(new Point(x, y), this[x, y]);
}
return ret;
}
private TextureRegion GetOrAddRegion(Rectangle rect) {
if (this.regions.TryGetValue(rect, out var region))
return region;