add player name

This commit is contained in:
MihailRis
2024-11-23 05:38:18 +03:00
parent 97a4741a73
commit acc4d2540d
6 changed files with 50 additions and 1 deletions
+12
View File
@@ -30,6 +30,7 @@ constexpr int SPAWN_ATTEMPTS_PER_UPDATE = 64;
Player::Player(
Level* level,
int64_t id,
const std::string& name,
glm::vec3 position,
float speed,
std::shared_ptr<Inventory> inv,
@@ -37,6 +38,7 @@ Player::Player(
)
: level(level),
id(id),
name(name),
speed(speed),
chosenSlot(0),
position(position),
@@ -269,6 +271,14 @@ entityid_t Player::getSelectedEntity() const {
return selectedEid;
}
void Player::setName(const std::string& name) {
this->name = name;
}
const std::string& Player::getName() const {
return name;
}
const std::shared_ptr<Inventory>& Player::getInventory() const {
return inventory;
}
@@ -285,6 +295,7 @@ dv::value Player::serialize() const {
auto root = dv::object();
root["id"] = id;
root["name"] = name;
root["position"] = dv::to_value(position);
root["rotation"] = dv::to_value(cam);
@@ -308,6 +319,7 @@ dv::value Player::serialize() const {
void Player::deserialize(const dv::value& src) {
src.at("id").get(id);
src.at("name").get(name);
const auto& posarr = src["position"];
+6 -1
View File
@@ -42,6 +42,7 @@ struct CursorSelection {
class Player : public Serializable {
Level* level;
int64_t id;
std::string name;
float speed;
int chosenSlot;
glm::vec3 position;
@@ -63,6 +64,7 @@ public:
Player(
Level* level,
int64_t id,
const std::string& name,
glm::vec3 position,
float speed,
std::shared_ptr<Inventory> inv,
@@ -100,9 +102,12 @@ public:
entityid_t getSelectedEntity() const;
void setName(const std::string& name);
const std::string& getName() const;
const std::shared_ptr<Inventory>& getInventory() const;
glm::vec3 getPosition() const {
const glm::vec3& getPosition() const {
return position;
}
+2
View File
@@ -23,6 +23,7 @@ Player* Players::create() {
auto playerPtr = std::make_unique<Player>(
level,
level->getWorld()->getInfo().nextPlayerId++,
"",
glm::vec3(0, DEF_PLAYER_Y, 0),
DEF_PLAYER_SPEED,
level->inventories->create(DEF_PLAYER_INVENTORY_SIZE),
@@ -53,6 +54,7 @@ void Players::deserialize(const dv::value& src) {
auto playerPtr = std::make_unique<Player>(
level,
0,
"",
glm::vec3(0, DEF_PLAYER_Y, 0),
DEF_PLAYER_SPEED,
level->inventories->create(DEF_PLAYER_INVENTORY_SIZE),