Tests are now clean so next step is to officially nuke the level manager.
This commit is contained in:
parent
564f9842a2
commit
5aca2fb56a
8 changed files with 47 additions and 72 deletions
|
@ -9,58 +9,72 @@ namespace Game {
|
|||
bool initialized = false;
|
||||
|
||||
void init() {
|
||||
if(!initialized) {
|
||||
LEVELS = make_shared<LevelManager>();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
LevelManager& get_the_manager() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return *LEVELS;
|
||||
}
|
||||
|
||||
shared_ptr<DinkyECS::World> current_world() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return current().world;
|
||||
}
|
||||
|
||||
shared_ptr<gui::BossFightUI> create_bossfight() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->create_bossfight(current_world());
|
||||
}
|
||||
|
||||
GameLevel& create_level() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
LEVELS->create_level(current_world());
|
||||
return next();
|
||||
}
|
||||
|
||||
GameLevel &next() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->next();
|
||||
}
|
||||
|
||||
GameLevel &previous() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->previous();
|
||||
}
|
||||
|
||||
GameLevel ¤t() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->current();
|
||||
}
|
||||
|
||||
size_t current_index() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->current_index();
|
||||
}
|
||||
|
||||
GameLevel &get(size_t index) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->get(index);
|
||||
}
|
||||
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->spawn_enemy(named);
|
||||
}
|
||||
|
||||
components::Position& player_position() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
auto world = current_world();
|
||||
auto& player = world->get_the<components::Player>();
|
||||
return world->get<components::Position>(player.entity);
|
||||
}
|
||||
|
||||
DinkyECS::Entity the_player() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return current().player;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,23 +18,22 @@ namespace gui {
|
|||
$gui.init();
|
||||
}
|
||||
|
||||
inline void make_clickable_area(std::shared_ptr<DinkyECS::World> world, guecs::UI &gui, const std::string &name) {
|
||||
inline void make_clickable_area(guecs::UI &gui, const std::string &name) {
|
||||
auto area = gui.entity(name);
|
||||
|
||||
gui.set<Clickable>(area, {
|
||||
[&](auto) {
|
||||
auto world = Game::current_world();
|
||||
world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void OverlayUI::init() {
|
||||
auto world = Game::current_world();
|
||||
|
||||
// gui.init is in the constructor
|
||||
make_clickable_area(world, $gui, "top");
|
||||
make_clickable_area(world, $gui, "middle");
|
||||
make_clickable_area(world, $gui, "bottom");
|
||||
make_clickable_area($gui, "top");
|
||||
make_clickable_area($gui, "middle");
|
||||
make_clickable_area($gui, "bottom");
|
||||
}
|
||||
|
||||
void OverlayUI::render(sf::RenderWindow& window) {
|
||||
|
|
|
@ -142,7 +142,6 @@ executable('runtests', sources + [
|
|||
'tests/event_router.cpp',
|
||||
'tests/fsm.cpp',
|
||||
'tests/inventory.cpp',
|
||||
'tests/levelmanager.cpp',
|
||||
'tests/lighting.cpp',
|
||||
'tests/loot.cpp',
|
||||
'tests/map.cpp',
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include "map.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
#include "worldbuilder.hpp"
|
||||
#include "save.hpp"
|
||||
#include "systems.hpp"
|
||||
#include "spatialmap.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using std::string;
|
||||
|
||||
TEST_CASE("basic level manager test", "[levelmanager]") {
|
||||
LevelManager lm;
|
||||
|
||||
// starts off with one already but I need to change that
|
||||
size_t level1 = lm.current_index();
|
||||
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);
|
||||
}
|
|
@ -4,15 +4,16 @@
|
|||
#include <fstream>
|
||||
#include "map.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "game_level.hpp"
|
||||
#include "lights.hpp"
|
||||
#include "point.hpp"
|
||||
|
||||
using namespace lighting;
|
||||
|
||||
TEST_CASE("lighting a map works", "[lighting]") {
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
Game::init();
|
||||
auto& level = Game::current();
|
||||
auto& map = *level.map;
|
||||
|
||||
Point light1, light2;
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@ json load_test_data(const string &fname) {
|
|||
TEST_CASE("camera control", "[map]") {
|
||||
textures::init();
|
||||
components::init();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
Game::init();
|
||||
|
||||
auto& level = Game::current();
|
||||
auto& map = *level.map;
|
||||
|
||||
Point center = map.center_camera({10,10}, 5, 5);
|
||||
|
||||
|
@ -35,21 +36,22 @@ TEST_CASE("camera control", "[map]") {
|
|||
REQUIRE(translation.y == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("map placement test", "[map]") {
|
||||
TEST_CASE("map placement test", "[map-fail]") {
|
||||
textures::init();
|
||||
components::init();
|
||||
for(int i = 0; i < 20; i++) {
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
Game::init();
|
||||
|
||||
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
auto& level = Game::create_level();
|
||||
|
||||
for(size_t rnum = 0; rnum < level.map->room_count(); rnum++) {
|
||||
Point pos;
|
||||
|
||||
REQUIRE(map.place_entity(rnum, pos));
|
||||
REQUIRE(level.map->place_entity(rnum, pos));
|
||||
|
||||
REQUIRE(!map.iswall(pos.x, pos.y));
|
||||
REQUIRE(map.inmap(pos.x, pos.y));
|
||||
REQUIRE(!level.map->iswall(pos.x, pos.y));
|
||||
REQUIRE(level.map->inmap(pos.x, pos.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +89,7 @@ TEST_CASE("map image test", "[map]") {
|
|||
textures::init();
|
||||
Game::init();
|
||||
|
||||
GameLevel level = Game::current();
|
||||
auto& level = Game::current();
|
||||
Matrix map_tiles = matrix::make(7,7);
|
||||
EntityGrid entity_map;
|
||||
|
||||
|
|
|
@ -4,20 +4,21 @@
|
|||
#include "config.hpp"
|
||||
#include "matrix.hpp"
|
||||
#include "rand.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "game_level.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include "map.hpp"
|
||||
#include <memory>
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
using namespace nlohmann;
|
||||
using namespace fmt;
|
||||
using std::string;
|
||||
using matrix::Matrix;
|
||||
|
||||
shared_ptr<Map> make_map() {
|
||||
// BUG? I mean, it's a shared_ptr so it should keep it around but....
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
return level.map;
|
||||
std::shared_ptr<Map> make_map() {
|
||||
Game::init();
|
||||
return Game::current().map;
|
||||
}
|
||||
|
||||
TEST_CASE("basic matrix iterator", "[matrix:basic]") {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <iostream>
|
||||
#include "rituals.hpp"
|
||||
#include "simplefsm.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "ai_debug.hpp"
|
||||
|
||||
TEST_CASE("ritual::Engine basic tests", "[rituals]") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue