Instance
This commit is contained in:
parent
cbb3091bfa
commit
15e6ae1c32
|
|
@ -6,6 +6,7 @@ project(server)
|
|||
project(studio)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core)
|
||||
find_package(Boost REQUIRED)
|
||||
qt_standard_project_setup()
|
||||
|
||||
add_library(engine STATIC
|
||||
|
|
@ -31,7 +32,8 @@ qt_add_executable(studio
|
|||
src/client/studio/main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(engine PUBLIC include)
|
||||
target_include_directories(engine PUBLIC src/include)
|
||||
target_link_libraries(engine PUBLIC ${BOOST_LIBRARIES})
|
||||
|
||||
target_link_libraries(player PRIVATE Qt6::Core engine)
|
||||
target_link_libraries(studio PRIVATE Qt6::Core engine)
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
RBX::Humanoid::Humanoid()
|
||||
{
|
||||
|
||||
this->setName("Humanoid");
|
||||
}
|
||||
|
|
@ -1,4 +1,48 @@
|
|||
#include "Instance.hpp"
|
||||
#include <engine/app/v8/tree/Instance.hpp>
|
||||
|
||||
RBX::Instance::Instance()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RBX::Instance::Instance(std::string name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RBX::Instance::contains(RBX::Instance* child)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RBX::Instance::isAncestorOf(RBX::Instance* instance)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RBX::Instance::askSetParent(RBX::Instance* instance)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RBX::Instance::canSetParent(RBX::Instance* instance)
|
||||
{
|
||||
return !instance || instance->canAddChild(this);
|
||||
}
|
||||
|
||||
bool RBX::Instance::askAddChild(RBX::Instance* instance)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RBX::Instance::canAddChild(RBX::Instance* instance)
|
||||
{
|
||||
if(instance->contains(this) || instance->parent == this)
|
||||
return false;
|
||||
if(askAddC hild(instance))
|
||||
return true;
|
||||
return instance->askSetParent(this);
|
||||
}
|
||||
|
||||
void RBX::Instance::setName(std::string name)
|
||||
{
|
||||
|
|
@ -7,4 +51,40 @@ void RBX::Instance::setName(std::string name)
|
|||
this->m_name = name;
|
||||
// raise property changed
|
||||
}
|
||||
}
|
||||
|
||||
void RBX::Instance::setParent(RBX::Instance* newParent)
|
||||
{
|
||||
if(newParent != m_parent)
|
||||
{
|
||||
if(this == newParent)
|
||||
{
|
||||
throw std::runtime_error("Attempt to set %s as its own parent", m_name);
|
||||
}
|
||||
if(isAncestorOf(newParent))
|
||||
{
|
||||
throw std::runtime_error("Attempt to set parent of %s to %s results in circular reference", newParent->getName(), m_name);
|
||||
}
|
||||
|
||||
if(m_parent)
|
||||
{
|
||||
std::vector<boost::shared_ptr<RBX::Instance>>* children = m_parent->getChildren();
|
||||
auto child_it = std::find(children->begin(), children->end(), this);
|
||||
if(child_it != children->end())
|
||||
children->erase(child_it);
|
||||
if(m_parent->numChildren() == 0)
|
||||
{
|
||||
// signal onlastchildremoved
|
||||
}
|
||||
}
|
||||
|
||||
m_parent = newParent;
|
||||
m_parent->children.push_back(this);
|
||||
newParent->onChildAdded(this);
|
||||
}
|
||||
}
|
||||
|
||||
void RBX::Instance::onChildAdded(RBX::Instance* childAdded)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
#define __APP_V8_TREE_INSTANCE_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <engine/app/Name.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace RBX
|
||||
{
|
||||
|
|
@ -9,9 +11,32 @@ namespace RBX
|
|||
{
|
||||
private:
|
||||
std::string m_name;
|
||||
RBX::Instance* m_parent;
|
||||
std::vector<boost::shared_ptr<RBX::Instance>> m_children;
|
||||
bool m_archivable;
|
||||
public:
|
||||
Instance();
|
||||
Instance(char* name);
|
||||
|
||||
bool contains(RBX::Instance* child);
|
||||
bool isAncestorOf(RBX::Instance* instance);
|
||||
|
||||
virtual bool askSetParent(RBX::Instance* instance); // derive this
|
||||
bool canSetParent(RBX::Instance* instance);
|
||||
virtual bool askAddChild(RBX::Instance* instance); // derive this
|
||||
bool canAddChild(RBX::Instance* instance);
|
||||
|
||||
void createChild(boost::shared_ptr<RBX::Instance>* result, const RBX::Name *className);
|
||||
|
||||
RBX::Instance* getParent() { return this->m_parent; };
|
||||
std::string getName() { return this->m_name };
|
||||
|
||||
void setParent(RBX::Instance* newParent);
|
||||
void setName(std::string name);
|
||||
std::vector<boost::shared_ptr<RBX::Instance>>* getChildren() { return &this->m_children; };
|
||||
int numChildren() { return this->m_children.size() };
|
||||
|
||||
void onChildAdded(RBX::Instance* childAdded);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue