private void LoadLevel(string levelFile) { var level = LevelDefinition.Load(levelFile); this.CurrentLevelDefinition = level; PreviewScene.QueueAction(() => { foreach (var thing in PreviewScene.Things.ToArray()) { if (thing is Cursor) { continue; } PreviewScene.Remove(thing); } foreach (var interaction in PreviewScene.Interactions.ToArray()) { PreviewScene.Remove(interaction); } level.Hydrate(PreviewScene, true); }); }
private void SetupSaveKeyInput() { this.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.S, null, () => { Dialog.ShowRichTextInput("Name this level".ToYellow(), (result) => { CurrentLevelDefinition.Save(result.ToString()); }, initialValue: LevelId?.ToConsoleString()); }, LifetimeManager); this.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.L, null, () => { var options = LevelDefinition.GetLevelDefinitionFiles().Select(f => new DialogOption() { DisplayText = System.IO.Path.GetFileNameWithoutExtension(f).ToYellow(), Id = f }); if (options.Count() == 0) { Dialog.ShowMessage("No levels to load"); } else { Dialog.Pick("Choose a level to load".ToYellow(), options).Then((button) => { var levelFile = button.Id; LoadLevel(levelFile); }); } }, LifetimeManager); }
public void Load(LevelDefinition def) { scenePanel.Scene.QueueAction(() => { Inventory toKeep = null; if (MainCharacter.Current != null) { toKeep = MainCharacter.Current.Inventory; } scenePanel.Scene.Clear(); def.Hydrate(scenePanel.Scene, false); foreach (var portal in scenePanel.Scene.Things.Where(p => p is Portal).Select(p => p as Portal)) { var localPortal = portal; localPortal.PortalEntered.SubscribeForLifetime(() => { Load(LevelDefinition.Load(localPortal.DestinationId)); }, portal.LifetimeManager); } if (MainCharacter.Current != null) { this.MainCharacter = MainCharacter.Current; if (toKeep != null) { MainCharacter.Current.Inventory = toKeep; } InputManager.SetKeyMap(InputManager.KeyMap); MainCharacter.Current.EatenByZombie.SubscribeForLifetime(() => { implicitPause = true; scenePanel.Scene.Stop(); QueueAction(() => { SoundEffects.Instance.PlaySound("playerdead"); Dialog.ShowMessage("Game over :(", () => { Stop(); }); }); }, scenePanel.LifetimeManager); } }); }
public void Play([ArgumentAwareTabCompletion(typeof(LevelCompletionType))] string levelFile) { if (levelFile.EndsWith(".czl") == false) { var guessedFile = System.IO.Path.Combine(LevelDefinition.LevelBuilderLevelsPath, levelFile + ".czl"); if (System.IO.File.Exists(guessedFile) == false) { throw new ArgException("No level called " + levelFile); } else { levelFile = guessedFile; } } else if (System.IO.File.Exists(levelFile)) { throw new ArgException("No level called " + levelFile); } var game = new GameApp(); game.Load(LevelDefinition.Load(levelFile)); game.Start().Wait(); }
public LevelBuilder() { Cursor = new Cursor(); UndoStack = new UndoRedoStack(); var topPanel = LayoutRoot.Add(new ConsolePanel() { Background = System.ConsoleColor.Black }).Fill(padding: new Thickness(0, 0, 0, 6)); var botPanel = LayoutRoot.Add(new ConsolePanel() { Height = 6, Background = System.ConsoleColor.DarkRed }).DockToBottom().FillHoriontally(); var borderPanel = topPanel.Add(new ConsolePanel() { Background = ConsoleColor.DarkGray, Width = LevelDefinition.Width + 2, Height = LevelDefinition.Height + 2 }).CenterHorizontally().CenterVertically(); ScenePanel = borderPanel.Add(new ScenePanel(LevelDefinition.Width, LevelDefinition.Height)).Fill(padding: new Thickness(1, 1, 1, 1)); var sceneFPSLabel = LayoutRoot.Add(new Label() { Text = "".ToConsoleString() }).FillHoriontally(); var renderFPSLabel = LayoutRoot.Add(new Label() { Y = 1, Text = "".ToConsoleString() }).FillHoriontally(); var paintFPSLabel = LayoutRoot.Add(new Label() { Y = 2, Text = "".ToConsoleString() }).FillHoriontally(); LifetimeManager.Manage(SetInterval(() => { sceneFPSLabel.Text = $"{ScenePanel.Scene.FPS} scene frames per second".ToCyan(); renderFPSLabel.Text = $"{FPS} render frames per second".ToCyan(); paintFPSLabel.Text = $"{PPS} paint frames per second".ToCyan(); }, TimeSpan.FromSeconds(1))); QueueAction(() => { if (this.LevelId != null) { LoadLevel(this.LevelId); } else { CurrentLevelDefinition = new LevelDefinition(); } PreviewScene.Start(); SetupCursorKeyInput(); SetupDropKeyInput(); SetupSaveKeyInput(); }); PreviewScene.QueueAction(() => { Cursor.Bounds.Resize(ScenePanel.PixelSize); PreviewScene.Add(Cursor); }); }
public LevelCompletionType() : base() { innerSource = new SimpleTabCompletionSource(LevelDefinition.GetLevelDefinitionFiles().Select(l => System.IO.Path.GetFileNameWithoutExtension(l).Contains(" ") ? "\"" + System.IO.Path.GetFileNameWithoutExtension(l) + "\"" : System.IO.Path.GetFileNameWithoutExtension(l))); }