diff --git a/SCsub b/SCsub index 816863f..b0e5534 100644 --- a/SCsub +++ b/SCsub @@ -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") diff --git a/props/voxelman_prop.cpp b/props/voxelman_prop.cpp new file mode 100644 index 0000000..14a7ed7 --- /dev/null +++ b/props/voxelman_prop.cpp @@ -0,0 +1,58 @@ +#include "voxelman_prop.h" + +Ref VoxelmanProp::get_prop(const int index) const { + ERR_FAIL_INDEX_V(index, _props.size(), Ref()); + + return _props.get(index); +} +void VoxelmanProp::set_prop(const int index, const Ref 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); +} diff --git a/props/voxelman_prop.h b/props/voxelman_prop.h new file mode 100644 index 0000000..15051e3 --- /dev/null +++ b/props/voxelman_prop.h @@ -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 get_prop(const int index) const; + void set_prop(const int index, const Ref 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 > _props; + int _num_props; +}; + +#endif diff --git a/props/voxelman_prop_data.cpp b/props/voxelman_prop_data.cpp new file mode 100644 index 0000000..f8fc9ea --- /dev/null +++ b/props/voxelman_prop_data.cpp @@ -0,0 +1,118 @@ +#include "voxelman_prop_data.h" + +#include "voxelman_prop.h" + +Ref VoxelmanPropData::get_mesh() const { + return _mesh; +} +void VoxelmanPropData::set_mesh(const Ref 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 VoxelmanPropData::get_scene() const { + return _scene; +} +void VoxelmanPropData::set_scene(const Ref 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 VoxelmanPropData::get_prop() const { + return _prop; +} +void VoxelmanPropData::set_prop(const Ref 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"); +} diff --git a/props/voxelman_prop_data.h b/props/voxelman_prop_data.h new file mode 100644 index 0000000..b464886 --- /dev/null +++ b/props/voxelman_prop_data.h @@ -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 get_mesh() const; + void set_mesh(const Ref 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 get_scene() const; + void set_scene(const Ref 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 get_prop() const; + void set_prop(const Ref prop); + + VoxelmanPropData(); + ~VoxelmanPropData(); + +protected: + static void _bind_methods(); + +private: + Ref _mesh; + + bool _has_light; + Color _light_color; + int _light_size; + + Ref _scene; + + Ref _prop; + + Vector3 _position; + Vector3 _rotation; + Vector3 _scale; +}; + +#endif diff --git a/register_types.cpp b/register_types.cpp index 5e402b7..14adc1e 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -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(); ClassDB::register_class(); @@ -33,6 +36,9 @@ void register_voxelman_types() { ClassDB::register_class(); ClassDB::register_class(); + + ClassDB::register_class(); + ClassDB::register_class(); } void unregister_voxelman_types() {