feat(engine): add Players service

This commit is contained in:
WindClan 2025-07-08 05:14:29 -04:00 committed by m-doescode
parent 0d53d1593f
commit dbe79a3567
5 changed files with 46 additions and 1 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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 },

View 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();
}
}

View 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;
};