added serializable class

This commit is contained in:
DanielProl1xy
2024-01-30 15:53:49 +03:00
parent a9b55f35be
commit 8466c42896
6 changed files with 64 additions and 41 deletions
+2 -32
View File
@@ -536,7 +536,7 @@ bool WorldFiles::readWorldInfo(World* world) {
}
void WorldFiles::writePlayer(Player* player) {
files::write_json(getPlayerFile(), player->write().release());
files::write_json(getPlayerFile(), player->serialize().release());
}
bool WorldFiles::readPlayer(Player* player) {
@@ -546,37 +546,7 @@ bool WorldFiles::readPlayer(Player* player) {
return false;
}
auto root = files::read_json(file);
auto posarr = root->list("position");
glm::vec3& position = player->hitbox->position;
position.x = posarr->num(0);
position.y = posarr->num(1);
position.z = posarr->num(2);
player->camera->position = position;
auto rotarr = root->list("rotation");
player->cam.x = rotarr->num(0);
player->cam.y = rotarr->num(1);
if (root->has("spawnpoint")) {
auto sparr = root->list("spawnpoint");
player->setSpawnPoint(glm::vec3(
sparr->num(0),
sparr->num(1),
sparr->num(2)
));
} else {
player->setSpawnPoint(position);
}
root->flag("flight", player->flight);
root->flag("noclip", player->noclip);
player->setChosenSlot(root->getInt("chosen-slot", player->getChosenSlot()));
auto invmap = root->map("inventory");
if (invmap) {
player->getInventory()->read(invmap);
}
player->deserialize(files::read_json(file).get());
return true;
}