Added an editable property to VoxelWorld, and made the world editor plugin make use of it.

This commit is contained in:
Relintai 2020-03-31 13:25:31 +02:00
parent dfafb23342
commit f7fd0193ea
3 changed files with 24 additions and 1 deletions

View File

@ -24,6 +24,13 @@ SOFTWARE.
#include "voxel_chunk.h"
bool VoxelWorld::get_editable() const {
return _editable;
}
void VoxelWorld::set_editable(const bool value) {
_editable = value;
}
int VoxelWorld::get_chunk_size_x() const {
return _chunk_size_x;
}
@ -376,6 +383,8 @@ void VoxelWorld::on_chunk_mesh_generation_finished_bind(Node *p_chunk) {
}
VoxelWorld::VoxelWorld() {
_editable = false;
_chunk_size_x = 16;
_chunk_size_y = 16;
_chunk_size_z = 16;
@ -472,6 +481,10 @@ void VoxelWorld::_notification(int p_what) {
void VoxelWorld::_bind_methods() {
ADD_SIGNAL(MethodInfo("chunk_mesh_generation_finished", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
ClassDB::bind_method(D_METHOD("get_editable"), &VoxelWorld::get_editable);
ClassDB::bind_method(D_METHOD("set_editable", "value"), &VoxelWorld::set_editable);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "get_editable");
ClassDB::bind_method(D_METHOD("get_chunk_size_x"), &VoxelWorld::get_chunk_size_x);
ClassDB::bind_method(D_METHOD("set_chunk_size_x", "value"), &VoxelWorld::set_chunk_size_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_chunk_size_x", "get_chunk_size_x");

View File

@ -39,6 +39,9 @@ class VoxelWorld : public Navigation {
GDCLASS(VoxelWorld, Navigation);
public:
bool get_editable() const;
void set_editable(const bool value);
int get_chunk_size_x() const;
void set_chunk_size_x(const int value);
@ -170,6 +173,8 @@ public:
};
private:
bool _editable;
int _chunk_size_x;
int _chunk_size_y;
int _chunk_size_z;

View File

@ -82,7 +82,12 @@ void VoxelWorldEditorPlugin::edit(Object *p_object) {
bool VoxelWorldEditorPlugin::handles(Object *p_object) const {
return p_object->is_class("VoxelWorld");
if (!p_object->is_class("VoxelWorld"))
return false;
VoxelWorld *w = Object::cast_to<VoxelWorld>(p_object);
return w->get_editable();
}
void VoxelWorldEditorPlugin::make_visible(bool p_visible) {