Added in prop related data classes.

This commit is contained in:
Relintai 2019-07-19 18:39:46 +02:00
parent 029f241005
commit 6b4de4cf80
6 changed files with 286 additions and 0 deletions

3
SCsub
View File

@ -21,3 +21,6 @@ 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.cpp")

58
props/voxelman_prop.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "voxelman_prop.h"
Ref<VoxelmanPropData> VoxelmanProp::get_prop(const int index) const {
ERR_FAIL_INDEX_V(index, _props.size(), Ref<VoxelmanPropData>());
return _props.get(index);
}
void VoxelmanProp::set_prop(const int index, const Ref<VoxelmanPropData> prop) {
ERR_FAIL_INDEX(index, _props.size());
_props.set(index, prop);
}
int VoxelmanProp::get_num_props(const int index) const {
return _num_props;
}
void VoxelmanProp::set_num_props(const int size) {
_num_props = size;
if (_num_props > MAX_PROPS) {
_num_props = MAX_PROPS;
}
_props.resize(size);
}
VoxelmanProp::VoxelmanProp() {
_num_props = 0;
}
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 >= _num_props) {
property.usage = 0;
}
}
}
void VoxelmanProp::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_num_props"), &VoxelmanProp::get_num_props);
ClassDB::bind_method(D_METHOD("set_num_props", "value"), &VoxelmanProp::set_num_props);
ADD_PROPERTY(PropertyInfo(Variant::INT, "num_props", PROPERTY_HINT_RANGE, "0," + itos(MAX_PROPS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_num_props", "get_num_props");
ClassDB::bind_method(D_METHOD("get_prop", "index"), &VoxelmanProp::get_prop);
ClassDB::bind_method(D_METHOD("set_prop", "index", "spell"), &VoxelmanProp::set_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);
}
BIND_CONSTANT(MAX_PROPS);
}

35
props/voxelman_prop.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef VOXELMAN_PROP_H
#define VOXELMAN_PROP_H
#include "core/reference.h"
#include "core/vector.h"
#include "voxelman_prop_data.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);
int get_num_props(const int index) const;
void set_num_props(const int size);
VoxelmanProp();
~VoxelmanProp();
enum {
MAX_PROPS = 36
};
protected:
static void _bind_methods();
void _validate_property(PropertyInfo &property) const;
private:
Vector<Ref<VoxelmanPropData> > _props;
int _num_props;
};
#endif

View File

@ -0,0 +1,118 @@
#include "voxelman_prop_data.h"
#include "voxelman_prop.h"
Ref<MeshDataResource> VoxelmanPropData::get_mesh() const {
return _mesh;
}
void VoxelmanPropData::set_mesh(const Ref<MeshDataResource> mesh) {
_mesh = mesh;
}
int VoxelmanPropData::get_has_light() const {
return _has_light;
}
void VoxelmanPropData::set_has_light(const int value){
_has_light = value;
}
Color VoxelmanPropData::get_light_color() const {
return _light_color;
}
void VoxelmanPropData::set_light_color(const Color value) {
_light_color = value;
}
int VoxelmanPropData::get_light_size() const {
return _light_size;
}
void VoxelmanPropData::set_light_size(const int value) {
_has_light = value;
}
Ref<PackedScene> VoxelmanPropData::get_scene() const {
return _scene;
}
void VoxelmanPropData::set_scene(const Ref<PackedScene> value) {
_scene = value;
}
Vector3 VoxelmanPropData::get_position() const {
return _position;
}
void VoxelmanPropData::set_position(const Vector3 value) {
_position = value;
}
Vector3 VoxelmanPropData::get_rotation() const {
return _rotation;
}
void VoxelmanPropData::set_rotation(const Vector3 value) {
_rotation = value;
}
Vector3 VoxelmanPropData::get_scale() const {
return _scale;
}
void VoxelmanPropData::set_scale(const Vector3 value) {
_scale = value;
}
Ref<VoxelmanProp> VoxelmanPropData::get_prop() const {
return _prop;
}
void VoxelmanPropData::set_prop(const Ref<VoxelmanProp> prop) {
_prop = prop;
}
VoxelmanPropData::VoxelmanPropData() {
_has_light = false;
_light_size = 5;
_scale = Vector3(1.0, 1.0, 1.0);
}
VoxelmanPropData::~VoxelmanPropData() {
if (_mesh.is_valid())
_mesh.unref();
if (_scene.is_valid())
_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);
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);
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);
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);
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);
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);
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);
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);
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);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale"), "set_scale", "get_scale");
}

View File

@ -0,0 +1,66 @@
#ifndef VOXELMAN_PROP_DATA_H
#define VOXELMAN_PROP_DATA_H
#include "core/reference.h"
#include "core/math/vector3.h"
#include "core/color.h"
#include "scene/resources/packed_scene.h"
#include "../../entity_spell_system/meshes/mesh_data_resource.h"
class VoxelmanProp;
class VoxelmanPropData : public Resource {
GDCLASS(VoxelmanPropData, Resource);
public:
Ref<MeshDataResource> get_mesh() const;
void set_mesh(const Ref<MeshDataResource> mesh);
int get_has_light() const;
void set_has_light(const int value);
Color get_light_color() const;
void set_light_color(const Color value);
int get_light_size() const;
void set_light_size(const int value);
Ref<PackedScene> get_scene() const;
void set_scene(const Ref<PackedScene> value);
Vector3 get_position() const;
void set_position(const Vector3 value);
Vector3 get_rotation() const;
void set_rotation(const Vector3 value);
Vector3 get_scale() const;
void set_scale(const Vector3 value);
Ref<VoxelmanProp> get_prop() const;
void set_prop(const Ref<VoxelmanProp> prop);
VoxelmanPropData();
~VoxelmanPropData();
protected:
static void _bind_methods();
private:
Ref<MeshDataResource> _mesh;
bool _has_light;
Color _light_color;
int _light_size;
Ref<PackedScene> _scene;
Ref<VoxelmanProp> _prop;
Vector3 _position;
Vector3 _rotation;
Vector3 _scale;
};
#endif

View File

@ -15,6 +15,9 @@
#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.h"
void register_voxelman_types() {
ClassDB::register_class<VoxelMesher>();
ClassDB::register_class<VoxelMesherTransvoxel>();
@ -33,6 +36,9 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelMesherCubic>();
ClassDB::register_class<VoxelCubePoints>();
ClassDB::register_class<VoxelmanPropData>();
ClassDB::register_class<VoxelmanProp>();
}
void unregister_voxelman_types() {