mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 05:43:43 +00:00
Config now gets read by the GameInternal.cpp
Made the process of adding a custom Config file work via a Virtual function within Game.h
This commit is contained in:
parent
9247b8df8a
commit
5e48f4e34f
@ -12,7 +12,9 @@ public:
|
||||
|
||||
void init();
|
||||
|
||||
void setCustomConfig(std::string path);
|
||||
void setCustomConfig(const std::optional<std::string>& path);
|
||||
|
||||
json getFinalConfig();
|
||||
|
||||
private:
|
||||
json baseConfig;
|
||||
|
||||
@ -9,6 +9,7 @@ public:
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void update(uint_fast16_t diffTime) = 0;
|
||||
virtual std::optional<std::string> getConfigFilePath() {return std::nullopt;}
|
||||
|
||||
GameInternal* gameInternal; //!< \deprecated
|
||||
};
|
||||
|
||||
@ -6,6 +6,8 @@ ConfigLoader::ConfigLoader() {
|
||||
baseConfig = loadConfigFromJSON("config.json");
|
||||
}
|
||||
|
||||
ConfigLoader::~ConfigLoader() {}
|
||||
|
||||
void ConfigLoader::init() {
|
||||
if (!customConfig.has_value()) {
|
||||
finalConfig = baseConfig;
|
||||
@ -27,8 +29,8 @@ json ConfigLoader::loadConfigFromJSON(const std::string& path) {
|
||||
}
|
||||
|
||||
|
||||
void ConfigLoader::setCustomConfig(std::string path) {
|
||||
customConfig.emplace(loadConfigFromJSON(path));
|
||||
void ConfigLoader::setCustomConfig(const std::optional<std::string>& path) {
|
||||
customConfig = path;
|
||||
}
|
||||
|
||||
json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) {
|
||||
@ -38,4 +40,9 @@ json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) {
|
||||
return baseConfig;
|
||||
}
|
||||
|
||||
json ConfigLoader::getFinalConfig() {
|
||||
return finalConfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
|
||||
#include <VEGO.h>
|
||||
|
||||
#include "ConfigLoader.h"
|
||||
|
||||
GameInternal::GameInternal() :
|
||||
manager(this),
|
||||
renderManager(),
|
||||
@ -29,13 +31,19 @@ GameInternal::~GameInternal() = default;
|
||||
|
||||
SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
|
||||
{
|
||||
this->gameInstance = GameFactory::instance().create(this);
|
||||
ConfigLoader().setCustomConfig(this->gameInstance->getConfigFilePath());
|
||||
ConfigLoader().init();
|
||||
|
||||
json config = ConfigLoader().getFinalConfig();
|
||||
|
||||
GameInternal::assets = new AssetManager(&manager);
|
||||
GameInternal::textureManager = new TextureManager(&manager);
|
||||
GameInternal::soundManager = new SoundManager();
|
||||
GameInternal::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
|
||||
|
||||
int flags = 0;
|
||||
if (fullscreen)
|
||||
if (config.at("fullscreen"))
|
||||
{
|
||||
flags = SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
@ -95,7 +103,6 @@ SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int widt
|
||||
// loading music
|
||||
// assets->addMusic("background_music", "assets/sound/background_music.mp3");
|
||||
|
||||
this->gameInstance = GameFactory::instance().create(this);
|
||||
this->gameInstance->init();
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user