feat(engine): add Player class
This commit is contained in:
parent
dbe79a3567
commit
0134d5c0a9
4 changed files with 50 additions and 2 deletions
11
core/src/objects/player.cpp
Normal file
11
core/src/objects/player.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "player.h"
|
||||
#include "objects/service/players.h"
|
||||
#include "objects/datamodel.h"
|
||||
|
||||
Player::Player(): Instance(&TYPE) {
|
||||
dataModel().value()->GetService<Players>()->numPlayers += 1;
|
||||
}
|
||||
Player::~Player() {
|
||||
// Subtract from player count on remove
|
||||
dataModel().value()->GetService<Players>()->numPlayers -= 1;
|
||||
}
|
23
core/src/objects/player.h
Normal file
23
core/src/objects/player.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "objects/model.h"
|
||||
#include <memory>
|
||||
|
||||
class DEF_INST_(not_creatable) Player : public Instance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
public:
|
||||
Player();
|
||||
~Player();
|
||||
|
||||
DEF_PROP_CATEGORY(DATA)
|
||||
DEF_PROP_(readonly) int userId = 0;
|
||||
DEF_PROP std::weak_ptr<Model> character;
|
||||
DEF_PROP_CATEGORY(TEAM) //placeholder, we cant add TeamColor or Teams yet since no BrickColor
|
||||
DEF_PROP bool neutral = true;
|
||||
|
||||
static inline std::shared_ptr<Player> New() { return std::make_shared<Player>(); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Player>(); };
|
||||
};
|
|
@ -1,8 +1,12 @@
|
|||
#include "players.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "objects/datamodel.h"
|
||||
#include "objects/player.h"
|
||||
#include <memory>
|
||||
|
||||
int numPlayers;
|
||||
int maxPlayers;
|
||||
|
||||
Players::Players(): Service(&TYPE) {
|
||||
}
|
||||
|
||||
|
@ -17,3 +21,11 @@ void Players::InitService() {
|
|||
inst->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Player> Players::createLocalPlayer(int userId) {
|
||||
std::shared_ptr<Player> newPlr = Player::New();
|
||||
newPlr->name = "Player"+std::to_string(userId);
|
||||
newPlr->userId = userId;
|
||||
dataModel().value()->GetService<Players>()->AddChild(newPlr);
|
||||
return newPlr;
|
||||
}
|
|
@ -2,21 +2,23 @@
|
|||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/service.h"
|
||||
#include "objects/player.h"
|
||||
|
||||
class DEF_INST_SERVICE Players : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
protected:
|
||||
void InitService() override;
|
||||
bool initialized = false;
|
||||
|
||||
public:
|
||||
Players();
|
||||
~Players();
|
||||
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Players>(); };
|
||||
std::shared_ptr<Player> createLocalPlayer(int userId);
|
||||
|
||||
DEF_PROP_CATEGORY(DATA)
|
||||
DEF_PROP_(readonly,no_save)
|
||||
int numPlayers = 0;
|
||||
DEF_PROP int maxPlayers = 6;
|
||||
DEF_PROP int maxPlayers = 10;
|
||||
DEF_PROP std::weak_ptr<Player> localPlayer;
|
||||
};
|
Loading…
Add table
Reference in a new issue