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:
parent
6add24fed2
commit
99d56b246c
5 changed files with 37 additions and 9 deletions
9
save.cpp
9
save.cpp
|
@ -16,11 +16,12 @@ inline void extract(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &i
|
|||
}
|
||||
}
|
||||
|
||||
void save::to_file(fs::path path, DinkyECS::World &world) {
|
||||
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.$rooms, map.$input_map, map.$walls, map.$limit};
|
||||
|
||||
extract<Position>(world, save_data.position);
|
||||
extract<Combat>(world, save_data.combat);
|
||||
|
@ -41,7 +42,7 @@ inline void inject(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &ou
|
|||
}
|
||||
}
|
||||
|
||||
void save::from_file(fs::path path, DinkyECS::World &world_out) {
|
||||
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);
|
||||
|
@ -60,11 +61,15 @@ void save::from_file(fs::path path, DinkyECS::World &world_out) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
map_out = Map(save_data.map.input_map,
|
||||
save_data.map.walls, save_data.map.limit);
|
||||
|
||||
save::load_configs(world_out);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue