Kind of working save now, but does have problems with dead things.

main
Zed A. Shaw 4 weeks ago
parent 99d56b246c
commit b2ed598c1f
  1. 2
      components.hpp
  2. 15
      main.cpp
  3. 2
      save.cpp
  4. 3
      save.hpp
  5. 9
      tests/save.cpp

@ -28,7 +28,7 @@ namespace components {
};
struct Tile {
std::string chr = "!";
std::string chr;
DEFINE_SERIALIZABLE(Tile, chr);
};

@ -8,8 +8,10 @@
#include "render.hpp"
#include "save.hpp"
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
#include <filesystem>
using namespace ftxui;
namespace fs = std::filesystem;
/*
* This needs to be turned into a real world generator
@ -48,14 +50,21 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
}
int main() {
int main(int argc, char *argv[]) {
DinkyECS::World world;
Map game_map(GAME_MAP_X, GAME_MAP_Y);
game_map.generate();
save::load_configs(world);
configure_world(world, game_map);
if(argc == 2) {
fmt::println("Loading save file {}", argv[1]);
fs::path save_path{argv[1]};
save::from_file(save_path, world, game_map);
} else {
game_map.generate();
configure_world(world, game_map);
}
spatial_map collider;
world.set_the<spatial_map>(collider);

@ -26,6 +26,7 @@ void save::to_file(fs::path path, DinkyECS::World &world, Map &map) {
extract<Position>(world, save_data.position);
extract<Combat>(world, save_data.combat);
extract<Motion>(world, save_data.motion);
extract<Tile>(world, save_data.tile);
archive.save(save_data);
std::string_view archive_view = archive.get_buffer();
@ -66,6 +67,7 @@ void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) {
inject<Position>(world_out, save_data.position);
inject<Combat>(world_out, save_data.combat);
inject<Motion>(world_out, save_data.motion);
inject<Tile>(world_out, save_data.tile);
map_out = Map(save_data.map.input_map,
save_data.map.walls, save_data.map.limit);

@ -32,8 +32,9 @@ namespace save {
std::map<DinkyECS::Entity, components::Position> position;
std::map<DinkyECS::Entity, components::Motion> motion;
std::map<DinkyECS::Entity, components::Combat> combat;
std::map<DinkyECS::Entity, components::Tile> tile;
DEFINE_SERIALIZABLE(SaveData, facts, map, position, motion, combat);
DEFINE_SERIALIZABLE(SaveData, facts, map, position, motion, combat, tile);
};
void to_file(fs::path path, DinkyECS::World &world, Map &map);

@ -66,6 +66,7 @@ TEST_CASE("basic save a world", "[save]") {
world.set<Position>(player.entity, {10,10});
world.set<Motion>(player.entity, {0, 0});
world.set<Combat>(player.entity, {100, 10});
world.set<Tile>(player.entity, {"@"});
save::to_file("./savetest.world", world, map);
@ -78,15 +79,19 @@ TEST_CASE("basic save a world", "[save]") {
REQUIRE(position1.location.x == position2.location.x);
REQUIRE(position1.location.y == position2.location.y);
Combat &combat1 = in_world.get<Combat>(player.entity);
Combat &combat1 = world.get<Combat>(player.entity);
Combat &combat2 = in_world.get<Combat>(player.entity);
REQUIRE(combat1.hp == combat2.hp);
Motion &motion1 = in_world.get<Motion>(player.entity);
Motion &motion1 = world.get<Motion>(player.entity);
Motion &motion2 = in_world.get<Motion>(player.entity);
REQUIRE(motion1.dx == motion2.dx);
REQUIRE(motion1.dy == motion2.dy);
Tile &tile1 = world.get<Tile>(player.entity);
Tile &tile2 = in_world.get<Tile>(player.entity);
REQUIRE(tile1.chr == tile2.chr);
REQUIRE(map.width() == in_map.width());
REQUIRE(map.height() == in_map.height());
REQUIRE(map.$walls == in_map.$walls);

Loading…
Cancel
Save