/// <summary>
        /// Saves the data into the given <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
        public void Save(Stream stream)
        {
            // Before saving all the instances, allow references to be resolved.
            Areas?.ForEach(x => x.SerializeReferences(this));

            EnemyPaths?.ForEach(x => x.SerializeReferences(this));
            GCameraPaths?.ForEach(x => x.SerializeReferences(this));
            GlidePaths?.ForEach(x => x.SerializeReferences(this));
            GravityPaths?.ForEach(x => x.SerializeReferences(this));
            ItemPaths?.ForEach(x => x.SerializeReferences(this));
            JugemPaths?.ForEach(x => x.SerializeReferences(this));
            LapPaths?.ForEach(x => x.SerializeReferences(this));
            PullPaths?.ForEach(x => x.SerializeReferences(this));

            Objs.ForEach(x => x.SerializeReferences(this));

            ReplayCameras?.ForEach(x => x.SerializeReferences(this));

            // Save the serialized values.
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                SupportPaths = true,
                Version = ByamlVersion.Version1
            });
            serializer.Serialize(stream, this);
        }
예제 #2
0
        private void GenerateIDs()
        {
            var factionIDs = new Dictionary <Faction, int>();
            var areaIDs    = new Dictionary <Area, int>();
            var itemIDs    = new Dictionary <Item, int>();
            var unitIDs    = new Dictionary <Unit, int>();

            void GenerateID <T>(T asset, Dictionary <T, int> lookup) where T : IAsset
            {
                asset.ID = lookup.Count;
                lookup.Add(asset, asset.ID);
            }

            Factions.ForEach(x => GenerateID(x, factionIDs));
            Areas.ForEach(x => GenerateID(x, areaIDs));
            Items.ForEach(x => GenerateID(x, itemIDs));
            Units.ForEach(x => GenerateID(x, unitIDs));

            foreach (var unit in Units)
            {
                unit.FactionID = unit.Faction.ID;
                unit.AreaID    = unit.Area.ID;

                unit.ItemIDs = new int[unit.Inventory.Count];
                for (int i = 0; i < unit.Inventory.Count; i++)
                {
                    unit.ItemIDs[i] = unit.Inventory[i].ID;
                }
            }
        }
        // ---- METHODS(PUBLIC) ---------------------------------------------------------------------------------------

        /// <summary>
        /// Loads the data from the given <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
        public void Load(Stream stream)
        {
            // Load all the values from the stream.
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                SupportPaths = true,
                Version = ByamlVersion.Version1
            });
            serializer.Deserialize(stream, this);

            // After loading all the instances, allow references to be resolved.
            Areas?.ForEach(x => x.DeserializeReferences(this));

            EnemyPaths?.ForEach(x => x.DeserializeReferences(this));
            GCameraPaths?.ForEach(x => x.DeserializeReferences(this));
            GlidePaths?.ForEach(x => x.DeserializeReferences(this));
            GravityPaths?.ForEach(x => x.DeserializeReferences(this));
            ItemPaths?.ForEach(x => x.DeserializeReferences(this));
            JugemPaths?.ForEach(x => x.DeserializeReferences(this));
            LapPaths?.ForEach(x => x.DeserializeReferences(this));
            ObjPaths?.ForEach(x => x.DeserializeReferences(this));
            Paths?.ForEach(x => x.DeserializeReferences(this));
            PullPaths?.ForEach(x => x.DeserializeReferences(this));

            Objs.ForEach(x => x.DeserializeReferences(this));

            ReplayCameras?.ForEach(x => x.DeserializeReferences(this));
        }
예제 #4
0
파일: World.cs 프로젝트: kaerber/kmud
        public void LoadAreas()
        {
            Areas = _areaManager.List("areas")
                    .Select(name => _areaManager.Load("areas", name))
                    .ToList();
            Areas.ForEach(a => a.Initialize(_updateQueue));

            Rooms = Areas.SelectMany(a => a.Rooms).ToDictionary(r => r.Id, r => r);
            Mobs  = Areas.SelectMany(a => a.Mobs).ToDictionary(m => m.Id, m => m);
            Items = Areas.SelectMany(a => a.Items).ToDictionary(i => i.Id, i => i);

            Rooms.Values.ForEach(r => r.Update());
        }