BROKEN: Big refactoring happening, so it compiles but game does not run and the tests fail.
This commit is contained in:
parent
96efc990c1
commit
9e91c71125
25 changed files with 128 additions and 526 deletions
66
save.cpp
66
save.cpp
|
@ -17,70 +17,16 @@ 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.$width, map.$height,
|
||||
map.$rooms, map.$walls};
|
||||
|
||||
// BUG: lights aren't saved/restored
|
||||
extract<Position>(world, save_data.position);
|
||||
extract<Combat>(world, save_data.combat);
|
||||
extract<Motion>(world, save_data.motion);
|
||||
extract<Tile>(world, save_data.tile);
|
||||
// extract<Inventory>(world, save_data.inventory);
|
||||
|
||||
archive.save(save_data);
|
||||
std::string_view archive_view = archive.get_buffer();
|
||||
|
||||
std::ofstream out(path, std::ios::binary);
|
||||
out << archive_view;
|
||||
out.flush();
|
||||
(void)path;
|
||||
(void)world;
|
||||
(void)map;
|
||||
}
|
||||
|
||||
template<typename CompT>
|
||||
inline void inject(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &outof) {
|
||||
for(auto [entity, value] : outof) {
|
||||
world.set<CompT>(entity, value);
|
||||
}
|
||||
}
|
||||
|
||||
void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) {
|
||||
tser::BinaryArchive archive(0);
|
||||
dbc::check(fs::exists(path), format("save file does not exist {}", path.string()));
|
||||
auto size = fs::file_size(path);
|
||||
|
||||
if(std::ifstream in_file{path, std::ios::binary}) {
|
||||
std::string in_data(size, '\0');
|
||||
|
||||
if(in_file.read(&in_data[0], size)) {
|
||||
std::string_view in_view(in_data);
|
||||
archive.initialize(in_view);
|
||||
} else {
|
||||
dbc::sentinel(format("wrong size or error reading {}", path.string()));
|
||||
}
|
||||
} else {
|
||||
dbc::sentinel(format("failed to load file {}", path.string()));
|
||||
}
|
||||
|
||||
auto save_data = archive.load<SaveData>();
|
||||
|
||||
world_out.set_the<Player>(save_data.facts.player);
|
||||
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);
|
||||
// inject<Inventory>(world_out, save_data.inventory);
|
||||
|
||||
size_t width = save_data.map.width;
|
||||
size_t height = save_data.map.height;
|
||||
|
||||
Pathing paths(width, height);
|
||||
map_out = Map(save_data.map.walls, paths);
|
||||
|
||||
save::load_configs(world_out);
|
||||
(void)path;
|
||||
(void)world_out;
|
||||
(void)map_out;
|
||||
}
|
||||
|
||||
void save::load_configs(DinkyECS::World &world) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue