And finally fix some of the API names to make more sense in their current location.

This commit is contained in:
Zed A. Shaw 2025-08-20 23:49:30 -04:00
parent a20d701096
commit 7ffa6025ce
11 changed files with 74 additions and 99 deletions

View file

@ -41,17 +41,6 @@ namespace GameDB {
shared_ptr<LevelDB> LDB;
bool initialized = false;
void init() {
components::init();
textures::init();
if(!initialized) {
LDB = make_shared<LevelDB>();
initialized = true;
new_level(NULL);
}
}
LevelScaling scale_level() {
return {
INITIAL_MAP_W + int(LDB->current_level * 2),
@ -59,28 +48,6 @@ namespace GameDB {
};
}
shared_ptr<DinkyECS::World> current_world() {
dbc::check(initialized, "Forgot to call GameDB::init()");
return current().world;
}
shared_ptr<gui::BossFightUI> create_bossfight() {
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);
auto& config = prev_world->get_the<GameConfig>();
// BUG: the jank is too strong here
auto boss_names = config.bosses.keys();
auto& level_name = boss_names[LDB->current_level % boss_names.size()];
auto& boss_data = config.bosses[level_name];
auto boss_id = world->entity();
components::configure_entity(*world, boss_id, boss_data["components"]);
return make_shared<gui::BossFightUI>(world, boss_id);
}
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world) {
dbc::check(initialized, "Forgot to call GameDB::init()");
@ -106,44 +73,57 @@ namespace GameDB {
return index;
}
Level& create_level() {
dbc::log("current_level");
size_t level = new_level(current_world());
dbc::check(level == LDB->current_level + 1, "new level index is wrong");
auto& the_level = next();
dbc::check(level == LDB->current_level, "level didn't update?!");
return the_level;
void init() {
components::init();
textures::init();
if(!initialized) {
LDB = make_shared<LevelDB>();
initialized = true;
new_level(NULL);
}
}
Level &next() {
shared_ptr<DinkyECS::World> current_world() {
dbc::check(initialized, "Forgot to call GameDB::init()");
return current_level().world;
}
shared_ptr<gui::BossFightUI> create_bossfight() {
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);
auto& config = prev_world->get_the<GameConfig>();
// BUG: the jank is too strong here
auto boss_names = config.bosses.keys();
auto& level_name = boss_names[LDB->current_level % boss_names.size()];
auto& boss_data = config.bosses[level_name];
auto boss_id = world->entity();
components::configure_entity(*world, boss_id, boss_data["components"]);
return make_shared<gui::BossFightUI>(world, boss_id);
}
Level& create_level() {
dbc::check(initialized, "Forgot to call GameDB::init()");
dbc::check(LDB->current_level < LDB->levels.size(), "attempt to get next level when at end");
size_t level = new_level(current_world());
dbc::check(level == LDB->current_level + 1, "new level index is wrong");
LDB->current_level++;
return LDB->levels.at(LDB->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);
}
Level &current() {
Level &current_level() {
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 GameDB::init()");
return LDB->current_level;
}
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 GameDB::init()");
auto world = current_world();
@ -153,6 +133,6 @@ namespace GameDB {
DinkyECS::Entity the_player() {
dbc::check(initialized, "Forgot to call GameDB::init()");
return current().player;
return current_level().player;
}
}