feat: Add basic part class
This commit is contained in:
parent
ca22b4438f
commit
a6b3247c0c
|
@ -12,8 +12,16 @@ static InstanceType TYPE_ {
|
||||||
|
|
||||||
InstanceType* Instance::TYPE = &TYPE_;
|
InstanceType* Instance::TYPE = &TYPE_;
|
||||||
|
|
||||||
InstanceType* GetClass() {
|
// Instance is abstract, so it should not implement GetClass directly
|
||||||
return &TYPE_;
|
// InstanceType* Instance::GetClass() {
|
||||||
|
// return &TYPE_;
|
||||||
|
// }
|
||||||
|
|
||||||
|
Instance::Instance(InstanceType* type) {
|
||||||
|
this->name = type->className;
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance::~Instance () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
void Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
||||||
|
|
|
@ -16,11 +16,15 @@ class Instance : std::enable_shared_from_this<Instance> {
|
||||||
private:
|
private:
|
||||||
std::optional<std::weak_ptr<Instance>> parent;
|
std::optional<std::weak_ptr<Instance>> parent;
|
||||||
std::vector<std::shared_ptr<Instance>> children;
|
std::vector<std::shared_ptr<Instance>> children;
|
||||||
|
protected:
|
||||||
|
Instance(InstanceType*);
|
||||||
|
virtual ~Instance();
|
||||||
public:
|
public:
|
||||||
static InstanceType* TYPE;
|
static InstanceType* TYPE;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
InstanceType* GetClass();
|
// Instance is abstract, so it should not implement GetClass directly
|
||||||
|
virtual InstanceType* GetClass() = 0;
|
||||||
void SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
void SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
||||||
std::optional<std::shared_ptr<Instance>> GetParent();
|
std::optional<std::shared_ptr<Instance>> GetParent();
|
||||||
inline const std::vector<std::shared_ptr<Instance>> GetChildren() { return children; }
|
inline const std::vector<std::shared_ptr<Instance>> GetChildren() { return children; }
|
||||||
|
|
16
src/objects/part.cpp
Normal file
16
src/objects/part.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "part.h"
|
||||||
|
|
||||||
|
static InstanceType TYPE_ {
|
||||||
|
.super = Instance::TYPE,
|
||||||
|
.className = "Part",
|
||||||
|
.constructor = &Part::CreateGeneric,
|
||||||
|
};
|
||||||
|
|
||||||
|
InstanceType* Part::TYPE = &TYPE_;
|
||||||
|
|
||||||
|
InstanceType* Part::GetClass() {
|
||||||
|
return &TYPE_;
|
||||||
|
}
|
||||||
|
|
||||||
|
Part::Part(): Instance(&TYPE_) {
|
||||||
|
}
|
14
src/objects/part.h
Normal file
14
src/objects/part.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class Part : public Instance {
|
||||||
|
public:
|
||||||
|
static InstanceType* TYPE;
|
||||||
|
|
||||||
|
Part();
|
||||||
|
|
||||||
|
static inline InstanceRef CreateGeneric() { return std::make_shared<Part>(); };
|
||||||
|
virtual InstanceType* GetClass() override;
|
||||||
|
};
|
Loading…
Reference in a new issue