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

master
Zed A. Shaw 10 months ago
parent a20d701096
commit 7ffa6025ce
  1. 12
      autowalker.cpp
  2. 94
      game_level.cpp
  3. 7
      game_level.hpp
  4. 4
      gui/debug_ui.cpp
  5. 2
      gui/fsm.cpp
  6. 4
      gui/main_ui.cpp
  7. 2
      gui/status_ui.cpp
  8. 34
      systems.cpp
  9. 2
      tests/lighting.cpp
  10. 4
      tests/map.cpp
  11. 2
      tests/matrix.cpp

@ -9,7 +9,7 @@ int number_left() {
GameDB::current_world()->query<components::Position, Comp>(
[&](const auto ent, auto&, auto&) {
if(ent != GameDB::current().player) {
if(ent != GameDB::current_level().player) {
count++;
}
});
@ -19,15 +19,15 @@ int number_left() {
template<typename Comp>
Pathing compute_paths() {
auto& walls_original = GameDB::current().map->$walls;
auto& walls_original = GameDB::current_level().map->$walls;
auto walls_copy = walls_original;
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)};
GameDB::current().world->query<components::Position>(
GameDB::current_level().world->query<components::Position>(
[&](const auto ent, auto& position) {
if(ent != GameDB::current().player) {
if(GameDB::current().world->has<Comp>(ent)) {
if(ent != GameDB::current_level().player) {
if(GameDB::current_level().world->has<Comp>(ent)) {
paths.set_target(position.location);
} else {
// this will mark that spot as a wall so we don't path there temporarily
@ -110,7 +110,7 @@ bool Autowalker::path_player(Pathing& paths, Point& target_out) {
}
}
if(!GameDB::current().map->can_move(target_out)) {
if(!GameDB::current_level().map->can_move(target_out)) {
path_fail(paths.$paths, target_out);
return false;
}

@ -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,42 +73,55 @@ 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();
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);
if(!initialized) {
LDB = make_shared<LevelDB>();
initialized = true;
new_level(NULL);
}
}
Level &previous() {
shared_ptr<DinkyECS::World> current_world() {
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);
return current_level().world;
}
Level &current() {
shared_ptr<gui::BossFightUI> create_bossfight() {
dbc::check(initialized, "Forgot to call GameDB::init()");
return LDB->levels.at(LDB->current_level);
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 current_index() {
Level& create_level() {
dbc::check(initialized, "Forgot to call GameDB::init()");
return LDB->current_level;
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 &get(size_t index) {
Level &current_level() {
dbc::check(initialized, "Forgot to call GameDB::init()");
return LDB->levels.at(index);
return LDB->levels.at(LDB->current_level);
}
components::Position& player_position() {
@ -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;
}
}

@ -24,16 +24,11 @@ namespace GameDB {
};
std::shared_ptr<gui::BossFightUI> create_bossfight();
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world);
Level& create_level();
void init();
Level &next();
Level &previous();
Level &current();
size_t current_index();
Level &current_level();
std::shared_ptr<DinkyECS::World> current_world();
Level &get(size_t index);
components::Position& player_position();
DinkyECS::Entity the_player();
}

@ -46,7 +46,7 @@ namespace gui {
void DebugUI::render(sf::RenderWindow& window) {
if(active) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto player = level.world->get_the<components::Player>();
auto player_combat = level.world->get<components::Combat>(player.entity);
auto map = level.map;
@ -76,7 +76,7 @@ namespace gui {
active = !active;
if(active) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
// it's on now, enable things
auto player = level.world->get_the<components::Player>();
auto& player_combat = level.world->get<components::Combat>(player.entity);

@ -267,7 +267,7 @@ namespace gui {
}
void FSM::try_move(int dir, bool strafe) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
using enum State;
// prevent moving into occupied space
Point move_to = $main_ui.plan_move(dir, strafe);

@ -32,7 +32,7 @@ namespace gui {
}
DinkyECS::Entity MainUI::camera_aim() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
// what happens if there's two things at that spot
if(level.collision->something_there($rayview->aiming_at)) {
return level.collision->get($rayview->aiming_at);
@ -98,7 +98,7 @@ namespace gui {
}
void MainUI::update_level() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& player_position = GameDB::player_position();
auto player = player_position.location;

@ -112,7 +112,7 @@ namespace gui {
}
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& slot_name = $gui.name_for(gui_id);
auto& inventory = level.world->get<inventory::Model>(level.player);

@ -33,7 +33,7 @@ void System::set_position(World& world, SpatialMap& collision, Entity entity, Po
}
void System::lighting() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& light = *level.lights;
auto& world = *level.world;
auto& map = *level.map;
@ -57,7 +57,7 @@ void System::lighting() {
}
void System::generate_paths() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
const auto &player_pos = GameDB::player_position();
level.map->set_target(player_pos.location);
@ -65,7 +65,7 @@ void System::generate_paths() {
}
void System::enemy_ai_initialize() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto& map = *level.map;
@ -93,7 +93,7 @@ void System::enemy_ai_initialize() {
}
void System::enemy_pathing() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto& map = *level.map;
const auto &player_pos = GameDB::player_position();
@ -135,7 +135,7 @@ inline void move_entity(SpatialMap &collider, Map &game_map, Position &position,
}
void System::motion() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
level.world->query<Position, Motion>(
[&](auto ent, auto &position, auto &motion) {
// don't process entities that don't move
@ -146,7 +146,7 @@ void System::motion() {
}
void System::distribute_loot(Position target_pos) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto& config = world.get_the<GameConfig>();
int inventory_count = Random::uniform(0, 3);
@ -171,7 +171,7 @@ void System::distribute_loot(Position target_pos) {
}
void System::death() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto player = world.get_the<Player>();
std::vector<Entity> dead_things;
@ -229,7 +229,7 @@ inline void animate_entity(World &world, Entity entity) {
}
void System::combat(int attack_id) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& collider = *level.collision;
auto& world = *level.world;
auto& the_belt = world.get_the<ritual::Belt>();
@ -286,7 +286,7 @@ void System::combat(int attack_id) {
void System::collision() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& collider = *level.collision;
auto& world = *level.world;
const auto& player_pos = GameDB::player_position();
@ -319,7 +319,7 @@ void System::collision() {
* from the world for say, putting into a container or inventory.
*/
void System::remove_from_world(Entity entity) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& item_pos = level.world->get<Position>(entity);
level.collision->remove(item_pos.location, entity);
// if you don't do this you get the bug that you can pickup
@ -328,7 +328,7 @@ void System::remove_from_world(Entity entity) {
}
void System::pickup() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto& collision = *level.collision;
auto pos = GameDB::player_position();
@ -393,7 +393,7 @@ void System::device(World &world, Entity actor, Entity item) {
}
void System::plan_motion(Position move_to) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& player_pos = GameDB::player_position();
player_pos.aiming_at = move_to.aiming_at;
@ -405,7 +405,7 @@ void System::plan_motion(Position move_to) {
void System::player_status() {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& combat = level.world->get<Combat>(level.player);
float percent = float(combat.hp) / float(combat.max_hp);
@ -450,7 +450,7 @@ Entity System::spawn_item(World& world, const std::string& name) {
}
void System::drop_item(Entity item) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto& map = *level.map;
auto player_pos = GameDB::player_position();
@ -498,7 +498,7 @@ void System::remove_from_container(Entity cont_id, const std::string& slot_id) {
void System::inventory_swap(Entity container_id, const std::string& a_name, const std::string &b_name) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
dbc::check(a_name != b_name, "Attempt to inventory swap the same slot, you should check this and avoid calling me.");
auto& inventory = level.world->get<inventory::Model>(container_id);
@ -516,7 +516,7 @@ bool System::inventory_occupied(Entity container_id, const std::string& name) {
void System::draw_map(Matrix& grid, EntityGrid& entity_map) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
Map &map = *level.map;
Matrix &fow = level.lights->$fow;
@ -606,7 +606,7 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
}
bool System::use_item(const string& slot_name) {
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& world = *level.world;
auto& inventory = world.get<inventory::Model>(level.player);
auto& player_combat = world.get<Combat>(level.player);

@ -11,7 +11,7 @@ using namespace lighting;
TEST_CASE("lighting a map works", "[lighting]") {
GameDB::init();
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& map = *level.map;
Point light1, light2;

@ -18,7 +18,7 @@ json load_test_data(const string &fname) {
TEST_CASE("camera control", "[map]") {
GameDB::init();
auto& level = GameDB::current();
auto& level = GameDB::current_level();
auto& map = *level.map;
Point center = map.center_camera({10,10}, 5, 5);
@ -81,7 +81,7 @@ TEST_CASE("dijkstra algo test", "[map]") {
TEST_CASE("map image test", "[map]") {
GameDB::init();
auto& level = GameDB::current();
auto& level = GameDB::current_level();
Matrix map_tiles = matrix::make(7,7);
EntityGrid entity_map;

@ -17,7 +17,7 @@ using matrix::Matrix;
std::shared_ptr<Map> make_map() {
GameDB::init();
return GameDB::current().map;
return GameDB::current_level().map;
}
TEST_CASE("basic matrix iterator", "[matrix]") {