28#include <unordered_map>
29#include <toml++/toml.hpp>
78 Main(
const std::string &ip =
"127.0.0.1",
unsigned int port = 9000,
unsigned int windowWidth = 800,
unsigned int windowHeight = 600,
bool windowCursor =
true,
bool windowFullscreen =
false,
const std::string &windowTitle =
"R-Type",
unsigned int windowX = 0,
unsigned int windowY = 0,
const std::string &windowCursorIcon =
"NULL",
bool imageIsSprite =
false,
bool spriteStartTop =
false,
bool spriteStartLeft =
false,
unsigned int spriteWidth = 20,
unsigned int spriteHeight = 20,
unsigned int frameLimit = 60,
const std::string &configFilePath =
"client_config.toml",
const bool log =
false,
const bool debug =
false,
const std::string &player =
"Player");
84 void setIp(
const std::string &ip);
85 void setPort(
const unsigned int port);
103 void setLog(
const bool debug);
106 void setPlayer(
const std::string &player);
109 const std::string
getIp();
122 const bool getLog()
const;
136 std::string _lowerText(
const std::string &text);
139 const bool _isIpInRange(
const std::string &ip)
const;
140 const bool _isPortCorrect(
const unsigned int port)
const;
141 const bool _isFilePresent(
const std::string &filepath)
const;
142 const bool _isFrameLimitCorrect(
const unsigned int frameLimit)
const;
143 const bool _isFontConfigurationCorrect(
const TOMLLoader &node)
const;
144 const bool _isIconConfigurationCorrect(
const TOMLLoader &node)
const;
145 const bool _isMusicConfigurationCorrect(
const TOMLLoader &node)
const;
146 const bool _isSpriteConfigurationCorrect(
const TOMLLoader &node)
const;
147 const bool _isBackgroundConfigurationCorrect(
const TOMLLoader &node)
const;
148 const bool _isKeyPresentAndOfCorrectType(
const TOMLLoader &node,
const std::string &key,
const toml::node_type &valueType)
const;
165 template <
typename Exception = CustomExceptions::Inval
idFontConfiguration,
typename ExceptionMissing = CustomExceptions::NoFontInConfigFile>
166 const TOMLLoader _getTOMLNodeContent(
const TOMLLoader &node,
const std::string &key,
const std::string &keyAlt)
169 const std::string tomlPath = _tomlContent.
getTOMLPath();
171 if (_tomlContent.
hasKey(key)) {
172 PRETTY_INFO <<
"Fetching the content for '" << key <<
"'." << std::endl;
174 if (_tomlContent.
getValueType(key) == toml::node_type::table) {
175 ItemNode = _tomlContent.
getTable(key);
179 }
else if (_tomlContent.
hasKey(keyAlt)) {
180 PRETTY_INFO <<
"Fetching the content for '" << keyAlt <<
"'." << std::endl;
182 if (_tomlContent.
getValueType(keyAlt) == toml::node_type::table) {
183 ItemNode = _tomlContent.
getTable(keyAlt);
188 PRETTY_CRITICAL <<
"The key " << key <<
" is missing from the config file, " <<
189 "the other supported key " << keyAlt <<
" wasn't found in the config file." << std::endl;
190 throw ExceptionMissing(_tomlContent.
getTOMLPath(), key);
198 std::uint32_t _initialiseAudio();
199 std::uint32_t _initialiseFonts();
200 std::uint32_t _initialiseIcon();
201 std::uint32_t _initialiseSprites();
202 std::uint32_t _initialiseBackgrounds();
205 void _initialiseConnection();
206 void _initialiseRessources();
209 void _updateLoadingText(
const std::string &detail =
"Loading...");
215 void _sendAllPackets();
216 void _processIncommingPackets();
219 const std::string _getIpChunk(
const unsigned int index,
const std::string &defaultValue)
const;
222 const std::optional<std::shared_ptr<GUI::ECS::Components::TextComponent>> _getTextComponent(
const std::string &textComponentKey);
225 const std::string _incrementIpV4Node(
const std::string &v4Section);
226 const std::string _decrementIpV4Node(
const std::string &v4Section);
229 const std::string _incrementPortCounter(
const std::string &portSection);
230 const std::string _decrementPortCounter(
const std::string &portSection);
233 void _incrementIpChunkOne();
234 void _incrementIpChunkTwo();
235 void _incrementIpChunkThree();
236 void _incrementIpChunkFour();
237 void _incrementPortChunk();
240 void _decrementIpChunkOne();
241 void _decrementIpChunkTwo();
242 void _decrementIpChunkThree();
243 void _decrementIpChunkFour();
244 void _decrementPortChunk();
247 const std::shared_ptr<GUI::ECS::Systems::EventManager> _getEventManager();
253 const std::shared_ptr<GUI::ECS::Components::ButtonComponent> _createButton(
const std::string &application,
const std::string &title, std::function<
void()> callback,
const std::string &callbackName =
"callback function",
const int width = 40,
const int height = 20,
const int textSize = 20,
const GUI::ECS::Systems::Colour &bg =
GUI::ECS::Systems::Colour::Black,
const GUI::ECS::Systems::Colour &normal =
GUI::ECS::Systems::Colour::White,
const GUI::ECS::Systems::Colour &hover =
GUI::ECS::Systems::Colour::Yellow,
const GUI::ECS::Systems::Colour &clicked =
GUI::ECS::Systems::Colour::AliceBlue,
const std::shared_ptr<GUI::ECS::Systems::Font> &textFont =
nullptr);
256 const unsigned int _getScreenCenterX();
257 const unsigned int _getScreenCenterY();
262 void _settingsMenu();
263 void _unknownScreen();
264 void _gameOverScreen();
265 void _gameWonScreen();
266 void _mainMenuScreen();
267 void _bossFightScreen();
268 void _connectionFailedScreen();
269 void _connectionAddressScreen();
285 void _goConnectionFailed();
287 void _goConnectionAddress();
298 void _updateMusicStatus();
301 void _startMainMenuMusic();
302 void _stopMainMenuMusic();
305 void _startGameLoopMusic();
306 void _stopGameLoopMusic();
309 void _startBossFightMusic();
310 void _stopBossFightMusic();
318 void _gameOverSound();
324 void _closeConnection();
329 std::unordered_map<std::type_index, std::vector<std::any>> _ecsEntities;
334 unsigned int _windowWidth;
335 unsigned int _windowHeight;
337 bool _windowFullscreen;
338 std::string _windowTitle;
339 unsigned int _windowX;
340 unsigned int _windowY;
341 std::string _windowCursorIcon;
343 bool _spriteStartTop;
344 bool _spriteStartLeft;
348 unsigned int _spriteWidth;
349 unsigned int _spriteHeight;
350 unsigned int _windowFrameLimit;
353 unsigned int _maximumPortRange = 64738;
356 std::uint32_t _baseId = 0;
359 std::string _configFilePath =
"client_config.toml";
363 unsigned int _iconIndex = 0;
364 unsigned int _loadingIndex = 0;
365 unsigned int _mainEventIndex = 0;
366 unsigned int _mainWindowIndex = 0;
367 unsigned int _titleFontIndex = 0;
368 unsigned int _bodyFontIndex = 0;
369 unsigned int _defaultFontIndex = 0;
370 unsigned int _buttonFontIndex = 0;
373 std::string _mainMenuKey =
"mainMenuButton";
379 bool _gameMusicStarted =
false;
380 bool _mainMenuMusicStarted =
false;
381 bool _bossFightMusicStarted =
false;
384 bool _connected =
false;
387 const std::string _ipV4FirstChunkKey =
"connectionAddressScreenIpV4FirstChunk";
388 const std::string _ipV4SecondChunkKey =
"connectionAddressScreenIpV4SecondChunk";
389 const std::string _ipV4ThirdChunkKey =
"connectionAddressScreenIpV4ThirdChunk";
390 const std::string _ipV4FourthChunkKey =
"connectionAddressScreenIpV4FourthChunk";
391 const std::string _portV4ChunkKey =
"connectionAddressScreenPortV4ChunkKey";
394 std::shared_ptr<GUI::Network::ThreadCapsule> _networkManager;
395 std::vector<GUI::Network::MessageNode> _bufferPackets;
399 bool _demoInitialised =
false;
400 bool _demoStarted =
false;
404 bool _onlineInitialised =
false;
405 bool _onlineStarted =
false;
406 bool _networkClassSet =
false;
407 bool _connectionInitialised =
false;
410 bool _playMusic =
true;
414 const std::string _playMusicToken =
"settingsWindowPlayMusicButton";
415 const std::string _playSoundEffectsToken =
"settingsWindowPlaySoundEffectsButton";
ActiveScreen
This is the enum class in charge of the window switcher code. This enum allows the mainloop of the pr...
This is the file in charge of containing the constants that are meant to be used throughout the progr...
File in charge of containing the custom errors that are going to be used for custom description error...
The file in charge of storing the files for the internal singleplayer demo.
This is the file that links the EntityNode children.
Header file for the EventManager class, responsible for managing input events.
Macro definitions for logging messages with varying levels of detail and formatting.
#define PRETTY_DEBUG
Debug log with details and colour.
#define PRETTY_INFO
Info log with details and colour.
#define PRETTY_CRITICAL
Critical log with details and colour.
This is the file in charge of containing the Log class (the one in charge of outputing info only when...
This is the file in charge of linking the child network ressource classes.
File in charge of containing the declarations for the ressources used in the online game.
void DisplayVersion(bool helpMode=false)
Displays version information for the program.
int RealMain(int argc, char **argv)
The main function for initializing and running the application.
void DisplayHelp(const std::string binName)
The main function of the help display.
Declaration of the SoundLib class for managing sounds in the ECS architecture.
Contains the TOMLLoader class for handling loading and navigation of TOML data.
Header file for the Window class, which handles the graphical window and rendering logic.
The Orchestrator class manages the overall game state, including entity creation, updates,...
The Orchestrator class manages the overall game state, including entity creation, updates,...
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
static const Colour Yellow
static const Colour Black
static const Colour White
static const Colour AliceBlue
Manages font entities in the GUI ECS.
The Main class is the main class of the program.
void run()
This is the function used to start the program's main section.
bool getWindowCursor()
Get the status of the window cursor.
const std::string getIp()
Get the value of the ip that was set.
const unsigned int getPort()
Get the value of the port.
std::tuple< unsigned int, unsigned int > getWindowPosition()
Get the window's position.
void setWindowFullscreen(bool fullscreen)
Start the window in full screen mode.
const ActiveScreen getActiveScreen() const
Function in charge of returning the screen that is currently active.
const std::string & getWindowCursorIcon()
Get the icon to display for the window's cursor.
void setWindowCursor(bool cursorVisible)
Set if the cursor is visible when in the window.
std::tuple< unsigned int, unsigned int > getWindowSize()
Get the windows dimensions.
void setDebug(const bool debug)
Toggle the debug mode for the program.
const std::string getActiveScreenAsString() const
Function in charge of returning the screen that is currently active but here, the type will be conver...
void setWindowCursorSprite(bool imageIsSprite)
Set if the image passed is of type sprite or not.
bool getWindowCursorSprite()
Get the status if the cursor is of type image or spritesheet.
~Main()
Destroy the Main:: Main object.
bool getWindowCursorSpriteReadFromLeft()
Get if the program is supposed to read from the left or the rigth.
unsigned int getWindowCursorSpriteWidth()
Get the width of the sprite texture.
void setWindowPositionX(unsigned int x)
Set the X position of the window.
void setWindowCursorSpriteReadFromTop(bool spriteStartTop)
Inform if the animation should start from the top.
void setFrameLimit(unsigned int frameLimit)
The function in charge of setting the frame Limit.
void setWindowCursorIcon(const std::string cursorImage)
Set the icon of the cursor (if the user wishes to change the default icon)
void setWindowCursorSpriteWidth(unsigned int spriteWidth)
Set the height for the sprite's overlay texture, which is used to draw the sprite's texture during an...
void setIp(const std::string &ip)
This is the function in charge of setting the ip on which the GUI is going to use to communicate abou...
std::string getConfigFile() const
Function in charge of returning the path to the config file.
unsigned int getWindowCursorSpriteHeight()
Get the height of the sprite texture.
void setWindowSize(unsigned int width, unsigned int height)
The window width and height that will be created.
bool getWindowFullscreen()
Get the status of the window (if it is in fullscreen)
const std::string getPlayer() const
Retrieves the player's name.
void setPlayer(const std::string &player)
Sets the player's name.
void setWindowPosition(unsigned int x, unsigned int y)
Set the position of the window.
unsigned int getWindowHeight()
Get the value of the window height.
unsigned int getFrameLimit() const
Function in charge of returning the current frame limit.
void setWindowHeight(unsigned int height)
Set the height of the window.
void setWindowCursorSpriteHeight(unsigned int spriteHeight)
Set the height for the sprite's overlay texture, which is used to draw the sprite's texture during an...
void setPort(const unsigned int port)
Set the port on which the GUI is going to connect to.
void setConfigFile(const std::string &configFile)
This is the function in charge of seting the config filepath.
void setWindowPositionY(unsigned int y)
Set the Y position of the window.
void setActiveScreen(const ActiveScreen screen)
Function in charge of updating the type of screen that is supposed to be displayed as well as change ...
void setLog(const bool debug)
Toggle the logging mode for the program.
bool getWindowCursorSpriteReadFromTop()
Get if the program is supposed to read from the top or not.
const std::string & getWindowTitle()
Get the title of the window.
const bool getLog() const
The function in charge of returning the status of the logging variable.
void setWindowWidth(unsigned int width)
Set the width of the window.
void setWindowTitle(const std::string &title)
Set the title of the window.
const bool getDebug() const
The function in charge of returning the status of the debug variable.
void setWindowCursorSpriteReadFromLeft(bool spriteStartLeft)
Inform if the animation should start from the left.
Main(const std::string &ip="127.0.0.1", unsigned int port=9000, unsigned int windowWidth=800, unsigned int windowHeight=600, bool windowCursor=true, bool windowFullscreen=false, const std::string &windowTitle="R-Type", unsigned int windowX=0, unsigned int windowY=0, const std::string &windowCursorIcon="NULL", bool imageIsSprite=false, bool spriteStartTop=false, bool spriteStartLeft=false, unsigned int spriteWidth=20, unsigned int spriteHeight=20, unsigned int frameLimit=60, const std::string &configFilePath="client_config.toml", const bool log=false, const bool debug=false, const std::string &player="Player")
Constructor for the Main class.
unsigned int getWindowWidth()
Get the value of the window width.
A utility class for parsing, navigating, and managing TOML files and data.
const toml::node_type getValueType(const std::string &key) const
Retrieves the type of a value for a specific key as a TOML node type.
const toml::table getRawTOML() const
Retrieves the raw TOML table.
const std::string getTOMLPath() const
Retrieves the path of the loaded TOML file.
toml::table getTable(const std::string &key) const
Retrieves a TOML table for a specific key.
const bool hasKey(const std::string &key) const
Checks if a specific key exists in the TOML data.
const std::string getValueTypeAsString(const std::string &key) const
Retrieves the type of a value for a specific key as a string.
const std::string getTypeAsString(const std::string &key) const
Retrieves the type of a value for a specific key as a string (alias).
This is the file that links the Components children.
This is the file that links the utility children ressources.