mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
Compare commits
2 Commits
b1c5e2187d
...
eab7dab429
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eab7dab429 | ||
|
|
91f15671c0 |
@ -24,13 +24,11 @@ add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(extern/tmxlite/tmxlite EXCLUDE_FROM_ALL)
|
||||
include_directories(extern/nlohmann_json/include)
|
||||
add_subdirectory(extern/nlohmann_json EXCLUDE_FROM_ALL)
|
||||
|
||||
|
||||
file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp)
|
||||
add_library(${PROJECT_NAME} ${SOURCES}
|
||||
include/ConfigLoader.h
|
||||
src/ConfigLoader.cpp)
|
||||
add_library(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR})
|
||||
|
||||
@ -39,6 +37,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL fu
|
||||
SDL3_image::SDL3_image-static
|
||||
SDL3_mixer::SDL3_mixer-static
|
||||
SDL3_ttf::SDL3_ttf-static
|
||||
nlohmann_json::nlohmann_json
|
||||
tmxlite
|
||||
)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"fullscreen": false,
|
||||
"title": "VGG (Very Good Game)",
|
||||
"height": 100,
|
||||
"width": 100,
|
||||
"screen_height": 100,
|
||||
"screen_width": 100,
|
||||
"icon": "./engine/internalAssets/iconImage.bmp"
|
||||
}
|
||||
@ -17,8 +17,8 @@ public:
|
||||
json getFinalConfig();
|
||||
|
||||
private:
|
||||
json baseConfig;
|
||||
std::optional<json> customConfig;
|
||||
|
||||
std::optional<std::string> customConfigPath;
|
||||
json finalConfig;
|
||||
|
||||
json loadConfigFromJSON(const std::string& path);
|
||||
|
||||
@ -9,7 +9,7 @@ public:
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void update(uint_fast16_t diffTime) = 0;
|
||||
virtual std::optional<std::string> getConfigFilePath() {return std::nullopt;}
|
||||
virtual std::optional<std::string> setConfigFilePath() {return std::nullopt;}
|
||||
|
||||
GameInternal* gameInternal; //!< \deprecated
|
||||
};
|
||||
|
||||
@ -77,8 +77,8 @@ Vector2D AssetManager::calculateSpawnPosition()
|
||||
{
|
||||
SDL_Rect spawnRect;
|
||||
spawnRect.h = spawnRect.w = 32;
|
||||
spawnRect.x = rand() % (VEGO_Game().config->getFinalConfig().at("width").get<int>() - spawnRect.w);
|
||||
spawnRect.y = rand() % (VEGO_Game().config->getFinalConfig().at("height").get<int>() - spawnRect.h);
|
||||
spawnRect.x = rand() % (VEGO_Game().config->getFinalConfig().at("screen_width").get<int>() - spawnRect.w);
|
||||
spawnRect.y = rand() % (VEGO_Game().config->getFinalConfig().at("screen_height").get<int>() - spawnRect.h);
|
||||
conflict = false;
|
||||
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
||||
{
|
||||
|
||||
@ -67,20 +67,20 @@ IntersectionBitSet CollisionHandler::getIntersectionWithBounds(Entity* entity, V
|
||||
|
||||
// all 4 directions and both sides to allow checking for fully out of bounds
|
||||
if (collider->x + posMod.x < 0 ||
|
||||
collider->x + posMod.x > VEGO_Game().config->getFinalConfig().at("width")) {
|
||||
collider->x + posMod.x > VEGO_Game().config->getFinalConfig().at("screen_width")) {
|
||||
intersections.set((size_t) Direction::LEFT);
|
||||
}
|
||||
|
||||
if (collider->x + collider->w + posMod.x < 0 ||
|
||||
collider->x + collider->w + posMod.x > VEGO_Game().config->getFinalConfig().at("width"))
|
||||
collider->x + collider->w + posMod.x > VEGO_Game().config->getFinalConfig().at("screen_width"))
|
||||
intersections.set((size_t) Direction::RIGHT);
|
||||
|
||||
if (collider->y + posMod.y < 0 ||
|
||||
collider->y + posMod.y > VEGO_Game().config->getFinalConfig().at("height"))
|
||||
collider->y + posMod.y > VEGO_Game().config->getFinalConfig().at("screen_height"))
|
||||
intersections.set((size_t) Direction::UP);
|
||||
|
||||
if (collider->y + collider->h + posMod.y < 0 ||
|
||||
collider->y + collider->h + posMod.y > VEGO_Game().config->getFinalConfig().at("height"))
|
||||
collider->y + collider->h + posMod.y > VEGO_Game().config->getFinalConfig().at("screen_height"))
|
||||
intersections.set((size_t) Direction::DOWN);
|
||||
|
||||
return intersections;
|
||||
|
||||
@ -2,20 +2,21 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
ConfigLoader::ConfigLoader() {
|
||||
//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() {}
|
||||
|
||||
void ConfigLoader::init() {
|
||||
if (!customConfig.has_value()) {
|
||||
//TODO: look into adaptive paths for better handling as this requires the implemented game
|
||||
// to have ./engine in the root folder
|
||||
const json baseConfig = loadConfigFromJSON("./engine/config.json");
|
||||
|
||||
if (!customConfigPath.has_value()) {
|
||||
finalConfig = baseConfig;
|
||||
return;
|
||||
}
|
||||
finalConfig = mergeConfigs(baseConfig, customConfig.value());
|
||||
|
||||
finalConfig = mergeConfigs(baseConfig, loadConfigFromJSON(customConfigPath.value()));
|
||||
}
|
||||
|
||||
json ConfigLoader::loadConfigFromJSON(const std::string& path) {
|
||||
@ -32,9 +33,7 @@ json ConfigLoader::loadConfigFromJSON(const std::string& path) {
|
||||
|
||||
|
||||
void ConfigLoader::setCustomConfig(const std::optional<std::string>& path) {
|
||||
if (path.has_value()) {
|
||||
customConfig = loadConfigFromJSON(path.value());
|
||||
}
|
||||
customConfigPath = path;
|
||||
}
|
||||
|
||||
json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) {
|
||||
|
||||
@ -31,10 +31,10 @@ GameInternal::~GameInternal() = default;
|
||||
|
||||
SDL_AppResult GameInternal::init()
|
||||
{
|
||||
config = new ConfigLoader;
|
||||
config = new ConfigLoader();
|
||||
|
||||
this->gameInstance = GameFactory::instance().create(this);
|
||||
config->setCustomConfig(this->gameInstance->getConfigFilePath());
|
||||
config->setCustomConfig(this->gameInstance->setConfigFilePath());
|
||||
config->init();
|
||||
|
||||
json finalConfig = config->getFinalConfig();
|
||||
@ -62,7 +62,9 @@ SDL_AppResult GameInternal::init()
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow(finalConfig.at("title").get<std::string>().c_str(), finalConfig.at("width"), finalConfig.at("height"), flags);
|
||||
window = SDL_CreateWindow(finalConfig.at("title").get<std::string>().c_str(),
|
||||
finalConfig.at("screen_width"), finalConfig.at("screen_height"), flags);
|
||||
|
||||
if (!window)
|
||||
{
|
||||
std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user