Exemple #1
0
        public TileManager(TileType tileType, string sourceTag, int sourceCount)
        {
            ReleaseTimerTick += delegate(object sender, EventArgs args) { ReleaseTiles(); };
            this.tileType = tileType;

            // TODO: Clean up the API for this shit?
            string dataPath = Settings.Global.Default.DataPath;
            string archivePath = Path.Combine(dataPath, "tile.dat");
            string paletteCollectionName = sourceTag + "." + PaletteCollection.FileExtension,
                paletteTableName = sourceTag + "." + PaletteTable.FileExtension;
            PaletteCollection paletteCollection;
            PaletteTable paletteTable;
            using(FileStream archiveStream = new FileStream(archivePath, FileMode.Open)) {
                ArchiveHeader archive = new ArchiveHeader(archiveStream);
                archiveStream.Seek(archive.GetEntry(paletteCollectionName).Offset, SeekOrigin.Begin);
                paletteCollection = PaletteCollection.FromStream(archiveStream);
                archiveStream.Seek(archive.GetEntry(paletteTableName).Offset, SeekOrigin.Begin);
                paletteTable = PaletteTable.FromStream(archiveStream);
            }
            GraphicLoader.ISourceProvider sourceProvider =
                new GraphicLoader.SourceProvider(sourceCount, Path.Combine(dataPath, sourceTag));
            graphicLoader = new GraphicLoader(paletteCollection, paletteTable, sourceProvider);

            BlankTile = new Tile(tileType, 0);
            // Use a clone because the Create method transfers ownership
            BlankTile.Create((Image)BlankImage.Clone());
            tiles.Add(0, BlankTile);
            // Artificially increment the refcount for blankTile so it is never disposed until it
            // is garbage collected.
            ++BlankTile.Refcount;
        }
Exemple #2
0
 public Stream GetSourceStream(int index)
 {
     Debug.Assert(index < sourceCount);
     string path = string.Format("{0}{1}.dat", sourceTag, index);
     FileStream stream = new FileStream(path, FileMode.Open);
     ArchiveHeader archive = new ArchiveHeader(stream);
     string entryName = Path.GetFileNameWithoutExtension(path) + ".epf";
     // TODO: Throw an exception if the entry is null?
     stream.Seek(archive.GetEntry(entryName).Offset, SeekOrigin.Begin);
     return stream;
 }