Initial changes to clean up the code.

main
Zed A. Shaw 2 weeks ago
parent 8d3ccd935d
commit f3f875ee80
  1. 4
      dinkyecs.hpp
  2. 2
      matrix.cpp
  3. 12
      matrix.hpp
  4. 3
      systems.cpp
  5. 14
      tests/gui.cpp
  6. 6
      tests/inventory.cpp
  7. 6
      tests/matrix.cpp
  8. 3
      worldbuilder.cpp

@ -52,7 +52,7 @@ namespace DinkyECS {
template <typename Comp>
void set_the(Comp val) {
$facts[std::type_index(typeid(Comp))] = val;
$facts.insert_or_assign(std::type_index(typeid(Comp)), val);
}
template <typename Comp>
@ -68,7 +68,7 @@ namespace DinkyECS {
template <typename Comp>
void set(Entity ent, Comp val) {
EntityMap &map = entity_map_for<Comp>();
map[ent] = val;
map.insert_or_assign(ent, val);
}
template <typename Comp>

@ -1,9 +1,9 @@
#include "matrix.hpp"
#include "constants.hpp"
#include "dbc.hpp"
#include <fmt/core.h>
#include <cmath>
#include <cstdlib>
#include "constants.hpp"
using namespace fmt;
using std::min, std::max;

@ -168,6 +168,10 @@ namespace matrix {
size_t bottom = 0;
box_t(MAT &mat, size_t at_x, size_t at_y, size_t size) :
box_t(mat, at_x, at_y, size, size) {
}
box_t(MAT &mat, size_t at_x, size_t at_y, size_t width, size_t height) :
from_x(at_x), from_y(at_y)
{
size_t h = matrix::height(mat);
@ -175,15 +179,15 @@ namespace matrix {
// keeps it from going below zero
// need extra -1 to compensate for the first next()
left = max(from_x, size) - size;
left = max(from_x, width) - width;
x = left - 1; // must be -1 for next()
// keeps it from going above width
right = min(from_x + size + 1, w);
right = min(from_x + width + 1, w);
// same for these two
top = max(from_y, size) - size;
top = max(from_y, height) - height;
y = top - (left == 0);
bottom = min(from_y + size + 1, h);
bottom = min(from_y + height + 1, h);
}
bool next() {

@ -203,6 +203,9 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &
}
void System::pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) {
dbc::pre("System::pickup actor doesn't have inventory", world.has<Inventory>(actor));
dbc::pre("System::pickup item isn't configured with InventoryItem.", world.has<InventoryItem>(item));
auto& inventory = world.get<Inventory>(actor);
auto& invitem = world.get<InventoryItem>(item);

@ -18,19 +18,7 @@ TEST_CASE("load a basic gui run but don't loop", "[gui]") {
save::load_configs(world);
Map game_map(40, 40);
WorldBuilder builder(game_map);
builder.generate_map();
auto &config = world.get_the<GameConfig>();
// configure a player as a fact of the world
Player player{world.entity()};
world.set_the<Player>(player);
world.set<Position>(player.entity, {game_map.place_entity(0)});
world.set<Motion>(player.entity, {0, 0});
world.set<Combat>(player.entity, {100, 10});
world.set<Tile>(player.entity, {config.enemies["PLAYER_TILE"]["display"]});
world.set<Inventory>(player.entity, {5});
world.set<LightSource>(player.entity, {6,1});
builder.generate(world);
SpatialMap collider;
world.set_the<SpatialMap>(collider);

@ -17,9 +17,9 @@ using namespace components;
DinkyECS::Entity add_items(DinkyECS::World &world, GameConfig &config) {
auto sword = world.entity();
world.set<InventoryItem>(sword, {1, config.items["SWORD_RUSTY"]});
world.set<Tile>(sword, {config.items["SWORD_RUSTY"]["display"]});
json& item_data = config.items["SWORD_RUSTY"];
world.set<InventoryItem>(sword, {item_data["inventory_count"], item_data});
components::configure(world, sword, item_data);
return sword;
}

@ -296,11 +296,7 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
for(size_t y = 0; y < end_y; ++y) {
for(size_t x = 0; x < end_x && it.next(); ++x) {
println("view x/y={},{}; w/h={},{}; start={},{}",
it.x, it.y, it.width, it.height, it.start.x, it.start.y);
println("orig x/y={},{}; w/h={},{}; start={},{}\n",
x+start.x, y+start.y, view_width, view_height, start.x, start.y);
// still working on this
}
}
}

@ -191,7 +191,8 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str
auto &config = world.get_the<GameConfig>();
auto enemy = world.entity();
auto enemy_data = config.enemies[name];
world.set<Position>(enemy, {game_map.place_entity(in_room)});
auto pos = game_map.place_entity(in_room);
world.set<Position>(enemy, {pos});
if(enemy_data.contains("components")) {
components::configure(world, enemy, enemy_data);

Loading…
Cancel
Save