diff --git a/MLEM.Data/DataTextureAtlas.cs b/MLEM.Data/DataTextureAtlas.cs
index 775bd72..38799b7 100644
--- a/MLEM.Data/DataTextureAtlas.cs
+++ b/MLEM.Data/DataTextureAtlas.cs
@@ -19,7 +19,7 @@ namespace MLEM.Data {
///
/// The texture to use for this atlas
///
- public readonly Texture2D Texture;
+ public readonly TextureRegion Texture;
///
/// Returns the texture region with the given name, or null if it does not exist.
///
@@ -37,21 +37,23 @@ namespace MLEM.Data {
private readonly Dictionary regions = new Dictionary();
- ///
- /// Creates a new data texture atlas with the given texture and region amount.
- ///
- /// The texture to use for this atlas
- public DataTextureAtlas(Texture2D texture) {
+ private DataTextureAtlas(TextureRegion texture) {
this.Texture = texture;
}
- internal static DataTextureAtlas Load(ContentManager content, string texturePath, string infoPath, bool pivotRelative) {
- var info = new FileInfo(Path.Combine(content.RootDirectory, infoPath ?? $"{texturePath}.atlas"));
+ ///
+ /// Loads a from the given loaded texture and texture data file.
+ ///
+ /// The texture to use for this data texture atlas
+ /// The content manager to use for loading
+ /// The path, including extension, to the atlas info file
+ /// If this value is true, then the pivot points passed in the info file will be relative to the coordinates of the texture region, not relative to the entire texture's origin.
+ /// A new data texture atlas with the given settings
+ public static DataTextureAtlas LoadAtlasData(TextureRegion texture, ContentManager content, string infoPath, bool pivotRelative = false) {
+ var info = new FileInfo(Path.Combine(content.RootDirectory, infoPath));
string text;
using (var reader = info.OpenText())
text = reader.ReadToEnd();
-
- var texture = content.Load(texturePath);
var atlas = new DataTextureAtlas(texture);
// parse each texture region: " loc piv "
@@ -59,7 +61,7 @@ namespace MLEM.Data {
foreach (Match match in Regex.Matches(text, regex)) {
var name = match.Groups[1].Value.Trim();
var loc = new Rectangle(
- int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value),
+ int.Parse(match.Groups[2].Value) + texture.U, int.Parse(match.Groups[3].Value) + texture.V,
int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value));
var piv = Vector2.Zero;
if (match.Groups[6].Success) {
@@ -92,7 +94,8 @@ namespace MLEM.Data {
/// If this value is true, then the pivot points passed in the info file will be relative to the coordinates of the texture region, not relative to the entire texture's origin.
/// A new data texture atlas with the given settings
public static DataTextureAtlas LoadTextureAtlas(this ContentManager content, string texturePath, string infoPath = null, bool pivotRelative = false) {
- return DataTextureAtlas.Load(content, texturePath, infoPath, pivotRelative);
+ var texture = new TextureRegion(content.Load(texturePath));
+ return DataTextureAtlas.LoadAtlasData(texture, content, infoPath ?? $"{texturePath}.atlas", pivotRelative);
}
}