SadComponents

SadConsole supports the use of Components, which can be attached to consoles.
Components can hook into Update, Render, Keyboard, Mouse methods.

Component-based architecture focuses on the decomposition of the design into individual functional or logical components that represent well-defined communication interfaces containing methods, events, and properties. It provides a higher level of abstraction and divides the problem into sub-problems, each associated with component partitions.

Build In Components

  • Timer (A component that uses the Update method to act as a timer, with some events)
  • SurfaceComponentFollowTarget (Centers the ViewPosition on the target position to follow it around)
  • ObjectComponentMove (Moves a Surface with arrow keys, keys can be adjusted)
  • Cursor (Adds a cursor to the parent, by default a Console already contains this component)
  • Renderer (Adds an entity renderer component to a surface, this handles entity rendering)

SadConsole.Extended Components

The SadConsole.Extended nuget package provides some default components that can be useful.

  • C64KeyboardHandler (A console prompt keyboard handler that acts like the text editor on the Commodore 64 and VIC-20 computers)
  • ClassicConsoleKeyboardHandler (A classic console/terminal prompt keyboard handler)
  • MouseTint (Tints a surface when that surface would use the mouse. Helps debug which object is receiving mouse input as you move the mouse around)
  • MoveViewPortKeyboardHandler (Moves the view of an IScreenSurface with a set of specified keyboard keys)
  • SmoothMove (Animates the movement of an object)

Adding a component

To add a component to a console/surface you use the SadComponents collection.

var timerComponent = new SadConsole.Components.Timer(System.TimeSpan.FromSeconds(5));
timerComponent.TimerElapsed += (sender, args) => { System.Console.WriteLine("Timer elapsed!"); };

timerComponent.Start();
timerComponent.Repeat = false;

Game.Instance.StartingConsole.SadComponents.Add(timerComponent);

This will make the StartingConsole handle the timer component.

Leave a comment

Design a site like this with WordPress.com
Get started