Initial changes to clean up the code.
This commit is contained in:
parent
8d3ccd935d
commit
f3f875ee80
8 changed files with 21 additions and 29 deletions
|
@ -52,7 +52,7 @@ namespace DinkyECS {
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
void set_the(Comp val) {
|
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>
|
template <typename Comp>
|
||||||
|
@ -68,7 +68,7 @@ namespace DinkyECS {
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
void set(Entity ent, Comp val) {
|
void set(Entity ent, Comp val) {
|
||||||
EntityMap &map = entity_map_for<Comp>();
|
EntityMap &map = entity_map_for<Comp>();
|
||||||
map[ent] = val;
|
map.insert_or_assign(ent, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "matrix.hpp"
|
#include "matrix.hpp"
|
||||||
#include "constants.hpp"
|
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include "constants.hpp"
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using std::min, std::max;
|
using std::min, std::max;
|
||||||
|
|
12
matrix.hpp
12
matrix.hpp
|
@ -168,6 +168,10 @@ namespace matrix {
|
||||||
size_t bottom = 0;
|
size_t bottom = 0;
|
||||||
|
|
||||||
box_t(MAT &mat, size_t at_x, size_t at_y, size_t size) :
|
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)
|
from_x(at_x), from_y(at_y)
|
||||||
{
|
{
|
||||||
size_t h = matrix::height(mat);
|
size_t h = matrix::height(mat);
|
||||||
|
@ -175,15 +179,15 @@ namespace matrix {
|
||||||
|
|
||||||
// keeps it from going below zero
|
// keeps it from going below zero
|
||||||
// need extra -1 to compensate for the first next()
|
// 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()
|
x = left - 1; // must be -1 for next()
|
||||||
// keeps it from going above width
|
// keeps it from going above width
|
||||||
right = min(from_x + size + 1, w);
|
right = min(from_x + width + 1, w);
|
||||||
|
|
||||||
// same for these two
|
// same for these two
|
||||||
top = max(from_y, size) - size;
|
top = max(from_y, height) - height;
|
||||||
y = top - (left == 0);
|
y = top - (left == 0);
|
||||||
bottom = min(from_y + size + 1, h);
|
bottom = min(from_y + height + 1, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool next() {
|
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) {
|
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& inventory = world.get<Inventory>(actor);
|
||||||
auto& invitem = world.get<InventoryItem>(item);
|
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);
|
save::load_configs(world);
|
||||||
Map game_map(40, 40);
|
Map game_map(40, 40);
|
||||||
WorldBuilder builder(game_map);
|
WorldBuilder builder(game_map);
|
||||||
builder.generate_map();
|
builder.generate(world);
|
||||||
|
|
||||||
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});
|
|
||||||
|
|
||||||
SpatialMap collider;
|
SpatialMap collider;
|
||||||
world.set_the<SpatialMap>(collider);
|
world.set_the<SpatialMap>(collider);
|
||||||
|
|
|
@ -17,9 +17,9 @@ using namespace components;
|
||||||
|
|
||||||
DinkyECS::Entity add_items(DinkyECS::World &world, GameConfig &config) {
|
DinkyECS::Entity add_items(DinkyECS::World &world, GameConfig &config) {
|
||||||
auto sword = world.entity();
|
auto sword = world.entity();
|
||||||
world.set<InventoryItem>(sword, {1, config.items["SWORD_RUSTY"]});
|
json& item_data = config.items["SWORD_RUSTY"];
|
||||||
world.set<Tile>(sword, {config.items["SWORD_RUSTY"]["display"]});
|
world.set<InventoryItem>(sword, {item_data["inventory_count"], item_data});
|
||||||
|
components::configure(world, sword, item_data);
|
||||||
return sword;
|
return sword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,11 +296,7 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
|
||||||
|
|
||||||
for(size_t y = 0; y < end_y; ++y) {
|
for(size_t y = 0; y < end_y; ++y) {
|
||||||
for(size_t x = 0; x < end_x && it.next(); ++x) {
|
for(size_t x = 0; x < end_x && it.next(); ++x) {
|
||||||
|
// still working on this
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,8 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str
|
||||||
auto &config = world.get_the<GameConfig>();
|
auto &config = world.get_the<GameConfig>();
|
||||||
auto enemy = world.entity();
|
auto enemy = world.entity();
|
||||||
auto enemy_data = config.enemies[name];
|
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")) {
|
if(enemy_data.contains("components")) {
|
||||||
components::configure(world, enemy, enemy_data);
|
components::configure(world, enemy, enemy_data);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue