Did a full code review to identify things to fix and either fixed them or noted BUG where I should come back.

This commit is contained in:
Zed A. Shaw 2024-12-04 21:43:59 -05:00
parent ae43dad499
commit 9abb39a3bf
14 changed files with 72 additions and 35 deletions

View file

@ -25,6 +25,7 @@ void System::lighting(DinkyECS::World &world, Map &game_map, LightRender &light,
light.set_light_target(position.location);
});
// BUG: some light doesn't move, can I not path those?
light.path_light(game_map.walls());
world.query<Position, LightSource>([&](const auto &ent, auto &position, auto &lightsource) {
@ -44,6 +45,7 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player
if(ent != player.entity) {
Point out = position.location; // copy
if(game_map.distance(out) < config.HEARING_DISTANCE) {
// BUG: is neighbors really the best name for this?
game_map.neighbors(out);
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
}
@ -55,6 +57,8 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player
void System::init_positions(DinkyECS::World &world) {
auto &collider = world.get_the<spatial_map>();
// BUG: instead of separate things maybe just one
// BUG: Collision component that references what is collide
world.query<Position, Combat>([&](const auto &ent, auto &pos, auto &combat) {
if(!combat.dead) {
collider.insert(pos.location, ent);
@ -95,6 +99,10 @@ void System::motion(DinkyECS::World &world, Map &game_map) {
}
void System::death(DinkyECS::World &world) {
// BUG: this is where entities can die on top of
// BUG: eachother and overlap their corpse
// BUG: maybe that can be allowed and looting just shows
// BUG: all dead things there?
auto &collider = world.get_the<spatial_map>();
world.query<Position, Combat>([&](const auto &ent, auto &position, auto &combat) {
@ -119,7 +127,6 @@ void System::collision(DinkyECS::World &world, Player &player) {
auto [found, nearby] = collider.neighbors(player_position.location);
if(found) {
for(auto entity : nearby) {
if(world.has<Combat>(entity)) {
auto& enemy_combat = world.get<Combat>(entity);
@ -134,6 +141,7 @@ void System::collision(DinkyECS::World &world, Player &player) {
auto loot = world.get<Loot>(entity);
auto &loot_pos = world.get<Position>(entity);
auto &inventory = world.get<Inventory>(player.entity);
// BUG: this should go away and be a part of inventory
auto &light = world.get<LightSource>(player.entity);
world.send<Events::GUI>(Events::GUI::LOOT, entity, loot);
@ -148,7 +156,9 @@ void System::collision(DinkyECS::World &world, Player &player) {
}
}
// BUG: this is kind of massive, need to maybe rethink how systems are designed. I mean...can each system be a callable class instead?
void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) {
world.query<Position, Tile>([&](const auto &ent, auto &pos, auto &tile) {
if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x
&& pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y) {
@ -156,6 +166,8 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &
int light_value = lighting[pos.location.y][pos.location.x];
// BUG: foreground color needs to come from entity and background color from the surface they're on
// the 2 and 4 are from ftxui::Canvas since it does a kind of "subpixel" drawing
canvas.DrawText(loc.x*2, loc.y*4, tile.chr, [light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(255, 200, light_value + 20);