diff --git a/main/dungeon.cpp b/main/dungeon.cpp index adc3683..8b1b219 100644 --- a/main/dungeon.cpp +++ b/main/dungeon.cpp @@ -145,15 +145,6 @@ void Dungeon::set_room_count(int value) { _room_count = value; } -#ifdef VOXELMAN_PRESENT -Ref Dungeon::get_environment() { - return _environment; -} -void Dungeon::set_environment(Ref value) { - _environment = value; -} -#endif - //Rooms Ref Dungeon::get_dungeon_room(const int index) const { ERR_FAIL_INDEX_V(index, _dungeon_rooms.size(), Ref()); @@ -549,94 +540,6 @@ void Dungeon::set_entity_datas(const Vector &entity_datas) { } #endif -#ifdef VOXELMAN_PRESENT -//// Surfaces //// -Ref Dungeon::get_voxel_surface(const int index) const { - ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref()); - - return _voxel_surfaces.get(index); -} -void Dungeon::set_voxel_surface(const int index, const Ref voxel_surface) { - ERR_FAIL_INDEX(index, _voxel_surfaces.size()); - - _voxel_surfaces.set(index, voxel_surface); -} -void Dungeon::add_voxel_surface(const Ref voxel_surface) { - _voxel_surfaces.push_back(voxel_surface); -} -void Dungeon::remove_voxel_surface(const int index) { - ERR_FAIL_INDEX(index, _voxel_surfaces.size()); - - _voxel_surfaces.remove(index); -} -int Dungeon::get_voxel_surface_count() const { - return _voxel_surfaces.size(); -} - -Vector Dungeon::get_voxel_surfaces() { - Vector r; - for (int i = 0; i < _voxel_surfaces.size(); i++) { -#if VERSION_MAJOR < 4 - r.push_back(_voxel_surfaces[i].get_ref_ptr()); -#else - r.push_back(_voxel_surfaces[i]); -#endif - } - return r; -} -void Dungeon::set_voxel_surfaces(const Vector &voxel_surfaces) { - _voxel_surfaces.clear(); - for (int i = 0; i < voxel_surfaces.size(); i++) { - Ref voxel_surface = Ref(voxel_surfaces[i]); - - _voxel_surfaces.push_back(voxel_surface); - } -} - -//Environments -Ref Dungeon::get_environment_data(const int index) const { - ERR_FAIL_INDEX_V(index, _environment_datas.size(), Ref()); - - return _environment_datas.get(index); -} -void Dungeon::set_environment_data(const int index, const Ref environment_data) { - ERR_FAIL_INDEX(index, _environment_datas.size()); - - _environment_datas.set(index, environment_data); -} -void Dungeon::add_environment_data(const Ref environment_data) { - _environment_datas.push_back(environment_data); -} -void Dungeon::remove_environment_data(const int index) { - ERR_FAIL_INDEX(index, _environment_datas.size()); - - _environment_datas.remove(index); -} -int Dungeon::get_environment_data_count() const { - return _environment_datas.size(); -} - -Vector Dungeon::get_environment_datas() { - Vector r; - for (int i = 0; i < _environment_datas.size(); i++) { -#if VERSION_MAJOR < 4 - r.push_back(_environment_datas[i].get_ref_ptr()); -#else - r.push_back(_environment_datas[i]); -#endif - } - return r; -} -void Dungeon::set_environment_datas(const Vector &environment_datas) { - _environment_datas.clear(); - for (int i = 0; i < environment_datas.size(); i++) { - Ref environment_data = Ref(environment_datas[i]); - - _environment_datas.push_back(environment_data); - } -} -#endif - Ref Dungeon::instance(const int seed) { Ref inst; @@ -787,7 +690,101 @@ void Dungeon::setup() { } } + #ifdef VOXELMAN_PRESENT +Ref Dungeon::get_environment() { + return _environment; +} +void Dungeon::set_environment(Ref value) { + _environment = value; +} + +//// Surfaces //// +Ref Dungeon::get_voxel_surface(const int index) const { + ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref()); + + return _voxel_surfaces.get(index); +} +void Dungeon::set_voxel_surface(const int index, const Ref voxel_surface) { + ERR_FAIL_INDEX(index, _voxel_surfaces.size()); + + _voxel_surfaces.set(index, voxel_surface); +} +void Dungeon::add_voxel_surface(const Ref voxel_surface) { + _voxel_surfaces.push_back(voxel_surface); +} +void Dungeon::remove_voxel_surface(const int index) { + ERR_FAIL_INDEX(index, _voxel_surfaces.size()); + + _voxel_surfaces.remove(index); +} +int Dungeon::get_voxel_surface_count() const { + return _voxel_surfaces.size(); +} + +Vector Dungeon::get_voxel_surfaces() { + Vector r; + for (int i = 0; i < _voxel_surfaces.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_voxel_surfaces[i].get_ref_ptr()); +#else + r.push_back(_voxel_surfaces[i]); +#endif + } + return r; +} +void Dungeon::set_voxel_surfaces(const Vector &voxel_surfaces) { + _voxel_surfaces.clear(); + for (int i = 0; i < voxel_surfaces.size(); i++) { + Ref voxel_surface = Ref(voxel_surfaces[i]); + + _voxel_surfaces.push_back(voxel_surface); + } +} + +//Environments +Ref Dungeon::get_environment_data(const int index) const { + ERR_FAIL_INDEX_V(index, _environment_datas.size(), Ref()); + + return _environment_datas.get(index); +} +void Dungeon::set_environment_data(const int index, const Ref environment_data) { + ERR_FAIL_INDEX(index, _environment_datas.size()); + + _environment_datas.set(index, environment_data); +} +void Dungeon::add_environment_data(const Ref environment_data) { + _environment_datas.push_back(environment_data); +} +void Dungeon::remove_environment_data(const int index) { + ERR_FAIL_INDEX(index, _environment_datas.size()); + + _environment_datas.remove(index); +} +int Dungeon::get_environment_data_count() const { + return _environment_datas.size(); +} + +Vector Dungeon::get_environment_datas() { + Vector r; + for (int i = 0; i < _environment_datas.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_environment_datas[i].get_ref_ptr()); +#else + r.push_back(_environment_datas[i]); +#endif + } + return r; +} +void Dungeon::set_environment_datas(const Vector &environment_datas) { + _environment_datas.clear(); + for (int i = 0; i < environment_datas.size(); i++) { + Ref environment_data = Ref(environment_datas[i]); + + _environment_datas.push_back(environment_data); + } +} + void Dungeon::setup_library(Ref library) { if (has_method("_setup_library")) { call("_setup_library", library); @@ -849,21 +846,6 @@ void Dungeon::generate_structure(Ref structure, bool spawn_mobs) call("_generate_structure", structure, spawn_mobs); } } -#else - -void Dungeon::setup_library(Ref library) { - if (has_method("_setup_library")) { - call("_setup_library", library); - } -} - -void Dungeon::generate_chunk(Ref chunk, bool spawn_mobs) { - ERR_FAIL_COND(!chunk.is_valid()); - - if (has_method("_generate_chunk")) { - call("_generate_chunk", chunk, spawn_mobs); - } -} #endif Ref Dungeon::generate_map() { @@ -897,10 +879,6 @@ Dungeon::Dungeon() { _room_count = 0; } Dungeon::~Dungeon() { -#ifdef VOXELMAN_PRESENT - _environment.unref(); -#endif - _dungeon_rooms.clear(); _dungeon_start_rooms.clear(); _dungeon_end_rooms.clear(); @@ -911,6 +889,8 @@ Dungeon::~Dungeon() { #endif #ifdef VOXELMAN_PRESENT + _environment.unref(); + _environment_datas.clear(); _voxel_surfaces.clear(); #endif @@ -924,24 +904,11 @@ void Dungeon::_bind_methods() { BIND_VMETHOD(MethodInfo("_setup")); -#ifdef VOXELMAN_PRESENT - BIND_VMETHOD(MethodInfo("_setup_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary"))); - BIND_VMETHOD(MethodInfo("_generate_structure", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure"), PropertyInfo(Variant::BOOL, "spawn_mobs"))); - BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), PropertyInfo(Variant::BOOL, "spawn_mobs"))); -#endif - ClassDB::bind_method(D_METHOD("instance", "seed"), &Dungeon::instance); ClassDB::bind_method(D_METHOD("_instance", "p_seed", "p_instance"), &Dungeon::_instance); ClassDB::bind_method(D_METHOD("setup"), &Dungeon::setup); -#ifdef VOXELMAN_PRESENT - ClassDB::bind_method(D_METHOD("setup_library", "library"), &Dungeon::setup_library); - ClassDB::bind_method(D_METHOD("_setup_library", "library"), &Dungeon::_setup_library); - - ClassDB::bind_method(D_METHOD("generate_chunk", "chunk", "spawn_mobs"), &Dungeon::generate_chunk); - ClassDB::bind_method(D_METHOD("generate_structure", "structure", "spawn_mobs"), &Dungeon::generate_structure); -#endif ClassDB::bind_method(D_METHOD("get_current_seed"), &Dungeon::get_current_seed); ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &Dungeon::set_current_seed); @@ -1017,13 +984,6 @@ void Dungeon::_bind_methods() { ClassDB::bind_method(D_METHOD("set_room_count", "value"), &Dungeon::set_room_count); ADD_PROPERTY(PropertyInfo(Variant::INT, "room_count"), "set_room_count", "get_room_count"); -#ifdef VOXELMAN_PRESENT - //Environment - ClassDB::bind_method(D_METHOD("get_environment"), &Dungeon::get_environment); - ClassDB::bind_method(D_METHOD("set_environment", "value"), &Dungeon::set_environment); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_environment", "get_environment"); -#endif - //Rooms ClassDB::bind_method(D_METHOD("get_dungeon_room", "index"), &Dungeon::get_dungeon_room); ClassDB::bind_method(D_METHOD("set_dungeon_room", "index", "data"), &Dungeon::set_dungeon_room); @@ -1130,6 +1090,21 @@ void Dungeon::_bind_methods() { #endif #ifdef VOXELMAN_PRESENT + BIND_VMETHOD(MethodInfo("_setup_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary"))); + BIND_VMETHOD(MethodInfo("_generate_structure", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure"), PropertyInfo(Variant::BOOL, "spawn_mobs"))); + BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), PropertyInfo(Variant::BOOL, "spawn_mobs"))); + + ClassDB::bind_method(D_METHOD("setup_library", "library"), &Dungeon::setup_library); + ClassDB::bind_method(D_METHOD("_setup_library", "library"), &Dungeon::_setup_library); + + ClassDB::bind_method(D_METHOD("generate_chunk", "chunk", "spawn_mobs"), &Dungeon::generate_chunk); + ClassDB::bind_method(D_METHOD("generate_structure", "structure", "spawn_mobs"), &Dungeon::generate_structure); + + //Environment + ClassDB::bind_method(D_METHOD("get_environment"), &Dungeon::get_environment); + ClassDB::bind_method(D_METHOD("set_environment", "value"), &Dungeon::set_environment); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_environment", "get_environment"); + //Environments ClassDB::bind_method(D_METHOD("get_environment_data", "index"), &Dungeon::get_environment_data); ClassDB::bind_method(D_METHOD("set_environment_data", "index", "data"), &Dungeon::set_environment_data); diff --git a/main/dungeon.h b/main/dungeon.h index 9b842ac..68bcfc5 100644 --- a/main/dungeon.h +++ b/main/dungeon.h @@ -110,12 +110,6 @@ public: int get_room_count(); void set_room_count(int value); -#ifdef VOXELMAN_PRESENT - //Environment - Ref get_environment(); - void set_environment(Ref value); -#endif - //Rooms Ref get_dungeon_room(const int index) const; void set_dungeon_room(const int index, const Ref dungeon_room); @@ -208,7 +202,16 @@ public: void set_entity_datas(const Vector &entity_datas); #endif + Ref instance(const int seed); + virtual Ref _instance(const int seed, Ref inst); + + void setup(); + #ifdef VOXELMAN_PRESENT + //Environment + Ref get_environment(); + void set_environment(Ref value); + //Environments Ref get_environment_data(const int index) const; void set_environment_data(const int index, const Ref environment_data); @@ -218,9 +221,7 @@ public: Vector get_environment_datas(); void set_environment_datas(const Vector &environment_datas); -#endif -#ifdef VOXELMAN_PRESENT //Surfaces Ref get_voxel_surface(const int index) const; void set_voxel_surface(const int index, const Ref voxel_surface); @@ -231,14 +232,6 @@ public: Vector get_voxel_surfaces(); void set_voxel_surfaces(const Vector &voxel_surfaces); -#endif - - Ref instance(const int seed); - virtual Ref _instance(const int seed, Ref inst); - - void setup(); - -#ifdef VOXELMAN_PRESENT void setup_library(Ref library); void _setup_library(Ref library); @@ -280,9 +273,6 @@ private: int _min_room_count; int _max_room_count; -#ifdef VOXELMAN_PRESENT - Ref _environment; -#endif Vector > _dungeon_rooms; Vector > _dungeon_start_rooms; @@ -299,10 +289,9 @@ private: #endif #ifdef VOXELMAN_PRESENT - Vector > _environment_datas; -#endif + Ref _environment; -#ifdef VOXELMAN_PRESENT + Vector > _environment_datas; Vector > _voxel_surfaces; #endif };