コード例 #1
0
ファイル: SprProvider.cs プロジェクト: NCC-Lykos/Chisel
        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);
        }
コード例 #2
0
 public TextureItem(TexturePackage package, string name, TextureFlags flags)
 {
     Package   = package;
     Name      = name;
     Flags     = flags;
     _subItems = new Dictionary <TextureSubItemType, TextureSubItem>();
 }
コード例 #3
0
        public TextureItem(TexturePackage package, string name, TextureFlags flags, string primarySubItemName, int width, int height)
        {
            Package = package;
            Name    = name;
            Flags   = flags;
            var baseItem = new TextureSubItem(TextureSubItemType.Base, this, primarySubItemName, width, height);

            _subItems = new Dictionary <TextureSubItemType, TextureSubItem> {
                { TextureSubItemType.Base, baseItem }
            };
        }
コード例 #4
0
ファイル: WadProvider.cs プロジェクト: NCC-Lykos/Chisel
        private bool LoadFromCache(TexturePackage package)
        {
            if (CachePath == null || !Directory.Exists(CachePath))
            {
                return(false);
            }

            var fi        = new FileInfo(package.PackageRoot);
            var cacheFile = Path.Combine(CachePath, fi.Name + "_" + (fi.LastWriteTime.Ticks));

            if (!File.Exists(cacheFile))
            {
                return(false);
            }

            var lines = File.ReadAllLines(cacheFile);

            if (lines.Length < 3)
            {
                return(false);
            }
            if (lines[0] != fi.FullName)
            {
                return(false);
            }
            if (lines[1] != fi.LastWriteTime.ToFileTime().ToString(CultureInfo.InvariantCulture))
            {
                return(false);
            }
            if (lines[2] != fi.Length.ToString(CultureInfo.InvariantCulture))
            {
                return(false);
            }

            try
            {
                var items = new List <TextureItem>();
                foreach (var line in lines.Skip(3))
                {
                    var spl = line.Split(NullCharacter);
                    items.Add(new TextureItem(package, spl[0], GetFlags(spl[0]), int.Parse(spl[1], CultureInfo.InvariantCulture), int.Parse(spl[2], CultureInfo.InvariantCulture)));
                }
                items.ForEach(package.AddTexture);
            }
            catch
            {
                // Cache file is no good...
                return(false);
            }
            return(true);
        }
コード例 #5
0
ファイル: WadProvider.cs プロジェクト: NCC-Lykos/Chisel
        private void SaveToCache(TexturePackage package)
        {
            if (CachePath == null || !Directory.Exists(CachePath))
            {
                return;
            }
            var fi        = new FileInfo(package.PackageRoot);
            var cacheFile = Path.Combine(CachePath, fi.Name + "_" + (fi.LastWriteTime.Ticks));
            var lines     = new List <string>();

            lines.Add(fi.FullName);
            lines.Add(fi.LastWriteTime.ToFileTime().ToString(CultureInfo.InvariantCulture));
            lines.Add(fi.Length.ToString(CultureInfo.InvariantCulture));
            foreach (var ti in package.Items.Values)
            {
                lines.Add(ti.Name + NullCharacter + ti.Width.ToString(CultureInfo.InvariantCulture) + NullCharacter + ti.Height.ToString(CultureInfo.InvariantCulture));
            }
            File.WriteAllLines(cacheFile, lines);
        }
コード例 #6
0
ファイル: WadProvider.cs プロジェクト: NCC-Lykos/Chisel
        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);
            }
        }