예제 #1
0
        public static void Load(Main main, string filename, bool deleteEditor = true)
        {
            if (filename == null)
            {
                MapLoader.Load(main, (Stream)null, deleteEditor);
            }
            else
            {
                // Don't try to load the menu from a save game
                string directory;
                if (main.CurrentSave.Value == null || filename == Main.MenuMap)
                {
                    directory = main.MapDirectory;
                }
                else
                {
                    directory = Path.Combine(main.SaveDirectory, main.CurrentSave);
                }

                string filenameWithExtension = filename;
                if (!filenameWithExtension.EndsWith(MapLoader.MapExtension))
                {
                    filenameWithExtension += MapLoader.MapExtension;
                }

                string fullFilename = Path.IsPathRooted(filenameWithExtension) ? filenameWithExtension : Path.Combine(directory, filenameWithExtension);

                if (main.CurrentSave.Value != null && !File.Exists(fullFilename))
                {
                    File.Copy(Path.Combine(main.MapDirectory, filenameWithExtension), fullFilename);
                }

                main.LoadingMap.Execute(filename);

                main.MapFile.Value = filename;

                using (Stream fs = File.OpenRead(fullFilename))
                {
                    using (Stream stream = new GZipInputStream(fs))
                        MapLoader.Load(main, stream, deleteEditor);
                }
            }
        }
예제 #2
0
        public static void LoadWithEntities(Main main, string nextMap, List <Entity> persistentEntities)
        {
            Stream stream = new MemoryStream();

            IO.MapLoader.Serializer.Serialize(stream, persistentEntities);

            MapLoader.Load(main, nextMap);

            stream.Seek(0, SeekOrigin.Begin);
            List <Entity> entities = (List <Entity>)IO.MapLoader.Serializer.Deserialize(stream);

            foreach (Entity e in entities)
            {
                Factory <Main> factory = Factory <Main> .Get(e.Type);

                e.GUID = 0;
                factory.Bind(e, main);
                main.Add(e);
            }
            stream.Dispose();
        }
예제 #3
0
        public static void New(Main main, string filename, string templateMap)
        {
            main.LoadingMap.Execute(filename);

            main.MapFile.Value = filename;

            if (!filename.EndsWith(MapLoader.MapExtension))
            {
                filename += MapLoader.MapExtension;
            }

            main.ClearEntities(false);

            if (!templateMap.EndsWith(MapLoader.MapExtension))
            {
                templateMap += MapLoader.MapExtension;
            }

            using (Stream fs = File.OpenRead(templateMap))
            {
                using (Stream stream = new GZipInputStream(fs))
                    MapLoader.Load(main, stream, false);
            }
        }
예제 #4
0
        public static void Transition(Main main, string nextMap, string spawn = null, bool saveInfo = true)
        {
            Stream stream = new MemoryStream();

            Container loadingNotification = new Container();

            loadingNotification.Tint.Value    = Microsoft.Xna.Framework.Color.Black;
            loadingNotification.Opacity.Value = 0.5f;
            TextElement loadingNotificationText = new TextElement();

            loadingNotificationText.Name.Value     = "Text";
            loadingNotificationText.FontFile.Value = main.Font;
            loadingNotificationText.Text.Value     = "\\loading";
            loadingNotification.Children.Add(loadingNotificationText);

            Animation anim = new Animation
                             (
                new Animation.Set <bool>(main.Menu.CanPause, false),
                main.Spawner.FlashAnimation(),
                new Animation.Execute(delegate()
            {
                main.UI.Root.GetChildByName("Notifications").Children.Add(loadingNotification);
            }),
                new Animation.Delay(0.01f),
                new Animation.Execute(delegate()
            {
                // We are exiting the map; just save the state of the map without the player.
                ListProperty <RespawnLocation> respawnLocations = PlayerDataFactory.Instance.Get <PlayerData>().RespawnLocations;
                respawnLocations.Clear();

                List <Entity> persistentEntities = main.Entities.Where((Func <Entity, bool>)MapLoader.entityIsPersistent).ToList();

                IO.MapLoader.Serializer.Serialize(stream, persistentEntities);

                foreach (Entity e in persistentEntities)
                {
                    e.Delete.Execute();
                }

                main.Spawner.StartSpawnPoint.Value = spawn;

                if (PlayerFactory.Instance != null)
                {
                    PlayerFactory.Instance.Delete.Execute();
                }

                main.SaveCurrentMap(null, default(Point), saveInfo);
                MapLoader.Load(main, nextMap);

                stream.Seek(0, SeekOrigin.Begin);
                List <Entity> entities = (List <Entity>)IO.MapLoader.Serializer.Deserialize(stream);
                foreach (Entity e in entities)
                {
                    Factory <Main> factory = Factory <Main> .Get(e.Type);
                    e.GUID = 0;
                    factory.Bind(e, main);
                    main.Add(e);
                }
                stream.Dispose();
            }),
                new Animation.Delay(0.01f),
                new Animation.Execute(loadingNotification.Delete),
                new Animation.Set <bool>(main.Menu.CanPause, true),
                new Animation.Execute(main.ScheduleSave)
                             );

            anim.EnabledWhenPaused = false;
            main.AddComponent(anim);
        }
예제 #5
0
파일: MapLoader.cs 프로젝트: tammukul/Lemma
 public static void Load(Main main, string filename, Entity playerData)
 {
     MapLoader.load(main, filename, true, playerData);
 }
예제 #6
0
파일: MapLoader.cs 프로젝트: tammukul/Lemma
 public static void Load(Main main, string filename)
 {
     MapLoader.load(main, filename, true, null);
 }
예제 #7
0
파일: MapLoader.cs 프로젝트: tammukul/Lemma
 public static void LoadKeepEditor(Main main, string filename)
 {
     MapLoader.load(main, filename, false, null);
 }