예제 #1
0
 protected override IEnumerable <HpiArchive.FileInfo> EnumerateFiles(HpiArchive r)
 {
     return(r.GetFilesRecursive("objects3d")
            .Where(x =>
                   x.Name.EndsWith(".3do", StringComparison.OrdinalIgnoreCase) &&
                   this.objectMap.ContainsKey(HpiPath.GetFileNameWithoutExtension(x.Name))));
 }
예제 #2
0
        public UndoableMapModel CreateFromHpi(string hpipath, string mappath, bool readOnly)
        {
            MapModel m;

            using (var hpi = new HpiArchive(hpipath))
            {
                var otaPath = HpiPath.ChangeExtension(mappath, ".ota");

                TdfNode n;

                var otaFileInfo   = hpi.FindFile(otaPath);
                var otaFileBuffer = new byte[otaFileInfo.Size];
                hpi.Extract(otaFileInfo, otaFileBuffer);
                using (var ota = new MemoryStream(otaFileBuffer))
                {
                    n = TdfNode.LoadTdf(ota);
                }

                var tntFileInfo   = hpi.FindFile(mappath);
                var tntFileBuffer = new byte[tntFileInfo.Size];
                hpi.Extract(tntFileInfo, tntFileBuffer);
                using (var s = new TntReader(new MemoryStream(tntFileBuffer)))
                {
                    m = this.mapModelFactory.FromTntAndOta(s, n);
                }
            }

            return(new UndoableMapModel(m, hpipath, readOnly));
        }
예제 #3
0
        private bool IsNeededFile(HpiArchive.FileInfo entry)
        {
            var file = entry.Name;

            return(file.EndsWith(".gaf", StringComparison.OrdinalIgnoreCase) &&
                   this.filenameFeatureMap.ContainsKey(
                       HpiPath.GetFileNameWithoutExtension(file)));
        }
예제 #4
0
        protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file)
        {
            // extract and read the file
            var fileBuffer = new byte[file.Size];

            archive.Extract(file, fileBuffer);
            var adapter = new GafEntryArrayAdapter();

            using (var b = new GafReader(new MemoryStream(fileBuffer), adapter))
            {
                b.Read();
            }

            var gaf = adapter.Entries;

            var records = this.filenameFeatureMap[HpiPath.GetFileNameWithoutExtension(file.Name)];

            // retrieve the anim for each record
            foreach (var record in records)
            {
                var sequenceName = record.SequenceName;
                if (string.IsNullOrEmpty(sequenceName))
                {
                    // Skip if this record has no sequence name.
                    continue;
                }

                var entry = gaf.FirstOrDefault(
                    x => string.Equals(x.Name, sequenceName, StringComparison.OrdinalIgnoreCase));
                if (entry == null)
                {
                    // skip if the sequence is not in this gaf file
                    continue;
                }

                var frame = entry.Frames[0];

                Bitmap bmp;
                if (frame.Data == null || frame.Width == 0 || frame.Height == 0)
                {
                    bmp = new Bitmap(50, 50);
                }
                else
                {
                    bmp = BitmapConvert.ToBitmap(
                        frame.Data,
                        frame.Width,
                        frame.Height,
                        frame.TransparencyIndex);
                }

                var offsetImage = new OffsetBitmap(-frame.OffsetX, -frame.OffsetY, bmp);
                this.Records.Add(new KeyValuePair <string, OffsetBitmap>(record.Name, offsetImage));
            }
        }
예제 #5
0
        public MapTile LoadSection(string hpiFileName, string sctFileName)
        {
            var key = HpiPath.Combine(hpiFileName, sctFileName);

            MapTile section;

            if (!this.tileCache.TryGetValue(key, out section))
            {
                section             = this.LoadSectionFromDisk(hpiFileName, sctFileName);
                this.tileCache[key] = section;
            }

            return(section);
        }
예제 #6
0
        protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file)
        {
            var records = this.objectMap[HpiPath.GetFileNameWithoutExtension(file.Name)];

            var fileBuffer = new byte[file.Size];

            archive.Extract(file, fileBuffer);

            using (var b = new MemoryStream(fileBuffer))
            {
                var adapter = new ModelEdgeReaderAdapter();
                var reader  = new ModelReader(b, adapter);
                reader.Read();
                var wire = Util.RenderWireframe(adapter.Edges);
                foreach (var record in records)
                {
                    this.Records.Add(new KeyValuePair <string, OffsetBitmap>(record.Name, wire));
                }
            }
        }
예제 #7
0
        private void OpenFromHapi(string filename)
        {
            List <string> maps;
            bool          readOnly;

            using (var h = new HpiArchive(filename))
            {
                maps = GetMapNames(h).ToList();
            }

            string mapName;

            switch (maps.Count)
            {
            case 0:
                this.dialogService.ShowError("No maps found in " + filename);
                return;

            case 1:
                mapName  = maps.First();
                readOnly = false;
                break;

            default:
                maps.Sort();
                mapName  = this.dialogService.AskUserToChooseMap(maps);
                readOnly = true;
                break;
            }

            if (mapName == null)
            {
                return;
            }

            var tntPath = HpiPath.Combine("maps", mapName + ".tnt");

            this.model.Map = Maybe.Some(this.mapLoadingService.CreateFromHpi(filename, tntPath, readOnly));
        }
예제 #8
0
        protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file)
        {
            var fileBuffer = new byte[file.Size];

            archive.Extract(file, fileBuffer);

            using (var s = new SctReader(new MemoryStream(fileBuffer)))
            {
                var section = new Section(archive.FileName, file.FullPath);
                section.Name       = HpiPath.GetFileNameWithoutExtension(file.Name);
                section.Minimap    = SectionFactory.MinimapFromSct(s);
                section.DataWidth  = s.DataWidth;
                section.DataHeight = s.DataHeight;

                var directoryString = HpiPath.GetDirectoryName(file.FullPath);
                Debug.Assert(directoryString != null, "Null directory for section in HPI.");
                var directories = directoryString.Split('\\');

                section.World    = directories[1];
                section.Category = directories[2];

                this.Records.Add(section);
            }
        }
예제 #9
0
 private static IEnumerable <string> GetMapNames(HpiArchive hpi)
 {
     return(hpi.GetFiles("maps")
            .Where(x => x.Name.EndsWith(".tnt", StringComparison.OrdinalIgnoreCase))
            .Select(x => HpiPath.GetFileNameWithoutExtension(x.Name)));
 }