Esempio n. 1
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();
            var tp   = new TexturePackage(String.Join(";", dirs), "sprites", this)
            {
                IsBrowsable = false
            };

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

                foreach (var spr in sprs)
                {
                    var size = GetSize(spr);
                    var rel  = Path.GetFullPath(spr).Substring(dir.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);
        }
Esempio n. 2
0
        private TexturePackage CreatePackage(string package)
        {
            try
            {
                var fi = new FileInfo(package);
                if (!fi.Exists)
                {
                    return(null);
                }

                var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this);
                if (LoadFromCache(tp))
                {
                    return(tp);
                }

                var list = new List <TextureItem>();

                var pack = _roots.Values.FirstOrDefault(x => x.Package.PackageFile.FullName == fi.FullName);
                if (pack == null)
                {
                    _roots.Add(tp, pack = new WadStream(new WadPackage(fi)));
                }

                list.AddRange(pack.Package.GetEntries().OfType <WadEntry>().Select(x => new TextureItem(tp, x.Name, GetFlags(x.Name), (int)x.Width, (int)x.Height)));
                foreach (var ti in list)
                {
                    tp.AddTexture(ti);
                }
                SaveToCache(tp);
                return(tp);
            }
            catch
            {
                return(null);
            }
        }