world_generator/data/world_generator.cpp
2019-09-22 22:12:20 +02:00

71 lines
2.4 KiB
C++

#include "world_generator.h"
Ref<PlanetData> WorldGenerator::get_planet_data(const int index) const {
ERR_FAIL_INDEX_V(index, _planet_datas.size(), Ref<PlanetData>());
return _planet_datas.get(index);
}
void WorldGenerator::set_planet_data(const int index, const Ref<PlanetData> planet_data) {
ERR_FAIL_INDEX(index, _planet_datas.size());
_planet_datas.set(index, planet_data);
}
void WorldGenerator::add_planet_data(const Ref<PlanetData> planet_data) {
_planet_datas.push_back(planet_data);
}
void WorldGenerator::remove_planet_data(const int index) {
ERR_FAIL_INDEX(index, _planet_datas.size());
_planet_datas.remove(index);
}
int WorldGenerator::get_planet_data_count() const {
return _planet_datas.size();
}
Vector<Variant> WorldGenerator::get_planet_datas() {
Vector<Variant> r;
for (int i = 0; i < _planet_datas.size(); i++) {
r.push_back(_planet_datas[i].get_ref_ptr());
}
return r;
}
void WorldGenerator::set_planet_datas(const Vector<Variant> &planet_datas) {
_planet_datas.clear();
for (int i = 0; i < planet_datas.size(); i++) {
Ref<PlanetData> planet_data = Ref<PlanetData>(planet_datas[i]);
_planet_datas.push_back(planet_data);
}
}
Ref<Planet> WorldGenerator::setup_planet() {
if (has_method("_setup_planet")) {
return call("_setup_planet");
}
return Ref<Planet>(NULL);
}
WorldGenerator::WorldGenerator() {
}
WorldGenerator::~WorldGenerator() {
_planet_datas.clear();
}
void WorldGenerator::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "planet", PROPERTY_HINT_RESOURCE_TYPE, "Planet") , "_setup_planet"));
ClassDB::bind_method(D_METHOD("get_planet_data", "index"), &VoxelmanProp::get_planet_data);
ClassDB::bind_method(D_METHOD("set_planet_data", "index", "data"), &VoxelmanProp::set_planet_data);
ClassDB::bind_method(D_METHOD("add_planet_data", "planet_data"), &VoxelmanProp::add_planet_data);
ClassDB::bind_method(D_METHOD("remove_planet_data", "index"), &VoxelmanProp::remove_planet_data);
ClassDB::bind_method(D_METHOD("get_planet_data_count"), &VoxelmanProp::get_planet_data_count);
ClassDB::bind_method(D_METHOD("get_planet_datas"), &VoxelmanProp::get_planet_datas);
ClassDB::bind_method(D_METHOD("set_planet_datas", "planet_datas"), &VoxelmanProp::set_planet_datas);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "planet_datas", PROPERTY_HINT_NONE, "17/17:PlanetData", PROPERTY_USAGE_DEFAULT, "PlanetData"), "set_planet_datas", "get_planet_datas");
}