Looks like this is _possibly_ working but the last step of actually loading a save needs to be figured out.

This commit is contained in:
Zed A. Shaw 2024-11-06 07:18:59 -05:00
parent 6add24fed2
commit 99d56b246c
5 changed files with 37 additions and 9 deletions

View file

@ -6,12 +6,14 @@
#include "save.hpp"
#include <optional>
#include <iostream>
#include "map.hpp"
#include "tser.hpp"
using namespace fmt;
using std::string;
using namespace components;
enum class Item : char {
RADAR = 'R',
TRAP = 'T',
@ -54,6 +56,8 @@ TEST_CASE("test using tser for serialization", "[config]") {
TEST_CASE("basic save a world", "[save]") {
DinkyECS::World world;
Map map(20, 20);
map.generate();
// configure a player as a fact of the world
Player player{world.entity()};
@ -63,10 +67,11 @@ TEST_CASE("basic save a world", "[save]") {
world.set<Motion>(player.entity, {0, 0});
world.set<Combat>(player.entity, {100, 10});
save::to_file("./savetest.world", world);
save::to_file("./savetest.world", world, map);
DinkyECS::World in_world;
save::from_file("./savetest.world", in_world);
Map in_map(0, 0); // this will be changed on load
save::from_file("./savetest.world", in_world, in_map);
Position &position1 = world.get<Position>(player.entity);
Position &position2 = in_world.get<Position>(player.entity);
@ -81,4 +86,9 @@ TEST_CASE("basic save a world", "[save]") {
Motion &motion2 = in_world.get<Motion>(player.entity);
REQUIRE(motion1.dx == motion2.dx);
REQUIRE(motion1.dy == motion2.dy);
REQUIRE(map.width() == in_map.width());
REQUIRE(map.height() == in_map.height());
REQUIRE(map.$walls == in_map.$walls);
REQUIRE(map.$input_map == in_map.$input_map);
}