0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

Compare commits

...

5 Commits

Author SHA1 Message Date
freezarite
84cee5e307 removed no longer used variables in Constants.h
updated _Init.cpp to use updated init() function from GameInternal.cpp
2024-12-16 06:21:26 +01:00
freezarite
55b60624c4 added a folder to hold internal assets for the standard config of the engine 2024-12-16 06:10:31 +01:00
freezarite
1f3cf01419 fixed a bug with the implementation of the nlohmann library in the CMakeLists.txt
fixed a bug where the config was not loaded correctly in the GameInternal.cpp
2024-12-16 06:08:52 +01:00
freezarite
691ea06eb0 Added and implemented some more config options in the GameInternal.cpp. Also removed GameInternal::init() parameters as they are no longer needed 2024-12-16 06:02:58 +01:00
freezarite
acdbf29896 Fixed a bug where the custom json was not loaded correctly
Changed base config location to ./engine/config.json to make implementation better for the game-dev
2024-12-16 05:47:28 +01:00
8 changed files with 23 additions and 17 deletions

View File

@ -24,7 +24,7 @@ add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL)
add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL)
add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL)
add_subdirectory(extern/tmxlite/tmxlite EXCLUDE_FROM_ALL) add_subdirectory(extern/tmxlite/tmxlite EXCLUDE_FROM_ALL)
add_subdirectory(extern/nlohmann_json EXCLUDE_FROM_ALL) include_directories(extern/nlohmann_json/include)
file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp)
@ -40,7 +40,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL fu
SDL3_mixer::SDL3_mixer-static SDL3_mixer::SDL3_mixer-static
SDL3_ttf::SDL3_ttf-static SDL3_ttf::SDL3_ttf-static
tmxlite tmxlite
nlohmann_json::nlohmann_json
) )
if(CMAKE_BUILD_TYPE MATCHES "Debug") if(CMAKE_BUILD_TYPE MATCHES "Debug")

View File

@ -1,3 +1,7 @@
{ {
"fullscreen": false "fullscreen": false,
"title": "VGG (Very Good Game)",
"height": 100,
"width": 100,
"icon": "./engine/internalAssets/iconImage.bmp"
} }

View File

@ -11,9 +11,6 @@ constexpr std::size_t MAX_GROUPS = 32;
constexpr std::size_t MAX_STATS = 8; constexpr std::size_t MAX_STATS = 8;
constexpr std::size_t MAX_TEAMS = 8; constexpr std::size_t MAX_TEAMS = 8;
constexpr int SCREEN_SIZE_HEIGHT = 640;
constexpr int SCREEN_SIZE_WIDTH = 800;
constexpr int FPS = 60; constexpr int FPS = 60;
constexpr int TILE_SIZE = 32; constexpr int TILE_SIZE = 32;

View File

@ -27,7 +27,7 @@ public:
GameInternal(); GameInternal();
~GameInternal(); ~GameInternal();
SDL_AppResult init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen); SDL_AppResult init();
void handleEvents(); void handleEvents();
void update(Uint64 frameTime); void update(Uint64 frameTime);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -3,7 +3,9 @@
#include <fstream> #include <fstream>
ConfigLoader::ConfigLoader() { ConfigLoader::ConfigLoader() {
baseConfig = loadConfigFromJSON("config.json"); //TODO: look into adaptive paths for better handling as this requires the implemented game
// to have ./engine in the root folder
baseConfig = loadConfigFromJSON("./engine/config.json");
} }
ConfigLoader::~ConfigLoader() {} ConfigLoader::~ConfigLoader() {}
@ -30,7 +32,9 @@ json ConfigLoader::loadConfigFromJSON(const std::string& path) {
void ConfigLoader::setCustomConfig(const std::optional<std::string>& path) { void ConfigLoader::setCustomConfig(const std::optional<std::string>& path) {
customConfig = path; if (path.has_value()) {
customConfig = loadConfigFromJSON(path.value());
}
} }
json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) { json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) {

View File

@ -29,13 +29,15 @@ GameInternal::GameInternal() :
GameInternal::~GameInternal() = default; GameInternal::~GameInternal() = default;
SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen) SDL_AppResult GameInternal::init()
{ {
this->gameInstance = GameFactory::instance().create(this); ConfigLoader* loader = new ConfigLoader();
ConfigLoader().setCustomConfig(this->gameInstance->getConfigFilePath());
ConfigLoader().init();
json config = ConfigLoader().getFinalConfig(); this->gameInstance = GameFactory::instance().create(this);
loader->setCustomConfig(this->gameInstance->getConfigFilePath());
loader->init();
json config = loader->getFinalConfig();
GameInternal::assets = new AssetManager(&manager); GameInternal::assets = new AssetManager(&manager);
GameInternal::textureManager = new TextureManager(&manager); GameInternal::textureManager = new TextureManager(&manager);
@ -60,7 +62,7 @@ SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int widt
return SDL_APP_FAILURE; return SDL_APP_FAILURE;
} }
window = SDL_CreateWindow(title, width, height, flags); window = SDL_CreateWindow(config.at("title").get<std::string>().c_str(), config.at("width"), config.at("height"), flags);
if (!window) if (!window)
{ {
std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl; std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl;
@ -70,7 +72,7 @@ SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int widt
// bad // bad
SDL_Surface* icon; SDL_Surface* icon;
if((icon = SDL_LoadBMP("assets/iconImage.bmp"))) if((icon = SDL_LoadBMP(config.at("icon").get<std::string>().c_str())))
{ {
SDL_SetWindowIcon(window, icon); SDL_SetWindowIcon(window, icon);
} }

View File

@ -19,7 +19,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
*appstate = vego::game = new GameInternal(); *appstate = vego::game = new GameInternal();
return vego::game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false); return vego::game->init();
} }
SDL_AppResult SDL_AppIterate(void *appstate) { SDL_AppResult SDL_AppIterate(void *appstate) {