Setup for the LevelManager to take charge of all level operations.

main
Zed A. Shaw 15 hours ago
parent 193f5f915e
commit 18a5f6bfa9
  1. 7
      gui.cpp
  2. 1
      gui.hpp
  3. 45
      levelmanager.cpp
  4. 23
      levelmanager.hpp
  5. 3
      map.hpp
  6. 3
      status.txt
  7. 28
      tests/levelmanager.cpp

@ -287,6 +287,9 @@ void GUI::handle_world_events() {
} break; } break;
case eGUI::STAIRS_DOWN: { case eGUI::STAIRS_DOWN: {
auto& device = std::any_cast<Device&>(data); auto& device = std::any_cast<Device&>(data);
next_level();
$status_ui.log(format("Up stairs has test {}.", $status_ui.log(format("Up stairs has test {}.",
(bool)device.config["test"])); (bool)device.config["test"]));
toggle_modal(&$next_level_ui, $next_level); toggle_modal(&$next_level_ui, $next_level);
@ -495,3 +498,7 @@ int GUI::main(bool run_once) {
return 0; return 0;
} }
void GUI::next_level() {
}

@ -158,6 +158,7 @@ public:
void save_world(); void save_world();
void shake(); void shake();
void shutdown(); void shutdown();
void next_level();
int main(bool run_once=false); int main(bool run_once=false);
void pause_screen(); void pause_screen();

@ -1,10 +1,49 @@
#include "levelmanager.hpp" #include "levelmanager.hpp"
#include "worldbuilder.hpp"
#include "constants.hpp"
#include "save.hpp"
using lighting::LightRender;
using std::shared_ptr, std::make_shared;
LevelManager::LevelManager() { LevelManager::LevelManager() {
// does nothing yet
} }
size_t LevelManager::create_level() {
GameLevel level;
level.index = $levels.size();
level.world = make_shared<DinkyECS::World>();
save::load_configs(*level.world);
level.map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y);
WorldBuilder builder(*level.map);
builder.generate(*level.world);
level.lights = make_shared<LightRender>(level.map->width(), level.map->height());
$levels.push_back(level);
dbc::check(level.index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error");
return level.index;
}
GameLevel &LevelManager::next() {
dbc::check($current_level < $levels.size(), "attempt to get next level when at end");
$current_level++;
return $levels.at($current_level);
}
GameLevel &LevelManager::previous() {
dbc::check($current_level > 0, "attempt to go to previous level when at 0");
$current_level--;
return $levels.at($current_level);
}
GameLevel &LevelManager::current() {
return $levels.at($current_level);
}
void LevelManager::create_level() { GameLevel &LevelManager::get(size_t index) {
// does nothing yet return $levels.at(index);
} }

@ -1,9 +1,30 @@
#pragma once #pragma once
#include "dinkyecs.hpp"
#include "lights.hpp"
#include "map.hpp"
#include <vector>
#include <memory>
struct GameLevel {
size_t index = 0;
std::shared_ptr<Map> map = nullptr;
std::shared_ptr<DinkyECS::World> world = nullptr;
std::shared_ptr<lighting::LightRender> lights = nullptr;
};
class LevelManager { class LevelManager {
public:
std::vector<GameLevel> $levels;
size_t $current_level = 0;
LevelManager(); LevelManager();
void create_level(); size_t create_level();
GameLevel &next();
GameLevel &previous();
GameLevel &current();
size_t current_index();
GameLevel &get(size_t index);
}; };

@ -39,9 +39,6 @@ public:
Map(Matrix &walls, Pathing &paths); Map(Matrix &walls, Pathing &paths);
// disable copying
Map(Map &map) = delete;
Matrix& paths() { return $paths.paths(); } Matrix& paths() { return $paths.paths(); }
TileMap& tiles() { return $tiles; } TileMap& tiles() { return $tiles; }
Matrix& input_map() { return $paths.input(); } Matrix& input_map() { return $paths.input(); }

@ -1,5 +1,6 @@
TODAY'S GOAL: TODO:
* What's the result of out of memory error with shared/unique ptr?
* Config is all over the place. Can I get rid of constant.hpp? Or most of it? Also renderer.cpp:RenderConfig is weird too. Too much indirection all around. * Config is all over the place. Can I get rid of constant.hpp? Or most of it? Also renderer.cpp:RenderConfig is weird too. Too much indirection all around.
* GUI needs to become a statemachine now. Too many panels open at too many times. * GUI needs to become a statemachine now. Too many panels open at too many times.
* Panels should be able to take a width/height and center theirself for me * Panels should be able to take a width/height and center theirself for me

@ -10,9 +10,31 @@
#include "levelmanager.hpp" #include "levelmanager.hpp"
using namespace fmt; using namespace fmt;
using namespace components;
using std::string; using std::string;
TEST_CASE("", "[levelmanager]") { TEST_CASE("basic level manager test", "[levelmanager]") {
// empty test to get setup LevelManager lm;
size_t level1 = lm.create_level();
size_t level2 = lm.create_level();
auto& test1_level = lm.get(level1);
auto& test2_level = lm.get(level2);
REQUIRE(test1_level.map->width() > 0);
REQUIRE(test1_level.map->height() > 0);
REQUIRE(test1_level.index == 0);
REQUIRE(test2_level.map->width() > 0);
REQUIRE(test2_level.map->height() > 0);
REQUIRE(test2_level.index == 1);
auto& cur_level = lm.current();
REQUIRE(cur_level.index == 0);
auto& next_level = lm.next();
REQUIRE(next_level.index == 1);
auto& prev_level = lm.previous();
REQUIRE(prev_level.index == 0);
} }

Loading…
Cancel
Save