private void BrokerToScene(ConsoleKey key, Action a, ConsoleModifiers?modifiers = null) { FocusManager.GlobalKeyHandlers.PushForLifetime(key, modifiers, () => { PreviewScene.QueueAction(a); }, LifetimeManager); }
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); }); }
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); }); }