The actors in the game world (so player and ghosts) are managed via a simplistic Entity-Component System I wrote. This Entity-Component system is also hijacked to provide the simplistic UI elements, such as the text 'box' used to enter a host and port. Using an ECS for those GUI elements actually worked pretty well, all-in-all.
*digs up descriptions of Components*
---
Ghost :- The ghost entity is tagged with a ghost component. This component has one piece of information, a number that represents which of the 3 ghost sprites represent this ghost.
Player :- The player entity is tagged with the player component. This component contains no useful data, it’s presence is used to tell that the entity is a player.
Actor :- Both player and ghost have the actor component. The actor component contains a position field that stores the x and y coordinates of the entity, and a direction field that stores the velocity of the entity.
Remote :- Entities that are not being controlled by the current client, so all entities on the server and all but one entity on each client, are given the remote component. The remote component also stores a UUID that identifies that user, for when the entitiy is referred to over networking traffic, such as for the handling of MoveRemoteActorOnServer and MoveRemoteActorOnClient messages.
Local :- The entity being controlled by the current client is tagged with the Local component. This component contains no fields, but it’s presence is used to determine that the entity can be controlled by local keyboard input. It is not used by the server as a result.
There are additional components used for the user interface, such as MenuOption, Text and TextBox. These are used for GUI entities, that typically have a one-to-one mapping between the entity and component (a menu option entity only has one component, MenuOption).
MenuOption :- A series of clickable lines of text. The position and size of the text is stored in the component as a field, alongside the actual text for each line and which line is currently active (or -1 for none). This allows for the MenuOptionController and MenuOptionView to manage the menus easily, updating active menus and displaying the menus respectively, and for any controllers that need menus to create one and inspect if any of the menus are active to determine if an option has been selected.
TextBox :- A text box which, when clicked on, will take what characters are typed into the keyboard. There can also be an optional filter to limit the characters (defaults to basic ASCII printable characters), as well as a position and size for the text box. This is used by the server and client connection controllers to allow users to specify hostname and port as needed.
Text :- The simplest of GUI components, text simply has a position, size of the text and a string to display. This text is then rendered in the TextView. This is used by, for example, the server lobby to display what players are connected.