Test coverage back and save system should work again but have to confirm it in-game.

main
Zed A. Shaw 2 days ago
parent 6b4ebf7629
commit 2576b16869
  1. 10
      map.cpp
  2. 2
      map.hpp
  3. 1
      meson.build
  4. 14
      save.cpp
  5. 3
      save.hpp
  6. 4
      tests/lighting.cpp
  7. 17
      tests/map.cpp
  8. 6
      tests/save.cpp
  9. 17
      tests/worldbuilder.cpp

@ -26,6 +26,15 @@ Map::Map(size_t width, size_t height) :
$paths(height, width, 1000)
{}
Map::Map(Matrix &walls, Pathing &paths, int limit) :
$limit(limit),
$walls(walls),
$paths(paths)
{
$width = walls[0].size();
$height = walls.size();
}
void Map::make_paths() {
$paths.compute_paths($walls);
}
@ -34,7 +43,6 @@ bool Map::inmap(size_t x, size_t y) {
return x < $width && y < $height;
}
void Map::set_target(const Point &at, int value) {
$paths.set_target(at, value);
}

@ -42,6 +42,8 @@ public:
Map(size_t width, size_t height);
Map(Matrix &walls, Pathing &paths, int limit);
// disable copying
Map(Map &map) = delete;

@ -46,6 +46,7 @@ runtests = executable('runtests', [
'tests/panel.cpp',
'tests/sound.cpp',
'tests/pathing.cpp',
'tests/lighting.cpp',
'tests/worldbuilder.cpp',
],
dependencies: dependencies)

@ -17,12 +17,11 @@ inline void extract(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &i
}
void save::to_file(fs::path path, DinkyECS::World &world, Map &map) {
/*
SaveData save_data;
tser::BinaryArchive archive;
save_data.facts.player = world.get_the<Player>();
save_data.map = MapData{map.$rooms, map.$input_map, map.$walls, map.$limit};
save_data.map = MapData{map.$rooms, map.$walls, map.$limit};
extract<Position>(world, save_data.position);
extract<Combat>(world, save_data.combat);
@ -36,7 +35,6 @@ void save::to_file(fs::path path, DinkyECS::World &world, Map &map) {
std::ofstream out(path, std::ios::binary);
out << archive_view;
out.flush();
*/
}
template<typename CompT>
@ -73,10 +71,12 @@ void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) {
inject<Tile>(world_out, save_data.tile);
inject<Inventory>(world_out, save_data.inventory);
/*
map_out = Map(save_data.map.input_map,
save_data.map.walls, save_data.map.limit);
*/
size_t width = save_data.map.walls[0].size();
size_t height = save_data.map.walls.size();
int limit = save_data.map.limit;
Pathing paths(width, height, limit);
map_out = Map(save_data.map.walls, paths, limit);
save::load_configs(world_out);
}

@ -12,11 +12,10 @@ namespace save {
struct MapData {
std::vector<Room> rooms;
Matrix input_map;
Matrix walls;
int limit;
DEFINE_SERIALIZABLE(MapData, rooms, input_map, walls);
DEFINE_SERIALIZABLE(MapData, rooms, walls);
};
struct Facts {

@ -3,6 +3,7 @@
#include <nlohmann/json.hpp>
#include <fstream>
#include "map.hpp"
#include "worldbuilder.hpp"
#include "lights.hpp"
#include "point.hpp"
@ -10,7 +11,8 @@ using namespace lighting;
TEST_CASE("lighting a map works", "[lighting]") {
Map map(20,20);
map.generate();
WorldBuilder builder(map);
builder.generate();
Point light1 = map.place_entity(0);
Point light2 = map.place_entity(1);

@ -3,6 +3,7 @@
#include <nlohmann/json.hpp>
#include <fstream>
#include "map.hpp"
#include "worldbuilder.hpp"
using namespace fmt;
using namespace nlohmann;
@ -13,6 +14,22 @@ json load_test_data(const string &fname) {
return json::parse(infile);
}
TEST_CASE("camera control", "[map]") {
Map map(20, 20);
WorldBuilder builder(map);
builder.generate();
Point center = map.center_camera({10,10}, 5, 5);
REQUIRE(center.x == 8);
REQUIRE(center.y == 8);
Point translation = map.map_to_camera({10,10}, center);
REQUIRE(translation.x == 2);
REQUIRE(translation.y == 2);
}
TEST_CASE("dijkstra algo test", "[map]") {
json data = load_test_data("./tests/dijkstra.json");

@ -7,6 +7,7 @@
#include <optional>
#include <iostream>
#include "map.hpp"
#include "worldbuilder.hpp"
#include "tser.hpp"
using namespace fmt;
@ -54,10 +55,10 @@ TEST_CASE("test using tser for serialization", "[config]") {
}
TEST_CASE("basic save a world", "[save]") {
/*
DinkyECS::World world;
Map map(20, 20);
map.generate();
WorldBuilder builder(map);
builder.generate();
// configure a player as a fact of the world
Player player{world.entity()};
@ -99,5 +100,4 @@ TEST_CASE("basic save a world", "[save]") {
Inventory &inv = world.get<Inventory>(player.entity);
REQUIRE(inv.gold == 102);
*/
}

@ -24,23 +24,6 @@ TEST_CASE("dumping and debugging", "[map]") {
map.dump();
}
TEST_CASE("camera control", "[map]") {
Map map(20, 20);
WorldBuilder builder(map);
builder.generate();
Point center = map.center_camera({10,10}, 5, 5);
REQUIRE(center.x == 8);
REQUIRE(center.y == 8);
Point translation = map.map_to_camera({10,10}, center);
REQUIRE(translation.x == 2);
REQUIRE(translation.y == 2);
}
TEST_CASE("pathing", "[map]") {
Map map(20, 20);
WorldBuilder builder(map);

Loading…
Cancel
Save