|
|
|
@ -7,10 +7,10 @@ using namespace components; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename CompT> |
|
|
|
|
inline void extract(DinkyECS::World &world, std::vector<CompT> &into) { |
|
|
|
|
inline void extract(DinkyECS::World &world, std::map<DinkyECS::Entity, CompT> &into) { |
|
|
|
|
auto from_world = world.entity_map_for<CompT>(); |
|
|
|
|
for(auto [entity, value] : from_world) { |
|
|
|
|
into.push_back(std::any_cast<CompT>(value)); |
|
|
|
|
into[entity] = std::any_cast<CompT>(value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -18,7 +18,8 @@ void save::to_file(std::string path, DinkyECS::World &world) { |
|
|
|
|
SaveData save_data; |
|
|
|
|
tser::BinaryArchive archive; |
|
|
|
|
|
|
|
|
|
save_data.player = world.get_the<Player>(); |
|
|
|
|
save_data.facts.player = world.get_the<Player>(); |
|
|
|
|
|
|
|
|
|
extract<Position>(world, save_data.position); |
|
|
|
|
extract<Combat>(world, save_data.combat); |
|
|
|
|
extract<Motion>(world, save_data.motion); |
|
|
|
@ -31,6 +32,12 @@ void save::to_file(std::string path, DinkyECS::World &world) { |
|
|
|
|
out.flush(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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(std::string path, DinkyECS::World &world_out) { |
|
|
|
|
tser::BinaryArchive archive(0); |
|
|
|
@ -51,13 +58,8 @@ void save::from_file(std::string path, DinkyECS::World &world_out) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto save_data = archive.load<SaveData>(); |
|
|
|
|
|
|
|
|
|
// BUG: need the entities!
|
|
|
|
|
world_out.set_the<Player>(save_data.player); |
|
|
|
|
|
|
|
|
|
for(auto position : save_data.position) { |
|
|
|
|
auto entity = world_out.entity(); |
|
|
|
|
// BUG: actually do need the entities
|
|
|
|
|
world_out.set<Position>(entity, position); |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|