diff --git a/SCsub b/SCsub index 1bb99a6..6b56edc 100644 --- a/SCsub +++ b/SCsub @@ -38,6 +38,7 @@ sources = [ "props/prop_data_light.cpp", "props/prop_data_prop.cpp", "props/prop_data_portal.cpp", + "props/prop_data_tiled_wall.cpp", "clutter/ground_clutter.cpp", "clutter/ground_clutter_foliage.cpp", diff --git a/config.py b/config.py index 44d2e90..7c136b9 100644 --- a/config.py +++ b/config.py @@ -15,6 +15,7 @@ def get_doc_classes(): "PropDataProp", "PropDataScene", "PropDataPortal", + "PropDataTiledWall", "PropData", "TiledWall", diff --git a/props/prop_data_tiled_wall.cpp b/props/prop_data_tiled_wall.cpp new file mode 100644 index 0000000..3a1908e --- /dev/null +++ b/props/prop_data_tiled_wall.cpp @@ -0,0 +1,117 @@ +/* +Copyright (c) 2019-2021 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "prop_data_tiled_wall.h" + +#include "../tiled_wall/tiled_wall.h" +#include "../tiled_wall/tiled_wall_data.h" + +#include "prop_data.h" + +int PropDataTiledWall::get_width() const { + return _width; +} +void PropDataTiledWall::set_width(const int value) { + _width = value; +} + +int PropDataTiledWall::get_heigth() const { + return _height; +} +void PropDataTiledWall::set_heigth(const int value) { + _height = value; +} + +Ref PropDataTiledWall::get_data() { + return _data; +} +void PropDataTiledWall::set_data(const Ref &data) { + _data = data; +} + +bool PropDataTiledWall::get_collision() const { + return _collision; +} +void PropDataTiledWall::set_collision(const int value) { + _collision = value; +} + +bool PropDataTiledWall::_processor_handles(Node *node) { + TiledWall *t = Object::cast_to(node); + + return t; +} + +void PropDataTiledWall::_processor_process(Ref prop_data, Node *node, const Transform &transform) { + TiledWall *t = Object::cast_to(node); + + ERR_FAIL_COND(!t); + + Ref tw; + tw.instance(); + + tw->set_width(t->get_width()); + tw->set_heigth(t->get_heigth()); + tw->set_data(t->get_data()); + tw->set_collision(t->get_collision()); + tw->set_transform(transform * t->get_transform()); + prop_data->add_prop(tw); +} + +Node *PropDataTiledWall::_processor_get_node_for(const Transform &transform) { + TiledWall *t = memnew(TiledWall); + + t->set_width(get_width()); + t->set_heigth(get_heigth()); + t->set_collision(get_collision()); + t->set_data(get_data()); + t->set_transform(get_transform()); + + return t; +} + +PropDataTiledWall::PropDataTiledWall() { + _width = 1; + _height = 1; + _collision = true; +} +PropDataTiledWall::~PropDataTiledWall() { + _data.unref(); +} + +void PropDataTiledWall::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_width"), &PropDataTiledWall::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &PropDataTiledWall::set_width); + ADD_PROPERTY(PropertyInfo(Variant::INT, "width"), "set_width", "get_width"); + + ClassDB::bind_method(D_METHOD("get_heigth"), &PropDataTiledWall::get_heigth); + ClassDB::bind_method(D_METHOD("set_heigth", "value"), &PropDataTiledWall::set_heigth); + ADD_PROPERTY(PropertyInfo(Variant::INT, "heigth"), "set_heigth", "get_heigth"); + + ClassDB::bind_method(D_METHOD("get_data"), &PropDataTiledWall::get_data); + ClassDB::bind_method(D_METHOD("set_data", "value"), &PropDataTiledWall::set_data); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "TiledWallData"), "set_data", "get_data"); + + ClassDB::bind_method(D_METHOD("get_collision"), &PropDataTiledWall::get_collision); + ClassDB::bind_method(D_METHOD("set_collision", "value"), &PropDataTiledWall::set_collision); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision"), "set_collision", "get_collision"); +} diff --git a/props/prop_data_tiled_wall.h b/props/prop_data_tiled_wall.h new file mode 100644 index 0000000..b0ca182 --- /dev/null +++ b/props/prop_data_tiled_wall.h @@ -0,0 +1,65 @@ +/* +Copyright (c) 2019-2021 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef PROP_DATA_TILED_WALL_H +#define PROP_DATA_TILED_WALL_H + +#include "core/math/vector3.h" +#include "prop_data_entry.h" + +class TiledWallData; + +class PropDataTiledWall : public PropDataEntry { + GDCLASS(PropDataTiledWall, PropDataEntry); + +public: + int get_width() const; + void set_width(const int value); + + int get_heigth() const; + void set_heigth(const int value); + + Ref get_data(); + void set_data(const Ref &data); + + bool get_collision() const; + void set_collision(const int value); + + bool _processor_handles(Node *node); + void _processor_process(Ref prop_data, Node *node, const Transform &transform); + Node *_processor_get_node_for(const Transform &transform); + + PropDataTiledWall(); + ~PropDataTiledWall(); + +protected: + static void _bind_methods(); + +private: + int _width; + int _height; + bool _collision; + + Ref _data; +}; + +#endif diff --git a/register_types.cpp b/register_types.cpp index c898067..22bff98 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -39,6 +39,7 @@ SOFTWARE. #include "props/prop_data_portal.h" #include "props/prop_data_prop.h" #include "props/prop_data_scene.h" +#include "props/prop_data_tiled_wall.h" #include "clutter/ground_clutter.h" #include "clutter/ground_clutter_foliage.h" @@ -85,6 +86,7 @@ void register_props_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); @@ -130,6 +132,9 @@ void register_props_types() { Ref portal_processor = Ref(memnew(PropDataPortal)); PropUtils::add_processor(portal_processor); + Ref tiled_wall_processor = Ref(memnew(PropDataTiledWall)); + PropUtils::add_processor(tiled_wall_processor); + #ifdef TOOLS_ENABLED EditorPlugins::add_by_type(); #endif diff --git a/tiled_wall/tiled_wall.cpp b/tiled_wall/tiled_wall.cpp index 99fbc08..b4a4d57 100644 --- a/tiled_wall/tiled_wall.cpp +++ b/tiled_wall/tiled_wall.cpp @@ -137,7 +137,7 @@ void TiledWall::refresh() { //An anouther thread could have initialized it before wo got the mutex! if (!_cache->get_initialized()) { _cache->initial_setup_default(); - + _data->setup_cache(_cache); _cache->refresh_rects(); @@ -209,6 +209,7 @@ void TiledWall::free_mesh() { TiledWall::TiledWall() { _width = 1; _height = 1; + _collision = true; //temporary set_portal_mode(PORTAL_MODE_GLOBAL);