Cleanups to the api, also props will now get added to VoxelmanLibrary.

This commit is contained in:
Relintai 2020-02-16 02:50:35 +01:00
parent 09372b1469
commit a08917370c
14 changed files with 87 additions and 29 deletions

View File

@ -272,7 +272,7 @@ void BiomeData::set_liquid_voxel_surface(const int index, const Ref<VoxelSurface
_liquid_voxel_surfaces.set(index, voxel_surface);
}
void BiomeData::add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface) {
void BiomeData::add_liquid_surface(const Ref<VoxelSurface> voxel_surface) {
_liquid_voxel_surfaces.push_back(voxel_surface);
}
void BiomeData::remove_liquid_voxel_surface(const int index) {
@ -401,7 +401,7 @@ void BiomeData::_bind_methods() {
//Liquid Surfaces
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface", "index"), &BiomeData::get_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surface", "index", "data"), &BiomeData::set_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_voxel_surface", "voxel_surface"), &BiomeData::add_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_surface", "voxel_surface"), &BiomeData::add_liquid_surface);
ClassDB::bind_method(D_METHOD("remove_liquid_voxel_surface", "index"), &BiomeData::remove_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface_count"), &BiomeData::get_liquid_voxel_surface_count);

View File

@ -118,7 +118,7 @@ public:
//Liquid Surfaces
Ref<VoxelSurface> get_liquid_voxel_surface(const int index) const;
void set_liquid_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void add_liquid_surface(const Ref<VoxelSurface> voxel_surface);
void remove_liquid_voxel_surface(const int index);
int get_liquid_voxel_surface_count() const;

View File

@ -353,7 +353,7 @@ void DungeonData::set_liquid_voxel_surface(const int index, const Ref<VoxelSurfa
_liquid_voxel_surfaces.set(index, voxel_surface);
}
void DungeonData::add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface) {
void DungeonData::add_liquid_surface(const Ref<VoxelSurface> voxel_surface) {
_liquid_voxel_surfaces.push_back(voxel_surface);
}
void DungeonData::remove_liquid_voxel_surface(const int index) {
@ -585,7 +585,7 @@ void DungeonData::_bind_methods() {
//Liquid Surfaces
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface", "index"), &DungeonData::get_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surface", "index", "data"), &DungeonData::set_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_voxel_surface", "voxel_surface"), &DungeonData::add_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_surface", "voxel_surface"), &DungeonData::add_liquid_surface);
ClassDB::bind_method(D_METHOD("remove_liquid_voxel_surface", "index"), &DungeonData::remove_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface_count"), &DungeonData::get_liquid_voxel_surface_count);

View File

@ -159,7 +159,7 @@ public:
//Liquid Surfaces
Ref<VoxelSurface> get_liquid_voxel_surface(const int index) const;
void set_liquid_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void add_liquid_surface(const Ref<VoxelSurface> voxel_surface);
void remove_liquid_voxel_surface(const int index);
int get_liquid_voxel_surface_count() const;

View File

@ -216,7 +216,7 @@ void DungeonRoomData::set_liquid_voxel_surface(const int index, const Ref<VoxelS
_liquid_voxel_surfaces.set(index, voxel_surface);
}
void DungeonRoomData::add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface) {
void DungeonRoomData::add_liquid_surface(const Ref<VoxelSurface> voxel_surface) {
_liquid_voxel_surfaces.push_back(voxel_surface);
}
void DungeonRoomData::remove_liquid_voxel_surface(const int index) {
@ -401,7 +401,7 @@ void DungeonRoomData::_bind_methods() {
//Liquid Surfaces
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface", "index"), &DungeonRoomData::get_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surface", "index", "data"), &DungeonRoomData::set_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_voxel_surface", "voxel_surface"), &DungeonRoomData::add_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_surface", "voxel_surface"), &DungeonRoomData::add_liquid_surface);
ClassDB::bind_method(D_METHOD("remove_liquid_voxel_surface", "index"), &DungeonRoomData::remove_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface_count"), &DungeonRoomData::get_liquid_voxel_surface_count);

View File

@ -108,7 +108,7 @@ public:
//Liquid Surfaces
Ref<VoxelSurface> get_liquid_voxel_surface(const int index) const;
void set_liquid_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void add_liquid_surface(const Ref<VoxelSurface> voxel_surface);
void remove_liquid_voxel_surface(const int index);
int get_liquid_voxel_surface_count() const;

View File

@ -193,7 +193,7 @@ void PlanetData::set_liquid_voxel_surface(const int index, const Ref<VoxelSurfac
_liquid_voxel_surfaces.set(index, voxel_surface);
}
void PlanetData::add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface) {
void PlanetData::add_liquid_surface(const Ref<VoxelSurface> voxel_surface) {
_liquid_voxel_surfaces.push_back(voxel_surface);
}
void PlanetData::remove_liquid_voxel_surface(const int index) {
@ -300,7 +300,7 @@ void PlanetData::_bind_methods() {
//Liquid Surfaces
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface", "index"), &PlanetData::get_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surface", "index", "data"), &PlanetData::set_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_voxel_surface", "voxel_surface"), &PlanetData::add_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("add_liquid_surface", "voxel_surface"), &PlanetData::add_liquid_surface);
ClassDB::bind_method(D_METHOD("remove_liquid_voxel_surface", "index"), &PlanetData::remove_liquid_voxel_surface);
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface_count"), &PlanetData::get_liquid_voxel_surface_count);

View File

@ -93,7 +93,7 @@ public:
//Liquid Surfaces
Ref<VoxelSurface> get_liquid_voxel_surface(const int index) const;
void set_liquid_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_liquid_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void add_liquid_surface(const Ref<VoxelSurface> voxel_surface);
void remove_liquid_voxel_surface(const int index);
int get_liquid_voxel_surface_count() const;

View File

@ -31,37 +31,61 @@ bool WorldGeneratorPropData::can_spawn(int seed) {
}
#ifdef VOXELMAN_PRESENT
Ref<PropData> WorldGeneratorPropData::get_prop(int seed) {
if (has_method("_get_prop")) {
return call("_get_prop", seed);
Ref<PropData> WorldGeneratorPropData::get_prop() {
return _prop;
}
void WorldGeneratorPropData::set_prop(Ref<PropData> value) {
_prop = value;
}
Ref<PropData> WorldGeneratorPropData::get_prop_seeded(int seed) {
if (has_method("_get_prop_seeded")) {
return call("_get_prop_seeded", seed);
}
return Ref<PropData>(NULL);
return Ref<PropData>();
}
#else
Ref<Resource> WorldGeneratorPropData::get_prop(int seed) {
if (has_method("_get_prop")) {
return call("_get_prop", seed);
Ref<Resource> WorldGeneratorPropData::get_prop() {
return _prop;
}
void WorldGeneratorPropData::set_prop(Ref<Resource> value) {
_prop = value;
}
Ref<Resource> WorldGeneratorPropData::get_prop_seeded(int seed) {
if (has_method("_get_prop_seeded")) {
return call("_get_prop_seeded", seed);
}
return Ref<Resource>(NULL);
return Ref<Resource>();
}
#endif
WorldGeneratorPropData::WorldGeneratorPropData() {
}
WorldGeneratorPropData::~WorldGeneratorPropData() {
_prop.unref();
}
void WorldGeneratorPropData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "can"), "_can_spawn", PropertyInfo(Variant::INT, "seed")));
#ifdef VOXELMAN_PRESENT
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "_get_prop", PropertyInfo(Variant::INT, "seed")));
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "_get_prop_seeded", PropertyInfo(Variant::INT, "seed")));
#else
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), "_get_prop", PropertyInfo(Variant::INT, "seed")));
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), "_get_prop_seeded", PropertyInfo(Variant::INT, "seed")));
#endif
ClassDB::bind_method(D_METHOD("get_prop"), &WorldGeneratorPropData::get_prop);
ClassDB::bind_method(D_METHOD("set_prop"), &WorldGeneratorPropData::set_prop);
#ifdef VOXELMAN_PRESENT
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop", "get_prop");
#else
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop"), "set_prop", "get_prop");
#endif
ClassDB::bind_method(D_METHOD("can_spawn", "seed"), &WorldGeneratorPropData::can_spawn);
ClassDB::bind_method(D_METHOD("get_prop", "seed"), &WorldGeneratorPropData::get_prop);
ClassDB::bind_method(D_METHOD("get_prop_seeded", "seed"), &WorldGeneratorPropData::get_prop_seeded);
}

View File

@ -36,9 +36,15 @@ public:
bool can_spawn(int seed);
#ifdef VOXELMAN_PRESENT
Ref<PropData> get_prop(int seed);
Ref<PropData> get_prop();
void set_prop(Ref<PropData> value);
Ref<PropData> get_prop_seeded(int seed);
#else
Ref<Resource> get_prop(int seed);
Ref<Resource> get_prop();
void set_prop(Ref<Resource> value);
Ref<Resource> get_prop_seeded(int seed);
#endif
WorldGeneratorPropData();
@ -46,6 +52,12 @@ public:
protected:
static void _bind_methods();
#ifdef VOXELMAN_PRESENT
Ref<PropData> _prop;
#else
Ref<Resource> _prop;
#endif
};
#endif

View File

@ -179,7 +179,18 @@ void Biome::_setup_library(Ref<VoxelmanLibrary> library) {
Ref<VoxelSurface> s = _data->get_liquid_voxel_surface(i);
if (s.is_valid()) {
library->add_liquid_voxel_surface(s);
library->add_liquid_surface(s);
}
}
for (int i = 0; i < _data->get_prop_data_count(); ++i) {
Ref<WorldGeneratorPropData> s = _data->get_prop_data(i);
if (s.is_valid()) {
Ref<PropData> pd = s->get_prop();
if (pd.is_valid())
library->add_prop(s->get_prop());
}
}
}

View File

@ -257,7 +257,7 @@ void Dungeon::_setup_library(Ref<VoxelmanLibrary> library) {
Ref<VoxelSurface> s = _data->get_liquid_voxel_surface(i);
if (s.is_valid()) {
library->add_liquid_voxel_surface(s);
library->add_liquid_surface(s);
}
}
}

View File

@ -187,7 +187,18 @@ void DungeonRoom::_setup_library(Ref<VoxelmanLibrary> library) {
Ref<VoxelSurface> s = _data->get_liquid_voxel_surface(i);
if (s.is_valid()) {
library->add_liquid_voxel_surface(s);
library->add_liquid_surface(s);
}
}
for (int i = 0; i < _data->get_prop_data_count(); ++i) {
Ref<WorldGeneratorPropData> s = _data->get_prop_data(i);
if (s.is_valid()) {
Ref<PropData> pd = s->get_prop();
if (pd.is_valid())
library->add_prop(pd);
}
}
}

View File

@ -132,7 +132,7 @@ void Planet::_setup_library(Ref<VoxelmanLibrary> library) {
Ref<VoxelSurface> s = _data->get_liquid_voxel_surface(i);
if (s.is_valid()) {
library->add_liquid_voxel_surface(s);
library->add_liquid_surface(s);
}
}
}