Work on the bindings.

This commit is contained in:
Relintai 2019-10-18 09:00:01 +02:00
parent e199300fff
commit a0fc4dfef2
4 changed files with 278 additions and 2 deletions

View File

@ -1,5 +1,55 @@
#include "dungeon.h"
int Dungeon::get_seed() {
return _seed;
}
void Dungeon::set_seed(int value) {
_seed = value;
}
int Dungeon::get_posx() {
return _posx;
}
void Dungeon::set_posx(int value) {
_posx = value;
}
int Dungeon::get_posy() {
return _posy;
}
void Dungeon::set_posy(int value) {
_posy = value;
}
int Dungeon::get_posz() {
return _posz;
}
void Dungeon::set_posz(int value) {
_posz = value;
}
int Dungeon::get_sizex() {
return _sizex;
}
void Dungeon::set_sizex(int value) {
_sizex = value;
}
int Dungeon::get_sizey() {
return _sizey;
}
void Dungeon::set_sizey(int value) {
_sizey = value;
}
int Dungeon::get_sizez() {
return _sizez;
}
void Dungeon::set_sizez(int value) {
_sizez = value;
}
Ref<EnvironmentData> Dungeon::get_environment() {
return _environment;
}
@ -7,6 +57,7 @@ void Dungeon::set_environment(Ref<EnvironmentData> value) {
_environment = value;
}
//Rooms
Ref<DungeonRoom> Dungeon::get_dungeon_room(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_rooms.size(), Ref<DungeonRoom>());
@ -30,6 +81,84 @@ int Dungeon::get_dungeon_room_count() const {
return _dungeon_rooms.size();
}
//Start Rooms
Ref<DungeonRoom> Dungeon::get_dungeon_start_room(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_start_rooms.size(), Ref<DungeonRoom>());
return _dungeon_start_rooms.get(index);
}
void Dungeon::set_dungeon_start_room(const int index, const Ref<DungeonRoom> dungeon_start_room) {
ERR_FAIL_INDEX(index, _dungeon_start_rooms.size());
_dungeon_start_rooms.set(index, dungeon_start_room);
}
void Dungeon::add_dungeon_start_room(const Ref<DungeonRoom> dungeon_start_room) {
_dungeon_start_rooms.push_back(dungeon_start_room);
}
void Dungeon::remove_dungeon_start_room(const int index) {
ERR_FAIL_INDEX(index, _dungeon_start_rooms.size());
_dungeon_start_rooms.remove(index);
}
int Dungeon::get_dungeon_start_room_count() const {
return _dungeon_start_rooms.size();
}
//End Rooms
Ref<DungeonRoom> Dungeon::get_dungeon_end_room(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_end_rooms.size(), Ref<DungeonRoom>());
return _dungeon_end_rooms.get(index);
}
void Dungeon::set_dungeon_end_room(const int index, const Ref<DungeonRoom> dungeon_end_room) {
ERR_FAIL_INDEX(index, _dungeon_end_rooms.size());
_dungeon_end_rooms.set(index, dungeon_end_room);
}
void Dungeon::add_dungeon_end_room(const Ref<DungeonRoom> dungeon_end_room) {
_dungeon_end_rooms.push_back(dungeon_end_room);
}
void Dungeon::remove_dungeon_end_room(const int index) {
ERR_FAIL_INDEX(index, _dungeon_end_rooms.size());
_dungeon_end_rooms.remove(index);
}
int Dungeon::get_dungeon_end_room_count() const {
return _dungeon_end_rooms.size();
}
//Corridors
Ref<DungeonRoom> Dungeon::get_dungeon_corridor(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_corridors.size(), Ref<DungeonRoom>());
return _dungeon_corridors.get(index);
}
void Dungeon::set_dungeon_corridor(const int index, const Ref<DungeonRoom> dungeon_corridor) {
ERR_FAIL_INDEX(index, _dungeon_corridors.size());
_dungeon_corridors.set(index, dungeon_corridor);
}
void Dungeon::add_dungeon_corridor(const Ref<DungeonRoom> dungeon_corridor) {
_dungeon_corridors.push_back(dungeon_corridor);
}
void Dungeon::remove_dungeon_corridor(const int index) {
ERR_FAIL_INDEX(index, _dungeon_corridors.size());
_dungeon_corridors.remove(index);
}
int Dungeon::get_dungeon_corridor_count() const {
return _dungeon_corridors.size();
}
void Dungeon::setup() {
if (has_method("_setup")) {
call("_setup");
}
}
void Dungeon::generate_chunk(Ref<VoxelChunk> chunk) {
if (has_method("_generate_chunk")) {
call("_generate_chunk", chunk);
@ -49,24 +178,63 @@ Ref<Image> Dungeon::generate_map() {
}
Dungeon::Dungeon() {
_seed = 0;
}
Dungeon::~Dungeon() {
_environment.unref();
_dungeon_rooms.clear();
_dungeon_start_rooms.clear();
_dungeon_end_rooms.clear();
_dungeon_corridors.clear();
}
void Dungeon::_bind_methods() {
BIND_VMETHOD(MethodInfo("_setup"));
BIND_VMETHOD(MethodInfo("_generate_structure", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure")));
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
ClassDB::bind_method(D_METHOD("setup"), &Dungeon::setup);
ClassDB::bind_method(D_METHOD("generate_chunk", "chunk"), &Dungeon::generate_chunk);
ClassDB::bind_method(D_METHOD("generate_structure", "structure"), &Dungeon::generate_structure);
ClassDB::bind_method(D_METHOD("get_seed"), &Dungeon::get_seed);
ClassDB::bind_method(D_METHOD("set_seed", "value"), &Dungeon::set_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
//Position
ClassDB::bind_method(D_METHOD("get_posx"), &Dungeon::get_posx);
ClassDB::bind_method(D_METHOD("set_posx", "value"), &Dungeon::set_posx);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posx"), "set_posx", "get_posx");
ClassDB::bind_method(D_METHOD("get_posy"), &Dungeon::get_posy);
ClassDB::bind_method(D_METHOD("set_posy", "value"), &Dungeon::set_posy);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posy"), "set_posy", "get_posy");
ClassDB::bind_method(D_METHOD("get_posz"), &Dungeon::get_posz);
ClassDB::bind_method(D_METHOD("set_posz", "value"), &Dungeon::set_posz);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posz"), "set_posz", "get_posz");
//Size
ClassDB::bind_method(D_METHOD("get_sizex"), &Dungeon::get_sizex);
ClassDB::bind_method(D_METHOD("set_sizex", "value"), &Dungeon::set_sizex);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizex"), "set_sizex", "get_sizex");
ClassDB::bind_method(D_METHOD("get_sizey"), &Dungeon::get_sizey);
ClassDB::bind_method(D_METHOD("set_sizey", "value"), &Dungeon::set_sizey);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizey"), "set_sizey", "get_sizey");
ClassDB::bind_method(D_METHOD("get_sizez"), &Dungeon::get_sizez);
ClassDB::bind_method(D_METHOD("set_sizez", "value"), &Dungeon::set_sizez);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizez"), "set_sizez", "get_sizez");
//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");
//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);
ClassDB::bind_method(D_METHOD("add_dungeon_room", "dungeon_room"), &Dungeon::add_dungeon_room);
@ -74,6 +242,30 @@ void Dungeon::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_dungeon_room_count"), &Dungeon::get_dungeon_room_count);
//Start Rooms
ClassDB::bind_method(D_METHOD("get_dungeon_start_room", "index"), &Dungeon::get_dungeon_start_room);
ClassDB::bind_method(D_METHOD("set_dungeon_start_room", "index", "data"), &Dungeon::set_dungeon_start_room);
ClassDB::bind_method(D_METHOD("add_dungeon_start_room", "dungeon_start_room"), &Dungeon::add_dungeon_start_room);
ClassDB::bind_method(D_METHOD("remove_dungeon_start_room", "index"), &Dungeon::remove_dungeon_start_room);
ClassDB::bind_method(D_METHOD("get_dungeon_start_room_count"), &Dungeon::get_dungeon_start_room_count);
//End Rooms
ClassDB::bind_method(D_METHOD("get_dungeon_end_room", "index"), &Dungeon::get_dungeon_end_room);
ClassDB::bind_method(D_METHOD("set_dungeon_end_room", "index", "data"), &Dungeon::set_dungeon_end_room);
ClassDB::bind_method(D_METHOD("add_dungeon_end_room", "dungeon_end_room"), &Dungeon::add_dungeon_end_room);
ClassDB::bind_method(D_METHOD("remove_dungeon_end_room", "index"), &Dungeon::remove_dungeon_end_room);
ClassDB::bind_method(D_METHOD("get_dungeon_end_room_count"), &Dungeon::get_dungeon_end_room_count);
//Corridors
ClassDB::bind_method(D_METHOD("get_dungeon_corridor", "index"), &Dungeon::get_dungeon_corridor);
ClassDB::bind_method(D_METHOD("set_dungeon_corridor", "index", "data"), &Dungeon::set_dungeon_corridor);
ClassDB::bind_method(D_METHOD("add_dungeon_corridor", "dungeon_corridor"), &Dungeon::add_dungeon_corridor);
ClassDB::bind_method(D_METHOD("remove_dungeon_corridor", "index"), &Dungeon::remove_dungeon_corridor);
ClassDB::bind_method(D_METHOD("get_dungeon_corridor_count"), &Dungeon::get_dungeon_corridor_count);
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "_generate_map"));
ClassDB::bind_method(D_METHOD("generate_map"), &Dungeon::generate_map);

View File

@ -13,10 +13,32 @@ class Dungeon : public Reference {
GDCLASS(Dungeon, Reference);
public:
int get_seed();
void set_seed(int value);
int get_posx();
void set_posx(int value);
int get_posy();
void set_posy(int value);
int get_posz();
void set_posz(int value);
int get_sizex();
void set_sizex(int value);
int get_sizey();
void set_sizey(int value);
int get_sizez();
void set_sizez(int value);
//Environment
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
//Rooms
Ref<DungeonRoom> get_dungeon_room(const int index) const;
void set_dungeon_room(const int index, const Ref<DungeonRoom> dungeon_room);
void add_dungeon_room(const Ref<DungeonRoom> dungeon_room);
@ -24,6 +46,31 @@ public:
int get_dungeon_room_count() const;
//Start Rooms
Ref<DungeonRoom> get_dungeon_start_room(const int index) const;
void set_dungeon_start_room(const int index, const Ref<DungeonRoom> dungeon_start_room);
void add_dungeon_start_room(const Ref<DungeonRoom> dungeon_start_room);
void remove_dungeon_start_room(const int index);
int get_dungeon_start_room_count() const;
//End Rooms
Ref<DungeonRoom> get_dungeon_end_room(const int index) const;
void set_dungeon_end_room(const int index, const Ref<DungeonRoom> dungeon_end_room);
void add_dungeon_end_room(const Ref<DungeonRoom> dungeon_end_room);
void remove_dungeon_end_room(const int index);
int get_dungeon_end_room_count() const;
//Corridors
Ref<DungeonRoom> get_dungeon_corridor(const int index) const;
void set_dungeon_corridor(const int index, const Ref<DungeonRoom> dungeon_corridors);
void add_dungeon_corridor(const Ref<DungeonRoom> dungeon_corridors);
void remove_dungeon_corridor(const int index);
int get_dungeon_corridor_count() const;
void setup();
void generate_chunk(Ref<VoxelChunk> chunk);
void generate_structure(Ref<VoxelStructure> structure);
@ -36,8 +83,21 @@ protected:
static void _bind_methods();
private:
int _seed;
int _posx;
int _posy;
int _posz;
int _sizex;
int _sizey;
int _sizez;
Ref<EnvironmentData> _environment;
Vector<Ref<DungeonRoom> > _dungeon_rooms;
Vector<Ref<DungeonRoom> > _dungeon_start_rooms;
Vector<Ref<DungeonRoom> > _dungeon_end_rooms;
Vector<Ref<DungeonRoom> > _dungeon_corridors;
};
#endif

View File

@ -1,5 +1,12 @@
#include "planet.h"
int Planet::get_seed() {
return _seed;
}
void Planet::set_seed(int value) {
_seed = value;
}
Ref<EnvironmentData> Planet::get_environment() {
return _environment;
}
@ -30,6 +37,12 @@ int Planet::get_biome_count() const {
return _biomes.size();
}
void Planet::setup() {
if (has_method("_setup")) {
call("_setup");
}
}
void Planet::generate_chunk(Ref<VoxelChunk> chunk) {
if (has_method("_generate_chunk")) {
call("_generate_chunk", chunk);
@ -43,7 +56,7 @@ Ref<Image> Planet::generate_map() {
}
Planet::Planet() {
_seed = 0;
}
Planet::~Planet() {
_environment.unref();
@ -51,9 +64,15 @@ Planet::~Planet() {
}
void Planet::_bind_methods() {
BIND_VMETHOD(MethodInfo("_setup"));
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
ClassDB::bind_method(D_METHOD("generate_chunk", "chunk"), &Planet::generate_chunk);
ClassDB::bind_method(D_METHOD("setup"), &Planet::setup);
ClassDB::bind_method(D_METHOD("get_seed"), &Planet::get_seed);
ClassDB::bind_method(D_METHOD("set_seed", "value"), &Planet::set_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
ClassDB::bind_method(D_METHOD("get_environment"), &Planet::get_environment);
ClassDB::bind_method(D_METHOD("set_environment", "value"), &Planet::set_environment);

View File

@ -12,6 +12,9 @@ class Planet : public Reference {
GDCLASS(Planet, Reference);
public:
int get_seed();
void set_seed(int value);
//Environment
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
@ -23,6 +26,7 @@ public:
int get_biome_count() const;
void setup();
void generate_chunk(Ref<VoxelChunk> chunk);
Ref<Image> generate_map();
@ -33,6 +37,7 @@ protected:
static void _bind_methods();
private:
int _seed;
Ref<EnvironmentData> _environment;
Vector<Ref<Biome> > _biomes;
};