Compare commits
4 commits
master
...
feature/pl
Author | SHA1 | Date | |
---|---|---|---|
d68b9d1f9d | |||
![]() |
3d23c446ea | ||
![]() |
0134d5c0a9 | ||
![]() |
dbe79a3567 |
9 changed files with 104 additions and 1 deletions
BIN
assets/icons/player.png
Normal file
BIN
assets/icons/player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 741 B |
BIN
assets/icons/players.png
Normal file
BIN
assets/icons/players.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 753 B |
|
@ -79,7 +79,7 @@ static void writePropertySetHandler(std::ofstream& out, ClassAnalysis state) {
|
|||
std::string subtype = parseWeakPtr(prop.backingFieldType);
|
||||
|
||||
if (prop.flags & PropertyFlag_Readonly) {
|
||||
out << "\n return AssignToReadOnlyMember(GetClass()->className, name)";
|
||||
out << "\n return AssignToReadOnlyMember(GetClass()->className, name);";
|
||||
} else if (prop.cframeMember == CFrameMember_Position) {
|
||||
out << "\n this->" << prop.fieldName << " = this->" << prop.fieldName << ".Rotation() + value.get<Vector3>();";
|
||||
} else if (prop.cframeMember == CFrameMember_Rotation) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "objects/service/script/serverscriptservice.h"
|
||||
#include "datatypes/variant.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "objects/service/players.h"
|
||||
#include "logger.h"
|
||||
#include "panic.h"
|
||||
#include <pugixml.hpp>
|
||||
|
@ -23,6 +24,7 @@ DataModel::DataModel()
|
|||
void DataModel::Init(bool runMode) {
|
||||
// Create default services
|
||||
GetService<Workspace>();
|
||||
GetService<Players>();
|
||||
GetService<ServerScriptService>();
|
||||
|
||||
// Init all services
|
||||
|
@ -30,6 +32,10 @@ void DataModel::Init(bool runMode) {
|
|||
service->InitService();
|
||||
if (runMode) service->OnRun();
|
||||
}
|
||||
|
||||
// if (runMode) {
|
||||
// GetService<Players>()->createLocalPlayer(0);
|
||||
// }
|
||||
}
|
||||
|
||||
void DataModel::SaveToFile(std::optional<std::string> path) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "objects/service/script/serverscriptservice.h"
|
||||
#include "objects/service/selection.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "objects/service/players.h"
|
||||
#include "objects/datamodel.h"
|
||||
|
||||
std::map<std::string, const InstanceType*> INSTANCE_MAP = {
|
||||
|
@ -32,6 +33,7 @@ std::map<std::string, const InstanceType*> INSTANCE_MAP = {
|
|||
// Services
|
||||
|
||||
{ "Workspace", &Workspace::TYPE },
|
||||
{ "Players", &Players::TYPE },
|
||||
{ "JointsService", &JointsService::TYPE },
|
||||
{ "ScriptContext", &ScriptContext::TYPE },
|
||||
{ "ServerScriptService", &ServerScriptService::TYPE },
|
||||
|
|
6
core/src/objects/player.cpp
Normal file
6
core/src/objects/player.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "player.h"
|
||||
#include "objects/service/players.h"
|
||||
#include "objects/datamodel.h"
|
||||
|
||||
Player::Player(): Instance(&TYPE) {}
|
||||
Player::~Player() {}
|
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_(explorer_icon="player") 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>(); };
|
||||
};
|
41
core/src/objects/service/players.cpp
Normal file
41
core/src/objects/service/players.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "players.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "objects/datamodel.h"
|
||||
#include "objects/player.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int numPlayers;
|
||||
int maxPlayers;
|
||||
|
||||
Players::Players(): Service(&TYPE) {
|
||||
}
|
||||
|
||||
Players::~Players() = default;
|
||||
|
||||
void Players::InitService() {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
// Clear any players if they for some reason exist
|
||||
for (std::shared_ptr<Instance> inst : GetChildren()) {
|
||||
inst->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Player>> Players::createLocalPlayer(int userId) {
|
||||
if (!dataModel()) return std::nullopt;
|
||||
std::shared_ptr<Player> newPlr = Player::New();
|
||||
newPlr->name = "Player"+std::to_string(userId);
|
||||
newPlr->userId = userId;
|
||||
this->localPlayer = newPlr;
|
||||
this->AddChild(newPlr);
|
||||
return newPlr;
|
||||
}
|
||||
|
||||
void Players::removeLocalPlayer() {
|
||||
if (!this->localPlayer.lock()) return;
|
||||
this->localPlayer.lock()->Destroy();
|
||||
this->localPlayer = std::weak_ptr<Player>();
|
||||
}
|
25
core/src/objects/service/players.h
Normal file
25
core/src/objects/service/players.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/service.h"
|
||||
#include "objects/player.h"
|
||||
|
||||
class DEF_INST_SERVICE_(explorer_icon="players") 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::optional<std::shared_ptr<Player>> createLocalPlayer(int userId);
|
||||
void removeLocalPlayer();
|
||||
|
||||
DEF_PROP_CATEGORY(DATA)
|
||||
DEF_PROP_(readonly,no_save) int numPlayers = 0;
|
||||
DEF_PROP int maxPlayers = 10;
|
||||
DEF_PROP_(readonly,no_save) std::weak_ptr<Player> localPlayer;
|
||||
};
|
Loading…
Add table
Reference in a new issue