misc(snap): add properties to snap
This commit is contained in:
parent
452c61ef90
commit
0da4d6d67f
4 changed files with 22 additions and 10 deletions
|
@ -119,7 +119,7 @@ void Instance::updateAncestry(std::optional<std::shared_ptr<Instance>> updatedCh
|
|||
|
||||
// Old workspace used to exist, and workspaces differ
|
||||
if (!oldWorkspace.expired() && oldWorkspace != _workspace) {
|
||||
OnWorkspaceRemoved(!oldWorkspace.expired() ? std::make_optional(oldWorkspace.lock()) : std::nullopt);
|
||||
OnWorkspaceRemoved(oldWorkspace.lock());
|
||||
}
|
||||
|
||||
// New workspace exists, and workspaces differ
|
||||
|
@ -171,7 +171,7 @@ void Instance::OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWor
|
|||
// Empty stub
|
||||
}
|
||||
|
||||
void Instance::OnWorkspaceRemoved(std::optional<std::shared_ptr<Workspace>> oldWorkspace) {
|
||||
void Instance::OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) {
|
||||
// Empty stub
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ protected:
|
|||
virtual void OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent);
|
||||
virtual void OnAncestryChanged(std::optional<std::shared_ptr<Instance>> child, std::optional<std::shared_ptr<Instance>> newParent);
|
||||
virtual void OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspace, std::shared_ptr<Workspace> newWorkspace);
|
||||
virtual void OnWorkspaceRemoved(std::optional<std::shared_ptr<Workspace>> oldWorkspace);
|
||||
virtual void OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace);
|
||||
|
||||
// The root data model this object is a descendant of
|
||||
std::optional<std::shared_ptr<DataModel>> dataModel();
|
||||
|
|
|
@ -26,22 +26,22 @@ Snap::Snap(): Instance(&TYPE) {
|
|||
.backingField = &part0,
|
||||
.type = &Data::InstanceRef::TYPE,
|
||||
.codec = fieldCodecOf<Data::InstanceRef, std::weak_ptr<Instance>>(),
|
||||
// .updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
||||
.updateCallback = memberFunctionOf(&Snap::onUpdated, this),
|
||||
}}, { "Part1", {
|
||||
.backingField = &part1,
|
||||
.type = &Data::InstanceRef::TYPE,
|
||||
.codec = fieldCodecOf<Data::InstanceRef, std::weak_ptr<Instance>>(),
|
||||
// .updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
||||
.updateCallback = memberFunctionOf(&Snap::onUpdated, this),
|
||||
}}, { "C0", {
|
||||
.backingField = &c0,
|
||||
.type = &Data::CFrame::TYPE,
|
||||
.codec = fieldCodecOf<Data::CFrame>(),
|
||||
// .updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
||||
.updateCallback = memberFunctionOf(&Snap::onUpdated, this),
|
||||
}}, { "C1", {
|
||||
.backingField = &c0,
|
||||
.type = &Data::CFrame::TYPE,
|
||||
.codec = fieldCodecOf<Data::CFrame>(),
|
||||
// .updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
||||
.updateCallback = memberFunctionOf(&Snap::onUpdated, this),
|
||||
}},
|
||||
}
|
||||
});
|
||||
|
@ -60,13 +60,24 @@ void Snap::OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspa
|
|||
buildJoint();
|
||||
}
|
||||
|
||||
void Snap::OnWorkspaceRemoved(std::optional<std::shared_ptr<Workspace>> oldWorkspace) {
|
||||
void Snap::OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) {
|
||||
if (!this->joint) return;
|
||||
|
||||
if (!oldWorkspace) oldWorkspace.value()->physicsWorld->destroyJoint(this->joint);
|
||||
oldWorkspace->physicsWorld->destroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
}
|
||||
|
||||
void Snap::onUpdated(std::string property) {
|
||||
// We are not in the workspace, so we don't really care what values are currently set
|
||||
if (!workspace()) return;
|
||||
|
||||
// Workspace cannot have changed, so if the joint currently exists, it is in the present one
|
||||
if (this->joint)
|
||||
workspace().value()->physicsWorld->destroyJoint(this->joint);
|
||||
|
||||
buildJoint();
|
||||
}
|
||||
|
||||
void Snap::buildJoint() {
|
||||
if (part0.expired() || part1.expired() || !workspace()) return;
|
||||
|
||||
|
|
|
@ -10,8 +10,9 @@ class Snap : public Instance {
|
|||
rp::FixedJoint* joint = nullptr;
|
||||
protected:
|
||||
void OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) override;
|
||||
void OnWorkspaceRemoved(std::optional<std::shared_ptr<Workspace>> oldWorkspace) override;
|
||||
void OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) override;
|
||||
|
||||
void onUpdated(std::string property);
|
||||
void buildJoint();
|
||||
void breakJoint();
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue