Renamed VoxelPropData, and cleaned up VoxelProp bit.

This commit is contained in:
Relintai 2019-09-21 00:02:10 +02:00
parent c1b0be11bd
commit 916676cfab
8 changed files with 90 additions and 88 deletions

2
SCsub
View File

@ -23,7 +23,7 @@ env.add_source_files(env.modules_sources,"world/voxel_chunk.cpp")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_mesher_cubic.cpp")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_cube_points.cpp")
env.add_source_files(env.modules_sources,"props/voxelman_prop_data.cpp")
env.add_source_files(env.modules_sources,"props/voxelman_prop_entry.cpp")
env.add_source_files(env.modules_sources,"props/voxelman_prop.cpp")
env.add_source_files(env.modules_sources,"level_generator/voxelman_level_generator.cpp")

View File

@ -1,26 +1,42 @@
#include "voxelman_prop.h"
Ref<VoxelmanPropData> VoxelmanProp::get_prop(const int index) const {
ERR_FAIL_INDEX_V(index, _props.size(), Ref<VoxelmanPropData>());
Ref<VoxelmanPropEntry> VoxelmanProp::get_prop(const int index) const {
ERR_FAIL_INDEX_V(index, _props.size(), Ref<VoxelmanPropEntry>());
return _props.get(index);
}
void VoxelmanProp::set_prop(const int index, const Ref<VoxelmanPropData> prop) {
void VoxelmanProp::set_prop(const int index, const Ref<VoxelmanPropEntry> prop) {
ERR_FAIL_INDEX(index, _props.size());
_props.set(index, prop);
}
void VoxelmanProp::add_prop(const Ref<VoxelmanPropEntry> prop) {
_props.push_back(prop);
}
void VoxelmanProp::remove_prop(const int index) {
ERR_FAIL_INDEX(index, _props.size());
_props.remove(index);
}
int VoxelmanProp::get_prop_count() const {
return _props.size();
}
void VoxelmanProp::set_prop_count(const int size) {
if (size > MAX_PROPS) {
_props.resize(MAX_PROPS);
return;
}
_props.resize(size);
Vector<Variant> VoxelmanProp::get_props() {
Vector<Variant> r;
for (int i = 0; i < _props.size(); i++) {
r.push_back(_props[i].get_ref_ptr());
}
return r;
}
void VoxelmanProp::set_props(const Vector<Variant> &props) {
_props.clear();
for (int i = 0; i < props.size(); i++) {
Ref<VoxelmanPropEntry> prop = Ref<VoxelmanPropEntry>(props[i]);
_props.push_back(prop);
}
}
VoxelmanProp::VoxelmanProp() {
@ -29,28 +45,15 @@ VoxelmanProp::~VoxelmanProp() {
_props.clear();
}
void VoxelmanProp::_validate_property(PropertyInfo &property) const {
String prop = property.name;
if (prop.begins_with("Prop_")) {
int num = prop.get_slicec('/', 0).get_slicec('_', 1).to_int();
if (num >= _props.size()) {
property.usage = 0;
}
}
}
void VoxelmanProp::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_prop_count"), &VoxelmanProp::get_prop_count);
ClassDB::bind_method(D_METHOD("set_prop_count", "value"), &VoxelmanProp::set_prop_count);
ADD_PROPERTY(PropertyInfo(Variant::INT, "prop_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_PROPS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_prop_count", "get_prop_count");
ClassDB::bind_method(D_METHOD("get_prop", "index"), &VoxelmanProp::get_prop);
ClassDB::bind_method(D_METHOD("set_prop", "index", "spell"), &VoxelmanProp::set_prop);
ClassDB::bind_method(D_METHOD("add_prop", "prop"), &VoxelmanProp::add_prop);
ClassDB::bind_method(D_METHOD("remove_prop", "index"), &VoxelmanProp::remove_prop);
for (int i = 0; i < MAX_PROPS; ++i) {
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "Prop_" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanPropData", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_prop", "get_prop", i);
}
ClassDB::bind_method(D_METHOD("get_prop_count"), &VoxelmanProp::get_prop_count);
BIND_CONSTANT(MAX_PROPS);
ClassDB::bind_method(D_METHOD("get_props"), &VoxelmanProp::get_props);
ClassDB::bind_method(D_METHOD("set_props", "props"), &VoxelmanProp::set_props);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:VoxelmanPropEntry", PROPERTY_USAGE_DEFAULT, "VoxelmanPropEntry"), "set_props", "get_props");
}

View File

@ -4,31 +4,30 @@
#include "core/reference.h"
#include "core/vector.h"
#include "voxelman_prop_data.h"
#include "voxelman_prop_entry.h"
class VoxelmanProp : public Resource {
GDCLASS(VoxelmanProp, Resource);
public:
Ref<VoxelmanPropData> get_prop(const int index) const;
void set_prop(const int index, const Ref<VoxelmanPropData> prop);
Ref<VoxelmanPropEntry> get_prop(const int index) const;
void set_prop(const int index, const Ref<VoxelmanPropEntry> prop);
void add_prop(const Ref<VoxelmanPropEntry> prop);
void remove_prop(const int index);
int get_prop_count() const;
void set_prop_count(const int size);
Vector<Variant> get_props();
void set_props(const Vector<Variant> &props);
VoxelmanProp();
~VoxelmanProp();
enum {
MAX_PROPS = 36
};
protected:
static void _bind_methods();
void _validate_property(PropertyInfo &property) const;
private:
Vector<Ref<VoxelmanPropData> > _props;
Vector<Ref<VoxelmanPropEntry> > _props;
};
#endif

View File

@ -1,77 +1,77 @@
#include "voxelman_prop_data.h"
#include "voxelman_prop_entry.h"
#include "voxelman_prop.h"
Ref<MeshDataResource> VoxelmanPropData::get_mesh() const {
Ref<MeshDataResource> VoxelmanPropEntry::get_mesh() const {
return _mesh;
}
void VoxelmanPropData::set_mesh(const Ref<MeshDataResource> mesh) {
void VoxelmanPropEntry::set_mesh(const Ref<MeshDataResource> mesh) {
_mesh = mesh;
}
int VoxelmanPropData::get_has_light() const {
int VoxelmanPropEntry::get_has_light() const {
return _has_light;
}
void VoxelmanPropData::set_has_light(const int value){
void VoxelmanPropEntry::set_has_light(const int value){
_has_light = value;
}
Color VoxelmanPropData::get_light_color() const {
Color VoxelmanPropEntry::get_light_color() const {
return _light_color;
}
void VoxelmanPropData::set_light_color(const Color value) {
void VoxelmanPropEntry::set_light_color(const Color value) {
_light_color = value;
}
int VoxelmanPropData::get_light_size() const {
int VoxelmanPropEntry::get_light_size() const {
return _light_size;
}
void VoxelmanPropData::set_light_size(const int value) {
void VoxelmanPropEntry::set_light_size(const int value) {
_has_light = value;
}
Ref<PackedScene> VoxelmanPropData::get_scene() const {
Ref<PackedScene> VoxelmanPropEntry::get_scene() const {
return _scene;
}
void VoxelmanPropData::set_scene(const Ref<PackedScene> value) {
void VoxelmanPropEntry::set_scene(const Ref<PackedScene> value) {
_scene = value;
}
Vector3 VoxelmanPropData::get_position() const {
Vector3 VoxelmanPropEntry::get_position() const {
return _position;
}
void VoxelmanPropData::set_position(const Vector3 value) {
void VoxelmanPropEntry::set_position(const Vector3 value) {
_position = value;
}
Vector3 VoxelmanPropData::get_rotation() const {
Vector3 VoxelmanPropEntry::get_rotation() const {
return _rotation;
}
void VoxelmanPropData::set_rotation(const Vector3 value) {
void VoxelmanPropEntry::set_rotation(const Vector3 value) {
_rotation = value;
}
Vector3 VoxelmanPropData::get_scale() const {
Vector3 VoxelmanPropEntry::get_scale() const {
return _scale;
}
void VoxelmanPropData::set_scale(const Vector3 value) {
void VoxelmanPropEntry::set_scale(const Vector3 value) {
_scale = value;
}
Ref<VoxelmanProp> VoxelmanPropData::get_prop() const {
Ref<VoxelmanProp> VoxelmanPropEntry::get_prop() const {
return _prop;
}
void VoxelmanPropData::set_prop(const Ref<VoxelmanProp> prop) {
void VoxelmanPropEntry::set_prop(const Ref<VoxelmanProp> prop) {
_prop = prop;
}
VoxelmanPropData::VoxelmanPropData() {
VoxelmanPropEntry::VoxelmanPropEntry() {
_has_light = false;
_light_size = 5;
_scale = Vector3(1.0, 1.0, 1.0);
}
VoxelmanPropData::~VoxelmanPropData() {
VoxelmanPropEntry::~VoxelmanPropEntry() {
if (_mesh.is_valid())
_mesh.unref();
@ -79,40 +79,40 @@ VoxelmanPropData::~VoxelmanPropData() {
_scene.unref();
}
void VoxelmanPropData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mesh"), &VoxelmanPropData::get_mesh);
ClassDB::bind_method(D_METHOD("set_mesh", "value"), &VoxelmanPropData::set_mesh);
void VoxelmanPropEntry::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mesh"), &VoxelmanPropEntry::get_mesh);
ClassDB::bind_method(D_METHOD("set_mesh", "value"), &VoxelmanPropEntry::set_mesh);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh");
ClassDB::bind_method(D_METHOD("get_has_light"), &VoxelmanPropData::get_has_light);
ClassDB::bind_method(D_METHOD("set_has_light", "value"), &VoxelmanPropData::set_has_light);
ClassDB::bind_method(D_METHOD("get_has_light"), &VoxelmanPropEntry::get_has_light);
ClassDB::bind_method(D_METHOD("set_has_light", "value"), &VoxelmanPropEntry::set_has_light);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_light"), "set_has_light", "get_has_light");
ClassDB::bind_method(D_METHOD("get_light_color"), &VoxelmanPropData::get_light_color);
ClassDB::bind_method(D_METHOD("set_light_color", "value"), &VoxelmanPropData::set_light_color);
ClassDB::bind_method(D_METHOD("get_light_color"), &VoxelmanPropEntry::get_light_color);
ClassDB::bind_method(D_METHOD("set_light_color", "value"), &VoxelmanPropEntry::set_light_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_light_color", "get_light_color");
ClassDB::bind_method(D_METHOD("get_light_size"), &VoxelmanPropData::get_light_size);
ClassDB::bind_method(D_METHOD("set_light_size", "value"), &VoxelmanPropData::set_light_size);
ClassDB::bind_method(D_METHOD("get_light_size"), &VoxelmanPropEntry::get_light_size);
ClassDB::bind_method(D_METHOD("set_light_size", "value"), &VoxelmanPropEntry::set_light_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size"), "set_light_size", "get_light_size");
ClassDB::bind_method(D_METHOD("get_scene"), &VoxelmanPropData::get_scene);
ClassDB::bind_method(D_METHOD("set_scene", "value"), &VoxelmanPropData::set_scene);
ClassDB::bind_method(D_METHOD("get_scene"), &VoxelmanPropEntry::get_scene);
ClassDB::bind_method(D_METHOD("set_scene", "value"), &VoxelmanPropEntry::set_scene);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", "get_scene");
ClassDB::bind_method(D_METHOD("get_prop"), &VoxelmanPropData::get_prop);
ClassDB::bind_method(D_METHOD("set_prop", "value"), &VoxelmanPropData::set_prop);
ClassDB::bind_method(D_METHOD("get_prop"), &VoxelmanPropEntry::get_prop);
ClassDB::bind_method(D_METHOD("set_prop", "value"), &VoxelmanPropEntry::set_prop);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanProp"), "set_prop", "get_prop");
ClassDB::bind_method(D_METHOD("get_position"), &VoxelmanPropData::get_position);
ClassDB::bind_method(D_METHOD("set_position", "value"), &VoxelmanPropData::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &VoxelmanPropEntry::get_position);
ClassDB::bind_method(D_METHOD("set_position", "value"), &VoxelmanPropEntry::set_position);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position");
ClassDB::bind_method(D_METHOD("get_rotation"), &VoxelmanPropData::get_rotation);
ClassDB::bind_method(D_METHOD("set_rotation", "value"), &VoxelmanPropData::set_rotation);
ClassDB::bind_method(D_METHOD("get_rotation"), &VoxelmanPropEntry::get_rotation);
ClassDB::bind_method(D_METHOD("set_rotation", "value"), &VoxelmanPropEntry::set_rotation);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation"), "set_rotation", "get_rotation");
ClassDB::bind_method(D_METHOD("get_scale"), &VoxelmanPropData::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "value"), &VoxelmanPropData::set_scale);
ClassDB::bind_method(D_METHOD("get_scale"), &VoxelmanPropEntry::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "value"), &VoxelmanPropEntry::set_scale);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale"), "set_scale", "get_scale");
}

View File

@ -10,8 +10,8 @@
class VoxelmanProp;
class VoxelmanPropData : public Resource {
GDCLASS(VoxelmanPropData, Resource);
class VoxelmanPropEntry : public Resource {
GDCLASS(VoxelmanPropEntry, Resource);
public:
Ref<MeshDataResource> get_mesh() const;
@ -41,8 +41,8 @@ public:
Ref<VoxelmanProp> get_prop() const;
void set_prop(const Ref<VoxelmanProp> prop);
VoxelmanPropData();
~VoxelmanPropData();
VoxelmanPropEntry();
~VoxelmanPropEntry();
protected:
static void _bind_methods();

View File

@ -16,7 +16,7 @@
#include "meshers/cubic_mesher/voxel_mesher_cubic.h"
#include "meshers/cubic_mesher/voxel_cube_points.h"
#include "props/voxelman_prop_data.h"
#include "props/voxelman_prop_entry.h"
#include "props/voxelman_prop.h"
#include "level_generator/voxelman_level_generator.h"
@ -39,7 +39,7 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelMesherCubic>();
ClassDB::register_class<VoxelCubePoints>();
ClassDB::register_class<VoxelmanPropData>();
ClassDB::register_class<VoxelmanPropEntry>();
ClassDB::register_class<VoxelmanProp>();
ClassDB::register_class<VoxelmanLevelGenerator>();

View File

@ -437,7 +437,7 @@ void VoxelChunk::process_prop_light(Ref<VoxelmanProp> prop, const Transform tran
ERR_FAIL_COND(!prop.is_valid());
for (int i = 0; i < prop->get_prop_count(); ++i) {
Ref<VoxelmanPropData> data = prop->get_prop(i);
Ref<VoxelmanPropEntry> data = prop->get_prop(i);
if (!data.is_valid())
continue;
@ -462,7 +462,7 @@ void VoxelChunk::process_prop(Ref<VoxelmanProp> prop, const Transform transform)
ERR_FAIL_COND(!prop.is_valid());
for (int i = 0; i < prop->get_prop_count(); ++i) {
Ref<VoxelmanPropData> data = prop->get_prop(i);
Ref<VoxelmanPropEntry> data = prop->get_prop(i);
if (!data.is_valid())
continue;

View File

@ -27,7 +27,7 @@
#include "../../entity_spell_system/meshes/mesh_data_resource.h"
#include "../props/voxelman_prop.h"
#include "../props/voxelman_prop_data.h"
#include "../props/voxelman_prop_entry.h"
class VoxelWorld;