Пример #1
0
        public override IEnumerable <TexturePackage> CreatePackages(IEnumerable <TextureCategory> sourceRoots)
        {
            // Sprite provider ignores the black/whitelists
            var dirs = sourceRoots.Where(sr => Directory.Exists(sr.Path));
            var tp   = new TexturePackage(String.Join(";", dirs.Select(d => d.Path)), "Sprites", this)
            {
                IsBrowsable = false
            };

            foreach (var dir in dirs)
            {
                var sprs = Directory.GetFiles(dir.Path, "*.spr", SearchOption.AllDirectories);
                if (!sprs.Any())
                {
                    continue;
                }

                foreach (var spr in sprs)
                {
                    var size = GetSize(spr);
                    var rel  = "sprites/" + Path.GetFullPath(spr).Substring(dir.Path.Length).TrimStart('/', '\\').Replace('\\', '/');
                    tp.AddTexture(new TextureItem(tp, rel.ToLowerInvariant(), TextureFlags.Transparent, size.Width, size.Height));
                }
            }
            if (!tp.Items.Any())
            {
                yield break;
            }
            yield return(tp);
        }
Пример #2
0
        public override IEnumerable <TexturePackage> CreatePackages(IEnumerable <TextureCategory> sourceRoots)
        {
            // Sprite provider ignores the black/whitelists
            var dirs = sourceRoots.Where(sr => Directory.Exists(sr.Path));

            foreach (var dir in dirs)
            {
                var tp = new TexturePackage(dir.Path, dir.CategoryName, this);

                var sprs = Directory.GetFiles(dir.Path, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".jpg") || s.EndsWith(".jpeg") || s.EndsWith(".png"));
                if (!sprs.Any())
                {
                    continue;
                }

                foreach (var spr in sprs)
                {
                    var rel = Path.GetFullPath(spr).Substring(dir.Path.Length).TrimStart('/', '\\').Replace('\\', '/');
                    rel = rel.Replace(".jpg", "").Replace(".jpeg", "").Replace(".png", "").ToLowerInvariant();

                    if (rel.Contains("_lm") || rel.EndsWith("bump") || rel.Contains("sky") || rel.EndsWith("_mask"))
                    {
                        continue;
                    }

                    rel = dir.Prefix + rel;

                    if (!loadedImages.ContainsKey(rel))
                    {
                        Bitmap       bmp   = new Bitmap(spr);
                        TextureFlags flags = TextureFlags.None;
                        for (int x = 0; x < 4; x++)
                        {
                            for (int y = 0; y < 4; y++)
                            {
                                int mX = x * (bmp.Width - 1) / 3;
                                int mY = y * (bmp.Height - 1) / 3;
                                if (bmp.GetPixel(mX, mY).A != 255)
                                {
                                    flags = TextureFlags.Transparent;
                                    break;
                                }
                            }
                            if (flags != TextureFlags.None)
                            {
                                break;
                            }
                        }
                        loadedImages.Add(rel, new Tuple <Bitmap, TextureFlags>(bmp, flags));
                    }

                    tp.AddTexture(new TextureItem(tp, rel.ToLower(), loadedImages[rel].Item2, loadedImages[rel].Item1.Width, loadedImages[rel].Item1.Height));
                }
                if (tp.Items.Any())
                {
                    yield return(tp);
                }
            }
        }
Пример #3
0
        public override IEnumerable <TexturePackage> CreatePackages(IEnumerable <string> sourceRoots, IEnumerable <string> additionalPackages, IEnumerable <string> blacklist, IEnumerable <string> whitelist)
        {
            // Sprite provider ignores the black/whitelists
            var dirs = sourceRoots.Union(additionalPackages).Where(Directory.Exists).Select(Path.GetFullPath).Select(x => x.ToLowerInvariant()).Distinct().ToList();

            foreach (var dir in dirs)
            {
                int slashInd = Math.Max(dir.LastIndexOf('/'), dir.LastIndexOf('\\'));
                var tp       = new TexturePackage(dir, dir.Remove(0, slashInd), this);

                var sprs = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".jpg") || s.EndsWith(".jpeg") || s.EndsWith(".png"));
                if (!sprs.Any())
                {
                    continue;
                }

                foreach (var spr in sprs)
                {
                    var rel = Path.GetFullPath(spr).Substring(dir.Length).TrimStart('/', '\\').Replace('\\', '/');
                    rel = rel.Replace(".jpg", "").Replace(".jpeg", "").Replace(".png", "").ToLower();

                    if (!loadedImages.ContainsKey(rel))
                    {
                        Bitmap       bmp   = new Bitmap(spr);
                        TextureFlags flags = TextureFlags.None;
                        for (int x = 0; x < 4; x++)
                        {
                            for (int y = 0; y < 4; y++)
                            {
                                int mX = x * (bmp.Width - 1) / 3;
                                int mY = y * (bmp.Height - 1) / 3;
                                if (bmp.GetPixel(mX, mY).A != 255)
                                {
                                    flags = TextureFlags.Transparent;
                                    break;
                                }
                            }
                            if (flags != TextureFlags.None)
                            {
                                break;
                            }
                        }
                        loadedImages.Add(rel, new Tuple <Bitmap, TextureFlags>(bmp, flags));
                    }

                    tp.AddTexture(new TextureItem(tp, rel.ToLower(), loadedImages[rel].Item2, loadedImages[rel].Item1.Width, loadedImages[rel].Item1.Height));
                }
                if (tp.Items.Any())
                {
                    yield return(tp);
                }
            }
        }