diff --git a/tiled_wall/tiled_wall_data.cpp b/tiled_wall/tiled_wall_data.cpp index 0e4d318..5912158 100644 --- a/tiled_wall/tiled_wall_data.cpp +++ b/tiled_wall/tiled_wall_data.cpp @@ -56,13 +56,13 @@ Ref TiledWallData::get_texture(const int index) const { return _textures.get(index); } -void TiledWallData::set_texture(const int index, const Ref prop) { +void TiledWallData::set_texture(const int index, const Ref texture) { ERR_FAIL_INDEX(index, _textures.size()); - _textures.set(index, prop); + _textures.set(index, texture); } -void TiledWallData::add_texture(const Ref prop) { - _textures.push_back(prop); +void TiledWallData::add_texture(const Ref texture) { + _textures.push_back(texture); } void TiledWallData::remove_texture(const int index) { ERR_FAIL_INDEX(index, _textures.size()); @@ -85,27 +85,78 @@ Vector TiledWallData::get_textures() { } return r; } -void TiledWallData::set_textures(const Vector &props) { +void TiledWallData::set_textures(const Vector &textures) { _textures.clear(); - for (int i = 0; i < props.size(); i++) { - Ref tex = Ref(props[i]); + for (int i = 0; i < textures.size(); i++) { + Ref tex = Ref(textures[i]); _textures.push_back(tex); } } +//flavour_textures +Ref TiledWallData::get_flavour_texture(const int index) const { + ERR_FAIL_INDEX_V(index, _flavour_textures.size(), Ref()); + + return _flavour_textures.get(index); +} +void TiledWallData::set_flavour_texture(const int index, const Ref texture) { + ERR_FAIL_INDEX(index, _flavour_textures.size()); + + _flavour_textures.set(index, texture); +} +void TiledWallData::add_flavour_texture(const Ref texture) { + _flavour_textures.push_back(texture); +} +void TiledWallData::remove_flavour_texture(const int index) { + ERR_FAIL_INDEX(index, _flavour_textures.size()); + + _flavour_textures.remove(index); +} + +int TiledWallData::get_flavour_texture_count() const { + return _flavour_textures.size(); +} + +Vector TiledWallData::get_flavour_textures() { + Vector r; + for (int i = 0; i < _flavour_textures.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_flavour_textures[i].get_ref_ptr()); +#else + r.push_back(_flavour_textures[i]); +#endif + } + return r; +} +void TiledWallData::set_flavour_textures(const Vector &textures) { + _flavour_textures.clear(); + for (int i = 0; i < textures.size(); i++) { + Ref tex = Ref(textures[i]); + + _flavour_textures.push_back(tex); + } +} + #if TEXTURE_PACKER_PRESENT void TiledWallData::add_textures_into(Ref texture_packer) { ERR_FAIL_COND(!texture_packer.is_valid()); for (int i = 0; i < _textures.size(); ++i) { - Ref entry = _textures.get(i); if (entry.is_valid()) { texture_packer->add_texture(entry); } } + + for (int i = 0; i < _flavour_textures.size(); ++i) { + Ref entry = _flavour_textures.get(i); + + if (entry.is_valid()) { + texture_packer->add_texture(entry); + } + } } #endif @@ -134,6 +185,12 @@ void TiledWallData::copy_from(const Ref &prop_data) { _textures.push_back(prop_data->_textures[i]); } + _flavour_textures.clear(); + + for (int i = 0; i < prop_data->_flavour_textures.size(); ++i) { + _flavour_textures.push_back(prop_data->_flavour_textures[i]); + } + emit_changed(); } @@ -145,6 +202,7 @@ TiledWallData::TiledWallData() { } TiledWallData::~TiledWallData() { _textures.clear(); + _flavour_textures.clear(); } void TiledWallData::_bind_methods() { @@ -156,6 +214,7 @@ void TiledWallData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &TiledWallData::set_snap_axis); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis"); + //textures ClassDB::bind_method(D_METHOD("get_texture", "index"), &TiledWallData::get_texture); ClassDB::bind_method(D_METHOD("set_texture", "index", "texture"), &TiledWallData::set_texture); ClassDB::bind_method(D_METHOD("add_texture", "texture"), &TiledWallData::add_texture); @@ -167,6 +226,18 @@ void TiledWallData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_textures", "textures"), &TiledWallData::set_textures); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "17/17:Texture", PROPERTY_USAGE_DEFAULT, "Texture"), "set_textures", "get_textures"); + //flavour_textures + ClassDB::bind_method(D_METHOD("get_flavour_texture", "index"), &TiledWallData::get_flavour_texture); + ClassDB::bind_method(D_METHOD("set_flavour_texture", "index", "texture"), &TiledWallData::set_flavour_texture); + ClassDB::bind_method(D_METHOD("add_tflavour_exture", "texture"), &TiledWallData::add_flavour_texture); + ClassDB::bind_method(D_METHOD("remove_flavour_texture", "index"), &TiledWallData::remove_flavour_texture); + + ClassDB::bind_method(D_METHOD("get_flavour_texture_count"), &TiledWallData::get_flavour_texture_count); + + ClassDB::bind_method(D_METHOD("get_flavour_textures"), &TiledWallData::get_flavour_textures); + ClassDB::bind_method(D_METHOD("set_flavour_textures", "textures"), &TiledWallData::set_flavour_textures); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "17/17:Texture", PROPERTY_USAGE_DEFAULT, "Texture"), "set_flavour_textures", "get_flavour_textures"); + #if TEXTURE_PACKER_PRESENT ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &TiledWallData::add_textures_into); #endif diff --git a/tiled_wall/tiled_wall_data.h b/tiled_wall/tiled_wall_data.h index a900207..3589d85 100644 --- a/tiled_wall/tiled_wall_data.h +++ b/tiled_wall/tiled_wall_data.h @@ -59,9 +59,10 @@ public: Vector3 get_snap_axis() const; void set_snap_axis(const Vector3 &value); + //textures Ref get_texture(const int index) const; - void set_texture(const int index, const Ref prop); - void add_texture(const Ref prop); + void set_texture(const int index, const Ref texture); + void add_texture(const Ref texture); void remove_texture(const int index); int get_texture_count() const; @@ -69,6 +70,17 @@ public: Vector get_textures(); void set_textures(const Vector &textures); + //flavour_textures + Ref get_flavour_texture(const int index) const; + void set_flavour_texture(const int index, const Ref texture); + void add_flavour_texture(const Ref texture); + void remove_flavour_texture(const int index); + + int get_flavour_texture_count() const; + + Vector get_flavour_textures(); + void set_flavour_textures(const Vector &textures); + #if TEXTURE_PACKER_PRESENT void add_textures_into(Ref texture_packer); #endif @@ -93,6 +105,7 @@ private: Vector3 _snap_axis; Vector> _textures; + Vector> _flavour_textures; bool _is_room; PoolVector3Array _room_bounds;