feat(engine): add Players service
This commit is contained in:
parent
0d53d1593f
commit
dbe79a3567
5 changed files with 46 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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 },
|
||||
|
|
19
core/src/objects/service/players.cpp
Normal file
19
core/src/objects/service/players.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "players.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "objects/datamodel.h"
|
||||
#include <memory>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
22
core/src/objects/service/players.h
Normal file
22
core/src/objects/service/players.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/service.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>(); };
|
||||
|
||||
DEF_PROP_CATEGORY(DATA)
|
||||
DEF_PROP_(readonly,no_save)
|
||||
int numPlayers = 0;
|
||||
DEF_PROP int maxPlayers = 6;
|
||||
};
|
Loading…
Add table
Reference in a new issue