Exemple #1
0
        IEnumerable <ITextureFile <TTile> > ReadInclude(XElement includeDirective,
                                                        TexturePackLoaderContext context,
                                                        HashSet <FilePath> path)
        {
            var file = (string)includeDirective.AttributeLocal("file");

            if (file == null)
            {
                return(new List <ITextureFile <TTile> >());
            }

            var targetPath = fileSystem.CombinePath(context.BasePath, file);

            if (path.Contains(targetPath))
            {
                throw new TexturePackLoaderException(
                          $"Circular reference in include files or duplicate include while evaluating path {targetPath}",
                          includeDirective);
            }

            path.Add(targetPath);
            using (var stream = fileSystem.Read(targetPath))
            {
                var doc = XDocument.Load(stream);

                var root        = doc.Root;
                var width       = (int?)root.AttributeLocal("width") ?? context.Width;
                var height      = (int?)root.AttributeLocal("height") ?? context.Height;
                var textureType = ParseTextureType((string)root.AttributeLocal("type"), context.TextureType);

                if (textureType != context.TextureType)
                {
                    throw new TexturePackLoaderException(
                              $"Include file '{targetPath}' is using a '{textureType}' tile type.", includeDirective);
                }

                var loaderContext = context.Create(width, height);
                return(ReadContent(root, loaderContext, path));
            }
        }