pandemonium_engine/modules/props_2d/props/prop_2d_data_scene.cpp

67 lines
1.6 KiB
C++
Raw Normal View History

2023-12-17 22:59:50 +01:00
#include "prop_2d_data_scene.h"
#include "../prop_2d_scene_instance.h"
#include "prop_2d_data.h"
Ref<PackedScene> Prop2DDataScene::get_scene() {
return _scene;
}
void Prop2DDataScene::set_scene(const Ref<PackedScene> &value) {
_scene = value;
}
bool Prop2DDataScene::_processor_handles(Node *node) {
Prop2DSceneInstance *i = Object::cast_to<Prop2DSceneInstance>(node);
return i;
}
void Prop2DDataScene::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform, Ref<Prop2DDataEntry> entry) {
Prop2DSceneInstance *i = Object::cast_to<Prop2DSceneInstance>(node);
ERR_FAIL_COND(!i);
Ref<Prop2DDataScene> l;
if (entry.is_valid()) {
l = entry;
} else {
l.instance();
}
l->set_scene(i->get_scene());
2022-03-16 09:02:48 +01:00
Prop2DDataEntry::_processor_process(prop_data, node, transform, l);
}
Node *Prop2DDataScene::_processor_get_node_for(const Transform2D &transform, Node *node) {
Prop2DSceneInstance *i = nullptr;
if (!node) {
i = memnew(Prop2DSceneInstance);
} else {
i = Object::cast_to<Prop2DSceneInstance>(node);
}
i->set_scene(get_scene());
return Prop2DDataEntry::_processor_get_node_for(transform, i);
}
Prop2DDataScene::Prop2DDataScene() {
_snap_to_mesh = true;
_snap_axis = Vector3(0, 1, 0);
}
Prop2DDataScene::~Prop2DDataScene() {
if (_scene.is_valid())
_scene.unref();
}
void Prop2DDataScene::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_scene"), &Prop2DDataScene::get_scene);
ClassDB::bind_method(D_METHOD("set_scene", "value"), &Prop2DDataScene::set_scene);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", "get_scene");
}