Rename to GameDB and GameDB::Level.
This commit is contained in:
parent
c46927ea10
commit
a20d701096
23 changed files with 142 additions and 151 deletions
|
@ -16,12 +16,6 @@ struct LevelScaling {
|
|||
int map_height=20;
|
||||
};
|
||||
|
||||
struct LevelManager {
|
||||
public:
|
||||
std::vector<GameLevel> levels;
|
||||
size_t current_level = 0;
|
||||
};
|
||||
|
||||
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
|
||||
{
|
||||
auto world = make_shared<DinkyECS::World>();
|
||||
|
@ -35,10 +29,16 @@ inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World>
|
|||
return world;
|
||||
}
|
||||
|
||||
namespace Game {
|
||||
namespace GameDB {
|
||||
using std::shared_ptr, std::string, std::make_shared;
|
||||
|
||||
shared_ptr<LevelManager> LMGR;
|
||||
struct LevelDB {
|
||||
public:
|
||||
std::vector<GameDB::Level> levels;
|
||||
size_t current_level = 0;
|
||||
};
|
||||
|
||||
shared_ptr<LevelDB> LDB;
|
||||
bool initialized = false;
|
||||
|
||||
void init() {
|
||||
|
@ -46,7 +46,7 @@ namespace Game {
|
|||
textures::init();
|
||||
|
||||
if(!initialized) {
|
||||
LMGR = make_shared<LevelManager>();
|
||||
LDB = make_shared<LevelDB>();
|
||||
initialized = true;
|
||||
new_level(NULL);
|
||||
}
|
||||
|
@ -54,18 +54,18 @@ namespace Game {
|
|||
|
||||
LevelScaling scale_level() {
|
||||
return {
|
||||
INITIAL_MAP_W + int(LMGR->current_level * 2),
|
||||
INITIAL_MAP_H + int(LMGR->current_level * 2)
|
||||
INITIAL_MAP_W + int(LDB->current_level * 2),
|
||||
INITIAL_MAP_H + int(LDB->current_level * 2)
|
||||
};
|
||||
}
|
||||
|
||||
shared_ptr<DinkyECS::World> current_world() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return current().world;
|
||||
}
|
||||
|
||||
shared_ptr<gui::BossFightUI> create_bossfight() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto prev_world = current_world();
|
||||
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
|
||||
auto world = clone_load_world(prev_world);
|
||||
|
@ -73,7 +73,7 @@ namespace Game {
|
|||
|
||||
// BUG: the jank is too strong here
|
||||
auto boss_names = config.bosses.keys();
|
||||
auto& level_name = boss_names[LMGR->current_level % boss_names.size()];
|
||||
auto& level_name = boss_names[LDB->current_level % boss_names.size()];
|
||||
auto& boss_data = config.bosses[level_name];
|
||||
|
||||
auto boss_id = world->entity();
|
||||
|
@ -83,7 +83,7 @@ namespace Game {
|
|||
}
|
||||
|
||||
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto world = clone_load_world(prev_world);
|
||||
|
||||
auto scaling = scale_level();
|
||||
|
@ -94,71 +94,65 @@ namespace Game {
|
|||
WorldBuilder builder(*map, *collision);
|
||||
builder.generate(*world);
|
||||
|
||||
size_t index = LMGR->levels.size();
|
||||
size_t index = LDB->levels.size();
|
||||
|
||||
auto player = world->get_the<Player>();
|
||||
|
||||
LMGR->levels.emplace_back(index, player.entity, map, world,
|
||||
LDB->levels.emplace_back(index, player.entity, map, world,
|
||||
make_shared<LightRender>(map->tiles()), collision);
|
||||
|
||||
dbc::check(index == LMGR->levels.size() - 1, "Level index is not the same as LMGR->levels.size() - 1, off by one error");
|
||||
dbc::check(index == LDB->levels.size() - 1, "Level index is not the same as LDB->levels.size() - 1, off by one error");
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
GameLevel& create_level() {
|
||||
Level& create_level() {
|
||||
dbc::log("current_level");
|
||||
size_t level = new_level(current_world());
|
||||
dbc::check(level == LMGR->current_level + 1, "new level index is wrong");
|
||||
dbc::check(level == LDB->current_level + 1, "new level index is wrong");
|
||||
auto& the_level = next();
|
||||
dbc::check(level == LMGR->current_level, "level didn't update?!");
|
||||
dbc::check(level == LDB->current_level, "level didn't update?!");
|
||||
return the_level;
|
||||
}
|
||||
|
||||
GameLevel &next() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(LMGR->current_level < LMGR->levels.size(), "attempt to get next level when at end");
|
||||
LMGR->current_level++;
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
Level &next() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
dbc::check(LDB->current_level < LDB->levels.size(), "attempt to get next level when at end");
|
||||
LDB->current_level++;
|
||||
return LDB->levels.at(LDB->current_level);
|
||||
}
|
||||
|
||||
GameLevel &previous() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(LMGR->current_level > 0, "attempt to go to previous level when at 0");
|
||||
LMGR->current_level--;
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
Level &previous() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
dbc::check(LDB->current_level > 0, "attempt to go to previous level when at 0");
|
||||
LDB->current_level--;
|
||||
return LDB->levels.at(LDB->current_level);
|
||||
}
|
||||
|
||||
GameLevel ¤t() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
Level ¤t() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return LDB->levels.at(LDB->current_level);
|
||||
}
|
||||
|
||||
size_t current_index() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LMGR->current_level;
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return LDB->current_level;
|
||||
}
|
||||
|
||||
GameLevel &get(size_t index) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LMGR->levels.at(index);
|
||||
}
|
||||
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named) {
|
||||
(void)named;
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::sentinel("THIS IS BROKEN");
|
||||
Level &get(size_t index) {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return LDB->levels.at(index);
|
||||
}
|
||||
|
||||
components::Position& player_position() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::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()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return current().player;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue