Test coverage back and save system should work again but have to confirm it in-game.
This commit is contained in:
parent
6b4ebf7629
commit
2576b16869
9 changed files with 43 additions and 31 deletions
10
map.cpp
10
map.cpp
|
@ -26,6 +26,15 @@ Map::Map(size_t width, size_t height) :
|
||||||
$paths(height, width, 1000)
|
$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() {
|
void Map::make_paths() {
|
||||||
$paths.compute_paths($walls);
|
$paths.compute_paths($walls);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +43,6 @@ bool Map::inmap(size_t x, size_t y) {
|
||||||
return x < $width && y < $height;
|
return x < $width && y < $height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Map::set_target(const Point &at, int value) {
|
void Map::set_target(const Point &at, int value) {
|
||||||
$paths.set_target(at, value);
|
$paths.set_target(at, value);
|
||||||
}
|
}
|
||||||
|
|
2
map.hpp
2
map.hpp
|
@ -42,6 +42,8 @@ public:
|
||||||
|
|
||||||
Map(size_t width, size_t height);
|
Map(size_t width, size_t height);
|
||||||
|
|
||||||
|
Map(Matrix &walls, Pathing &paths, int limit);
|
||||||
|
|
||||||
// disable copying
|
// disable copying
|
||||||
Map(Map &map) = delete;
|
Map(Map &map) = delete;
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ runtests = executable('runtests', [
|
||||||
'tests/panel.cpp',
|
'tests/panel.cpp',
|
||||||
'tests/sound.cpp',
|
'tests/sound.cpp',
|
||||||
'tests/pathing.cpp',
|
'tests/pathing.cpp',
|
||||||
|
'tests/lighting.cpp',
|
||||||
'tests/worldbuilder.cpp',
|
'tests/worldbuilder.cpp',
|
||||||
],
|
],
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
14
save.cpp
14
save.cpp
|
@ -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) {
|
void save::to_file(fs::path path, DinkyECS::World &world, Map &map) {
|
||||||
/*
|
|
||||||
SaveData save_data;
|
SaveData save_data;
|
||||||
tser::BinaryArchive archive;
|
tser::BinaryArchive archive;
|
||||||
|
|
||||||
save_data.facts.player = world.get_the<Player>();
|
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<Position>(world, save_data.position);
|
||||||
extract<Combat>(world, save_data.combat);
|
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);
|
std::ofstream out(path, std::ios::binary);
|
||||||
out << archive_view;
|
out << archive_view;
|
||||||
out.flush();
|
out.flush();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CompT>
|
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<Tile>(world_out, save_data.tile);
|
||||||
inject<Inventory>(world_out, save_data.inventory);
|
inject<Inventory>(world_out, save_data.inventory);
|
||||||
|
|
||||||
/*
|
size_t width = save_data.map.walls[0].size();
|
||||||
map_out = Map(save_data.map.input_map,
|
size_t height = save_data.map.walls.size();
|
||||||
save_data.map.walls, save_data.map.limit);
|
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);
|
save::load_configs(world_out);
|
||||||
}
|
}
|
||||||
|
|
3
save.hpp
3
save.hpp
|
@ -12,11 +12,10 @@ namespace save {
|
||||||
|
|
||||||
struct MapData {
|
struct MapData {
|
||||||
std::vector<Room> rooms;
|
std::vector<Room> rooms;
|
||||||
Matrix input_map;
|
|
||||||
Matrix walls;
|
Matrix walls;
|
||||||
int limit;
|
int limit;
|
||||||
|
|
||||||
DEFINE_SERIALIZABLE(MapData, rooms, input_map, walls);
|
DEFINE_SERIALIZABLE(MapData, rooms, walls);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Facts {
|
struct Facts {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
|
#include "worldbuilder.hpp"
|
||||||
#include "lights.hpp"
|
#include "lights.hpp"
|
||||||
#include "point.hpp"
|
#include "point.hpp"
|
||||||
|
|
||||||
|
@ -10,7 +11,8 @@ using namespace lighting;
|
||||||
|
|
||||||
TEST_CASE("lighting a map works", "[lighting]") {
|
TEST_CASE("lighting a map works", "[lighting]") {
|
||||||
Map map(20,20);
|
Map map(20,20);
|
||||||
map.generate();
|
WorldBuilder builder(map);
|
||||||
|
builder.generate();
|
||||||
|
|
||||||
Point light1 = map.place_entity(0);
|
Point light1 = map.place_entity(0);
|
||||||
Point light2 = map.place_entity(1);
|
Point light2 = map.place_entity(1);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
|
#include "worldbuilder.hpp"
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
@ -13,6 +14,22 @@ json load_test_data(const string &fname) {
|
||||||
return json::parse(infile);
|
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]") {
|
TEST_CASE("dijkstra algo test", "[map]") {
|
||||||
json data = load_test_data("./tests/dijkstra.json");
|
json data = load_test_data("./tests/dijkstra.json");
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
|
#include "worldbuilder.hpp"
|
||||||
#include "tser.hpp"
|
#include "tser.hpp"
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
@ -54,10 +55,10 @@ TEST_CASE("test using tser for serialization", "[config]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("basic save a world", "[save]") {
|
TEST_CASE("basic save a world", "[save]") {
|
||||||
/*
|
|
||||||
DinkyECS::World world;
|
DinkyECS::World world;
|
||||||
Map map(20, 20);
|
Map map(20, 20);
|
||||||
map.generate();
|
WorldBuilder builder(map);
|
||||||
|
builder.generate();
|
||||||
|
|
||||||
// configure a player as a fact of the world
|
// configure a player as a fact of the world
|
||||||
Player player{world.entity()};
|
Player player{world.entity()};
|
||||||
|
@ -99,5 +100,4 @@ TEST_CASE("basic save a world", "[save]") {
|
||||||
|
|
||||||
Inventory &inv = world.get<Inventory>(player.entity);
|
Inventory &inv = world.get<Inventory>(player.entity);
|
||||||
REQUIRE(inv.gold == 102);
|
REQUIRE(inv.gold == 102);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,23 +24,6 @@ TEST_CASE("dumping and debugging", "[map]") {
|
||||||
map.dump();
|
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]") {
|
TEST_CASE("pathing", "[map]") {
|
||||||
Map map(20, 20);
|
Map map(20, 20);
|
||||||
WorldBuilder builder(map);
|
WorldBuilder builder(map);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue