Пример #1
0
        public static PlatformContext Load(BinaryReader reader)
        {
            var version = reader.ReadInt32();

            if (version != Version)
            {
                throw new InvalidDataException("Bad version");
            }
            var context = new PlatformContext();

            context.BlockStore = BinBlockStoreSerializer.Load(reader);
            context.Map        = BinTileMapSerializer.Load(reader);
            var numLights = reader.ReadInt32();

            while (numLights > 0)
            {
                context.AttachLightSource(BinLightSerializer.Load(reader));
                numLights--;
            }
            context.LightsEnabled = reader.ReadBoolean();
            context.Time          = TimeSpan.FromSeconds(reader.ReadDouble());
            var numSpawns = reader.ReadInt32();

            while (numSpawns > 0)
            {
                var spawn = BinSpawnSerializer.Load(reader);
                context.Spawn.Add(spawn);
                numSpawns--;
            }
            return(context);
        }
Пример #2
0
        public static void Save(BinaryWriter writer, PlatformContext context)
        {
            writer.Write((Int32)Version);
            BinBlockStoreSerializer.Save(writer, context.BlockStore);
            BinTileMapSerializer.Save(writer, context.Map);
            var lights = context.LightSources.ToList();

            writer.Write((Int32)lights.Count);
            foreach (var light in lights)
            {
                BinLightSerializer.Save(writer, light);
            }
            writer.Write(context.LightsEnabled);
            writer.Write((Double)context.Time.TotalSeconds);
            writer.Write((Int32)context.Spawn.Count);
            foreach (var spawn in context.Spawn)
            {
                BinSpawnSerializer.Save(writer, spawn);
            }
        }