Commits

Nick Gravelyn  committed d15733b

Adding argument for texture root directory onto the helpers.

  • Participants
  • Parent commits d8f4018

Comments (0)

Files changed (1)

File TiledLib/TiledLib/TiledHelpers.cs

         /// load the resulting map and not have to also load up textures. The external reference is stored on the
         /// TileSet's Texture field so make sure you serialize that if you call this method.
         /// </summary>
-        public static void BuildTileSetTextures(MapContent input, ContentProcessorContext context)
+        public static void BuildTileSetTextures(MapContent input, ContentProcessorContext context, string textureRoot = "")
         {
             foreach (var tileSet in input.TileSets)
             {
+                // get the real path to the image
+                string path = Path.Combine(textureRoot, tileSet.Image);
+
                 // the asset name is the entire path, minus extension, after the content directory
                 string asset = string.Empty;
-                if (tileSet.Image.StartsWith(Directory.GetCurrentDirectory()))
-                    asset = tileSet.Image.Remove(tileSet.Image.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
+                if (path.StartsWith(Directory.GetCurrentDirectory()))
+                    asset = path.Remove(tileSet.Image.LastIndexOf('.')).Substring(Directory.GetCurrentDirectory().Length + 1);
                 else
-                    asset = Path.GetFileNameWithoutExtension(tileSet.Image);
+                    asset = Path.GetFileNameWithoutExtension(path);
 
                 // build the asset as an external reference
                 OpaqueDataDictionary data = new OpaqueDataDictionary();
                 data.Add("ColorKeyEnabled", tileSet.ColorKey.HasValue);
                 data.Add("ColorKeyColor", tileSet.ColorKey.HasValue ? tileSet.ColorKey.Value : Microsoft.Xna.Framework.Color.Magenta);
                 tileSet.Texture = context.BuildAsset<TextureContent, TextureContent>(
-                    new ExternalReference<TextureContent>(tileSet.Image),
+                    new ExternalReference<TextureContent>(path),
                     "TextureProcessor",
                     data,
                     "TextureImporter",
         /// Additionally reads in the property information for the tiles and stores them alongside the source rectangles
         /// in a Tile object stored in the TileSet's Tiles list.
         /// </summary>
-        public static void GenerateTileSourceRectangles(MapContent input)
+        public static void GenerateTileSourceRectangles(MapContent input, string textureRoot = "")
         {
             // do some processing on tile sets to load external textures and figure out tile regions
             foreach (var tileSet in input.TileSets)
             {
+                // get the real path to the image
+                string path = Path.Combine(textureRoot, tileSet.Image);
+
                 // load the image so we can compute the individual tile source rectangles
                 int imageWidth = 0;
                 int imageHeight = 0;
-                using (Image image = Image.FromFile(tileSet.Image))
+                using (Image image = Image.FromFile(path))
                 {
                     imageWidth = image.Width;
                     imageHeight = image.Height;