Skip to content

Commit

Permalink
Merge pull request #746 from merthsoft/develop
Browse files Browse the repository at this point in the history
Resolve relative path of texture in TextureAtlasJsonConverter
  • Loading branch information
lithiumtoast authored Sep 10, 2021
2 parents 2009adb + 214e960 commit 1d8ea44
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

// TODO: When we get to .NET Standard 2.1 it would be more robust to use
// [Path.GetRelativePath](https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath?view=netstandard-2.1)
var textureName = Path.GetFileNameWithoutExtension(metadata.Texture);
var textureDirectory = Path.GetDirectoryName(metadata.Texture);
var directory = Path.GetDirectoryName(_path);
var relativeAssetName = Path.Combine(directory, metadata.Texture);
var assetName = Path.Combine(directory, Path.GetFileNameWithoutExtension(relativeAssetName));
var texture = _contentManager.Load<Texture2D>(assetName);
var relativePath = Path.Combine(_contentManager.RootDirectory, directory, textureDirectory, textureName);
var resolvedAssetName = Path.GetFullPath(relativePath);
var texture = _contentManager.Load<Texture2D>(resolvedAssetName);

return TextureAtlas.Create(assetName, texture, metadata.RegionWidth, metadata.RegionHeight);
return TextureAtlas.Create(resolvedAssetName, texture, metadata.RegionWidth, metadata.RegionHeight);
}
}

Expand All @@ -68,4 +70,4 @@ public override bool CanConvert(Type objectType)
return objectType == typeof(TextureAtlas);
}
}
}
}

0 comments on commit 1d8ea44

Please sign in to comment.