Exemplo n.º 1
0
		public static BioCodexMap Load(Stream stream)
		{
			if (stream == null)
			{
				throw new ArgumentNullException(nameof(stream));
			}

			using (var reader = new BioCodexMapReader(stream))
			{
				var map = new BinaryBioCodexMap();

				// Sections
				var sectionsCount = reader.ReadInt32();
				map.Sections = new Dictionary<int, BioCodexSection>();

				for (var i = 0; i < sectionsCount; i++)
				{
					var id = reader.ReadInt32();
					var section = reader.ReadCodexSection();

					if (!map.Sections.ContainsKey(id))
					{
						map.Sections.Add(id, section);
					}
					else
					{
						map.Sections[id] = section;
					}
				}

				// Pages
				var pagesCount = reader.ReadInt32();
				map.Pages = new Dictionary<int, BioCodexPage>();

				for (var i = 0; i < pagesCount; i++)
				{
					var id = reader.ReadInt32();
					var page = reader.ReadCodexPage();

					if (!map.Pages.ContainsKey(id))
					{
						map.Pages.Add(id, page);
					}
					else
					{
						map.Pages[id] = page;
					}
				}

				return map;
			}
		}
        public static BioCodexMap Load(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using (var reader = new BioCodexMapReader(stream))
            {
                var map = new BinaryBioCodexMap();

                // Sections
                var sectionsCount = reader.ReadInt32();
                map.Sections = new Dictionary <int, BioCodexSection>();

                for (var i = 0; i < sectionsCount; i++)
                {
                    var id      = reader.ReadInt32();
                    var section = reader.ReadCodexSection();

                    if (!map.Sections.ContainsKey(id))
                    {
                        map.Sections.Add(id, section);
                    }
                    else
                    {
                        map.Sections[id] = section;
                    }
                }

                // Pages
                var pagesCount = reader.ReadInt32();
                map.Pages = new Dictionary <int, BioCodexPage>();

                for (var i = 0; i < pagesCount; i++)
                {
                    var id   = reader.ReadInt32();
                    var page = reader.ReadCodexPage();

                    if (!map.Pages.ContainsKey(id))
                    {
                        map.Pages.Add(id, page);
                    }
                    else
                    {
                        map.Pages[id] = page;
                    }
                }

                return(map);
            }
        }
Exemplo n.º 3
0
        public void SaveFile()
        {
            if (pcc == null)
            {
                return;
            }

            if (CodexMapControl != null)
            {
                IExportEntry export;
                int dataOffset;

                if (CodexMapView.TryFindCodexMap(pcc, out export, out dataOffset))
                {
                    using (var stream = new MemoryStream())
                    {
                        var codexMap = CodexMapControl.ToCodexMap();
                        var binaryCodexMap = new BinaryBioCodexMap(codexMap.Sections, codexMap.Pages);

                        binaryCodexMap.Save(stream);

                        export.setBinaryData(stream.ToArray());
                    }
                }
            }

            if (QuestMapControl != null)
            {
                IExportEntry export;
                int dataOffset;

                if (QuestMapControl.TryFindQuestMap(pcc, out export, out dataOffset))
                {
                    using (var stream = new MemoryStream())
                    {
                        var questMap = QuestMapControl.ToQuestMap();
                        var binaryQuestMap = new BinaryBioQuestMap(questMap.Quests, questMap.BoolTaskEvals, questMap.IntTaskEvals, questMap.FloatTaskEvals);

                        binaryQuestMap.Save(stream);

                        export.setBinaryData(stream.ToArray());
                    }
                }
            }

            if (StateEventMapControl != null)
            {
                IExportEntry export;
                int dataOffset;

                if (StateEventMapControl.TryFindStateEventMap(pcc, out export, out dataOffset))
                {
                    using (var stream = new MemoryStream())
                    {
                        var stateEventMap = StateEventMapControl.ToStateEventMap();
                        var binaryStateEventMap = new BinaryBioStateEventMap(stateEventMap.StateEvents);

                        binaryStateEventMap.Save(stream);

                        export.setBinaryData(stream.ToArray());
                    }
                }
            }

            pcc.save(FileName);
        }