propogate player smart-pointer usage

This commit is contained in:
DanielProl1xy
2024-02-21 15:27:00 +03:00
parent 7c6b52cb2a
commit 0b31a19f47
5 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -559,11 +559,11 @@ bool WorldFiles::readWorldInfo(World* world) {
return true; return true;
} }
void WorldFiles::writePlayer(Player* player) { void WorldFiles::writePlayer(std::shared_ptr<Player> player) {
files::write_json(getPlayerFile(), player->serialize().release()); files::write_json(getPlayerFile(), player->serialize().release());
} }
bool WorldFiles::readPlayer(Player* player) { bool WorldFiles::readPlayer(std::shared_ptr<Player> player) {
fs::path file = getPlayerFile(); fs::path file = getPlayerFile();
if (!fs::is_regular_file(file)) { if (!fs::is_regular_file(file)) {
std::cerr << "warning: player.json does not exists" << std::endl; std::cerr << "warning: player.json does not exists" << std::endl;
+2 -2
View File
@@ -143,13 +143,13 @@ public:
chunk_inventories_map fetchInventories(int x, int z); chunk_inventories_map fetchInventories(int x, int z);
bool readWorldInfo(World* world); bool readWorldInfo(World* world);
bool readPlayer(Player* player); bool readPlayer(std::shared_ptr<Player> player);
void writeRegion(int x, int y, void writeRegion(int x, int y,
WorldRegion* entry, WorldRegion* entry,
fs::path file, fs::path file,
int layer); int layer);
void writePlayer(Player* player); void writePlayer(std::shared_ptr<Player> player);
/* @param world world info to save (nullable) */ /* @param world world info to save (nullable) */
void write(const World* world, const Content* content); void write(const World* world, const Content* content);
void writePacks(const World* world); void writePacks(const World* world);
+2 -2
View File
@@ -645,6 +645,6 @@ void Hud::setPause(bool pause) {
menu->setVisible(pause); menu->setVisible(pause);
} }
Player* Hud::getPlayer() const { std::shared_ptr<Player> Hud::getPlayer() const {
return frontend->getLevel()->player.get(); return frontend->getLevel()->player;
} }
+1 -1
View File
@@ -118,7 +118,7 @@ public:
void remove(HudElement& element); void remove(HudElement& element);
void remove(std::shared_ptr<gui::UINode> node); void remove(std::shared_ptr<gui::UINode> node);
Player* getPlayer() const; std::shared_ptr<Player> getPlayer() const;
}; };
#endif /* SRC_HUD_H_ */ #endif /* SRC_HUD_H_ */
+2 -2
View File
@@ -61,7 +61,7 @@ void World::write(Level* level) {
} }
wfile->write(this, content); wfile->write(this, content);
wfile->writePlayer(level->player.get()); wfile->writePlayer(level->player);
} }
Level* World::create(std::string name, Level* World::create(std::string name,
@@ -89,7 +89,7 @@ Level* World::load(fs::path directory,
} }
auto level = new Level(world.get(), content, settings); auto level = new Level(world.get(), content, settings);
wfile->readPlayer(level->player.get()); wfile->readPlayer(level->player);
world.release(); world.release();
return level; return level;
} }