diff --git a/map.cpp b/map.cpp index 5a34da2..656ae8e 100644 --- a/map.cpp +++ b/map.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); } diff --git a/map.hpp b/map.hpp index 9ede0b4..34a0ed0 100644 --- a/map.hpp +++ b/map.hpp @@ -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; diff --git a/meson.build b/meson.build index 194c589..a567e33 100644 --- a/meson.build +++ b/meson.build @@ -46,6 +46,7 @@ runtests = executable('runtests', [ 'tests/panel.cpp', 'tests/sound.cpp', 'tests/pathing.cpp', + 'tests/lighting.cpp', 'tests/worldbuilder.cpp', ], dependencies: dependencies) diff --git a/save.cpp b/save.cpp index e43c54f..386adb1 100644 --- a/save.cpp +++ b/save.cpp @@ -17,12 +17,11 @@ inline void extract(DinkyECS::World &world, std::map &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(); - save_data.map = MapData{map.$rooms, map.$input_map, map.$walls, map.$limit}; + save_data.map = MapData{map.$rooms, map.$walls, map.$limit}; extract(world, save_data.position); extract(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 @@ -73,10 +71,12 @@ void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) { inject(world_out, save_data.tile); inject(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); } diff --git a/save.hpp b/save.hpp index e73f3d6..1309833 100644 --- a/save.hpp +++ b/save.hpp @@ -12,11 +12,10 @@ namespace save { struct MapData { std::vector rooms; - Matrix input_map; Matrix walls; int limit; - DEFINE_SERIALIZABLE(MapData, rooms, input_map, walls); + DEFINE_SERIALIZABLE(MapData, rooms, walls); }; struct Facts { diff --git a/tests/lighting.cpp b/tests/lighting.cpp index 9f9b12d..d64e474 100644 --- a/tests/lighting.cpp +++ b/tests/lighting.cpp @@ -3,6 +3,7 @@ #include #include #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); diff --git a/tests/map.cpp b/tests/map.cpp index cee1e23..bb959d4 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -3,6 +3,7 @@ #include #include #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"); diff --git a/tests/save.cpp b/tests/save.cpp index abde54a..3ec1996 100644 --- a/tests/save.cpp +++ b/tests/save.cpp @@ -7,6 +7,7 @@ #include #include #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(player.entity); REQUIRE(inv.gold == 102); - */ } diff --git a/tests/worldbuilder.cpp b/tests/worldbuilder.cpp index 83c5a98..fb5fa41 100644 --- a/tests/worldbuilder.cpp +++ b/tests/worldbuilder.cpp @@ -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);