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