Improved the World generator's interface.

This commit is contained in:
Relintai 2019-11-10 21:14:53 +01:00
parent e0deb2ea66
commit ca1740ee04
16 changed files with 138 additions and 59 deletions

View File

@ -183,14 +183,6 @@ void BiomeData::set_environment_datas(const Vector<Variant> &environment_datas)
}
}
Ref<Biome> BiomeData::setup_biome(int seed) {
if (has_method("_setup_biome")) {
return call("_setup_biome", seed);
}
return Ref<Biome>(NULL);
}
BiomeData::BiomeData() {
}
@ -201,10 +193,6 @@ BiomeData::~BiomeData() {
}
void BiomeData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "room", PROPERTY_HINT_RESOURCE_TYPE, "Biome"), "_setup_biome", PropertyInfo(Variant::INT, "seed")));
ClassDB::bind_method(D_METHOD("setup_biome", "seed"), &BiomeData::setup_biome);
ClassDB::bind_method(D_METHOD("get_level_range"), &BiomeData::get_level_range);
ClassDB::bind_method(D_METHOD("set_level_range", "value"), &BiomeData::set_level_range);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range");

View File

@ -68,8 +68,6 @@ public:
Vector<Variant> get_environment_datas();
void set_environment_datas(const Vector<Variant> &environment_datas);
Ref<Biome> setup_biome(int seed);
BiomeData();
~BiomeData();

View File

@ -305,16 +305,6 @@ void DungeonData::set_environment_datas(const Vector<Variant> &environment_datas
}
}
Ref<Dungeon> DungeonData::setup_dungeon(int seed) {
if (has_method("_setup_dungeon")) {
return call("_setup_dungeon", seed);
}
return Ref<Dungeon>();
}
DungeonData::DungeonData() {
_min_sizex = 0;
_min_sizey = 0;
@ -338,10 +328,6 @@ DungeonData::~DungeonData() {
}
void DungeonData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "room", PROPERTY_HINT_RESOURCE_TYPE, "Dungeon"), "_setup_dungeon", PropertyInfo(Variant::INT, "seed")));
ClassDB::bind_method(D_METHOD("setup_dungeon", "seed"), &DungeonData::setup_dungeon);
ClassDB::bind_method(D_METHOD("get_level_range"), &DungeonData::get_level_range);
ClassDB::bind_method(D_METHOD("set_level_range", "value"), &DungeonData::set_level_range);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range");

View File

@ -111,8 +111,6 @@ public:
Vector<Variant> get_entity_datas();
void set_entity_datas(const Vector<Variant> &entity_datas);
Ref<Dungeon> setup_dungeon(int seed);
DungeonData();
~DungeonData();

View File

@ -168,14 +168,6 @@ void DungeonRoomData::set_entity_datas(const Vector<Variant> &entity_datas) {
}
}
Ref<DungeonRoom> DungeonRoomData::setup_room(int seed) {
if (has_method("_setup_room")) {
return call("_setup_room", seed);
}
return Ref<DungeonRoom>();
}
DungeonRoomData::DungeonRoomData() {
_min_sizex = 0;
_min_sizey = 0;
@ -190,10 +182,6 @@ DungeonRoomData::~DungeonRoomData() {
}
void DungeonRoomData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "room", PROPERTY_HINT_RESOURCE_TYPE, "DungeonRoom"), "_setup_room", PropertyInfo(Variant::INT, "seed")));
ClassDB::bind_method(D_METHOD("setup_room", "seed"), &DungeonRoomData::setup_room);
ClassDB::bind_method(D_METHOD("get_level_range"), &DungeonRoomData::get_level_range);
ClassDB::bind_method(D_METHOD("set_level_range", "value"), &DungeonRoomData::set_level_range);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range");

View File

@ -58,8 +58,6 @@ public:
Vector<Variant> get_environment_datas();
void set_environment_datas(const Vector<Variant> &environment_datas);
Ref<DungeonRoom> setup_room(int seed);
//Entities
Ref<EntityData> get_entity_data(const int index) const;
void set_entity_data(const int index, const Ref<EntityData> entity_data);

View File

@ -106,14 +106,6 @@ void PlanetData::set_environment_datas(const Vector<Variant> &environment_datas)
}
}
Ref<Planet> PlanetData::setup_planet(int seed) {
if (has_method("_setup_planet")) {
return call("_setup_planet", seed);
}
return Ref<Planet>(NULL);
}
PlanetData::PlanetData() {
_id = 0;
}
@ -122,11 +114,6 @@ PlanetData::~PlanetData() {
}
void PlanetData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "biome", PROPERTY_HINT_RESOURCE_TYPE, "Planet"), "_setup_planet", PropertyInfo(Variant::INT, "seed")));
ClassDB::bind_method(D_METHOD("setup_planet", "seed"), &PlanetData::setup_planet);
ClassDB::bind_method(D_METHOD("get_id"), &PlanetData::get_id);
ClassDB::bind_method(D_METHOD("set_id", "value"), &PlanetData::set_id);
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");

View File

@ -47,8 +47,6 @@ public:
Vector<Variant> get_environment_datas();
void set_environment_datas(const Vector<Variant> &environment_datas);
Ref<Planet> setup_planet(int seed);
PlanetData();
~PlanetData();

View File

@ -14,6 +14,15 @@ void Biome::set_environment(Ref<EnvironmentData> value) {
_environment = value;
}
Ref<BiomeData> Biome::get_data() {
return _data;
}
void Biome::set_data(Ref<BiomeData> value) {
_data = value;
setup();
}
//// Prop Data ////
Ref<WorldGeneratorPropData> Biome::get_prop_data(const int index) const {
ERR_FAIL_INDEX_V(index, _prop_datas.size(), Ref<WorldGeneratorPropData>());
@ -108,6 +117,12 @@ void Biome::generate_stack_bind(Node *chunk, int x, int z, bool spawn_mobs) {
generate_stack(Object::cast_to<VoxelChunk>(chunk), x, z, spawn_mobs);
}
void Biome::setup() {
if (has_method("_setup")) {
call("_setup");
}
}
Biome::Biome() {
}
@ -119,9 +134,11 @@ Biome::~Biome() {
}
void Biome::_bind_methods() {
BIND_VMETHOD(MethodInfo("_setup"));
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
BIND_VMETHOD(MethodInfo("_generate_stack", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), PropertyInfo(Variant::INT, "x"), PropertyInfo(Variant::INT, "z"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
ClassDB::bind_method(D_METHOD("setup"), &Biome::setup);
ClassDB::bind_method(D_METHOD("generate_chunk", "chunk", "spawn_mobs"), &Biome::generate_chunk_bind);
ClassDB::bind_method(D_METHOD("generate_stack", "chunk", "x", "z", "spawn_mobs"), &Biome::generate_stack_bind);
@ -133,6 +150,10 @@ void Biome::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_environment", "value"), &Biome::set_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_environment", "get_environment");
ClassDB::bind_method(D_METHOD("get_data"), &Biome::get_data);
ClassDB::bind_method(D_METHOD("set_data", "value"), &Biome::set_data);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PlanetData"), "set_data", "get_data");
//Props
ClassDB::bind_method(D_METHOD("get_prop_data", "index"), &Biome::get_prop_data);
ClassDB::bind_method(D_METHOD("set_prop_data", "index", "data"), &Biome::set_prop_data);

View File

@ -9,6 +9,10 @@
#include "../../world/environment_data.h"
#include "../../../entity_spell_system/entities/data/entity_data.h"
#include "../data/biome_data.h"
class BiomeData;
class Biome : public Reference {
GDCLASS(Biome, Reference);
@ -20,6 +24,9 @@ public:
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
Ref<BiomeData> get_data();
void set_data(Ref<BiomeData> value);
//WorldGeneratorPropData
Ref<WorldGeneratorPropData> get_prop_data(const int index) const;
void set_prop_data(const int index, const Ref<WorldGeneratorPropData> prop_data);
@ -49,6 +56,8 @@ public:
void generate_stack(VoxelChunk *chunk, int x, int z, bool spawn_mobs);
void generate_stack_bind(Node *chunk, int x, int z, bool spawn_mobs);
void setup();
Biome();
~Biome();
@ -59,6 +68,7 @@ private:
Vector2 _level_range;
Ref<EnvironmentData> _environment;
Ref<BiomeData> _data;
Vector<Ref<WorldGeneratorPropData> > _prop_datas;
Vector<Ref<EntityData> > _entity_datas;
Vector<Ref<Dungeon> > _dungeons;

View File

@ -72,6 +72,15 @@ void Dungeon::set_environment(Ref<EnvironmentData> value) {
_environment = value;
}
Ref<DungeonData> Dungeon::get_data() {
return _data;
}
void Dungeon::set_data(Ref<DungeonData> value) {
_data = value;
setup();
}
//Rooms
Ref<DungeonRoom> Dungeon::get_dungeon_room(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_rooms.size(), Ref<DungeonRoom>());
@ -297,6 +306,10 @@ void Dungeon::_bind_methods() {
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");
ClassDB::bind_method(D_METHOD("get_data"), &Dungeon::get_data);
ClassDB::bind_method(D_METHOD("set_data", "value"), &Dungeon::set_data);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PlanetData"), "set_data", "get_data");
//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);

View File

@ -12,6 +12,10 @@
#include "../../../entity_spell_system/entities/data/entity_data.h"
#include "../data/dungeon_data.h"
class DungeonData;
class Dungeon : public Reference {
GDCLASS(Dungeon, Reference);
@ -50,6 +54,9 @@ public:
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
Ref<DungeonData> get_data();
void set_data(Ref<DungeonData> value);
//Rooms
Ref<DungeonRoom> get_dungeon_room(const int index) const;
void set_dungeon_room(const int index, const Ref<DungeonRoom> dungeon_room);
@ -119,6 +126,7 @@ private:
int _room_count;
Ref<EnvironmentData> _environment;
Ref<DungeonData> _data;
Vector<Ref<DungeonRoom> > _dungeon_rooms;
Vector<Ref<DungeonRoom> > _dungeon_start_rooms;
Vector<Ref<DungeonRoom> > _dungeon_end_rooms;

View File

@ -65,6 +65,15 @@ void DungeonRoom::set_environment(Ref<EnvironmentData> value) {
_environment = value;
}
Ref<DungeonRoomData> DungeonRoom::get_data() {
return _data;
}
void DungeonRoom::set_data(Ref<DungeonRoomData> value) {
_data = value;
setup();
}
Ref<VoxelStructure> DungeonRoom::get_structure() {
return _structure;
}
@ -209,6 +218,10 @@ void DungeonRoom::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_environment", "value"), &DungeonRoom::set_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_environment", "get_environment");
ClassDB::bind_method(D_METHOD("get_data"), &DungeonRoom::get_data);
ClassDB::bind_method(D_METHOD("set_data", "value"), &DungeonRoom::set_data);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PlanetData"), "set_data", "get_data");
ClassDB::bind_method(D_METHOD("get_structure"), &DungeonRoom::get_structure);
ClassDB::bind_method(D_METHOD("set_structure", "value"), &DungeonRoom::set_structure);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure"), "set_structure", "get_structure");

View File

@ -10,6 +10,10 @@
#include "../../world/environment_data.h"
#include "../../../entity_spell_system/entities/data/entity_data.h"
#include "../data/dungeon_room_data.h"
class DungeonRoomData;
class DungeonRoom : public Reference {
GDCLASS(DungeonRoom, Reference);
@ -44,6 +48,9 @@ public:
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
Ref<DungeonRoomData> get_data();
void set_data(Ref<DungeonRoomData> value);
//Structure
Ref<VoxelStructure> get_structure();
void set_structure(Ref<VoxelStructure> structure);
@ -89,6 +96,7 @@ private:
int _sizez;
Ref<EnvironmentData> _environment;
Ref<DungeonRoomData> _data;
Ref<VoxelStructure> _structure;
Vector<Ref<WorldGeneratorPropData> > _prop_datas;
Vector<Ref<EntityData> > _entity_datas;

View File

@ -21,6 +21,15 @@ void Planet::set_environment(Ref<EnvironmentData> value) {
_environment = value;
}
Ref<PlanetData> Planet::get_data() {
return _data;
}
void Planet::set_data(Ref<PlanetData> value) {
_data = value;
setup();
}
Ref<Biome> Planet::get_biome(const int index) const {
ERR_FAIL_INDEX_V(index, _biomes.size(), Ref<Biome>());
@ -44,6 +53,30 @@ int Planet::get_biome_count() const {
return _biomes.size();
}
//// Dungeons ////
Ref<Dungeon> Planet::get_dungeon(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeons.size(), Ref<Dungeon>());
return _dungeons.get(index);
}
void Planet::set_dungeon(const int index, const Ref<Dungeon> dungeon) {
ERR_FAIL_INDEX(index, _dungeons.size());
_dungeons.set(index, dungeon);
}
void Planet::add_dungeon(const Ref<Dungeon> dungeon) {
_dungeons.push_back(dungeon);
}
void Planet::remove_dungeon(const int index) {
ERR_FAIL_INDEX(index, _dungeons.size());
_dungeons.remove(index);
}
int Planet::get_dungeon_count() const {
return _dungeons.size();
}
void Planet::setup() {
if (has_method("_setup")) {
call("_setup");
@ -95,6 +128,11 @@ void Planet::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_environment", "value"), &Planet::set_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_environment", "get_environment");
ClassDB::bind_method(D_METHOD("get_data"), &Planet::get_data);
ClassDB::bind_method(D_METHOD("set_data", "value"), &Planet::set_data);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PlanetData"), "set_data", "get_data");
//biomes
ClassDB::bind_method(D_METHOD("get_biome", "index"), &Planet::get_biome);
ClassDB::bind_method(D_METHOD("set_biome", "index", "data"), &Planet::set_biome);
ClassDB::bind_method(D_METHOD("add_biome", "biome"), &Planet::add_biome);
@ -102,6 +140,14 @@ void Planet::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_biome_count"), &Planet::get_biome_count);
//Dungeons
ClassDB::bind_method(D_METHOD("get_dungeon", "index"), &Planet::get_dungeon);
ClassDB::bind_method(D_METHOD("set_dungeon", "index", "data"), &Planet::set_dungeon);
ClassDB::bind_method(D_METHOD("add_dungeon", "dungeon"), &Planet::add_dungeon);
ClassDB::bind_method(D_METHOD("remove_dungeon", "index"), &Planet::remove_dungeon);
ClassDB::bind_method(D_METHOD("get_dungeon_count"), &Planet::get_dungeon_count);
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "_generate_map"));
ClassDB::bind_method(D_METHOD("generate_map"), &Planet::generate_map);

View File

@ -6,8 +6,13 @@
#include "../../world/voxel_chunk.h"
#include "biome.h"
#include "dungeon.h"
#include "../../world/environment_data.h"
#include "../data/planet_data.h"
class PlanetData;
class Planet : public Reference {
GDCLASS(Planet, Reference);
@ -22,6 +27,10 @@ public:
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
Ref<PlanetData> get_data();
void set_data(Ref<PlanetData> value);
//Biomes
Ref<Biome> get_biome(const int index) const;
void set_biome(const int index, const Ref<Biome> biome);
void add_biome(const Ref<Biome> biome);
@ -29,6 +38,14 @@ public:
int get_biome_count() const;
//Dungeons
Ref<Dungeon> get_dungeon(const int index) const;
void set_dungeon(const int index, const Ref<Dungeon> dungeon);
void add_dungeon(const Ref<Dungeon> dungeon);
void remove_dungeon(const int index);
int get_dungeon_count() const;
void setup();
void generate_chunk(VoxelChunk *chunk, bool spawn_mobs);
void generate_chunk_bind(Node *chunk, bool spawn_mobs);
@ -44,7 +61,9 @@ private:
int _seed;
Vector2 _level_range;
Ref<EnvironmentData> _environment;
Ref<PlanetData> _data;
Vector<Ref<Biome> > _biomes;
Vector<Ref<Dungeon> > _dungeons;
};
#endif