Added an another set of getters/setters for flavour textures into TiledWallData.

This commit is contained in:
Relintai 2021-08-17 01:12:56 +02:00
parent b292a387cb
commit acf1af1e77
2 changed files with 94 additions and 10 deletions

View File

@ -56,13 +56,13 @@ Ref<Texture> TiledWallData::get_texture(const int index) const {
return _textures.get(index);
}
void TiledWallData::set_texture(const int index, const Ref<Texture> prop) {
void TiledWallData::set_texture(const int index, const Ref<Texture> texture) {
ERR_FAIL_INDEX(index, _textures.size());
_textures.set(index, prop);
_textures.set(index, texture);
}
void TiledWallData::add_texture(const Ref<Texture> prop) {
_textures.push_back(prop);
void TiledWallData::add_texture(const Ref<Texture> texture) {
_textures.push_back(texture);
}
void TiledWallData::remove_texture(const int index) {
ERR_FAIL_INDEX(index, _textures.size());
@ -85,27 +85,78 @@ Vector<Variant> TiledWallData::get_textures() {
}
return r;
}
void TiledWallData::set_textures(const Vector<Variant> &props) {
void TiledWallData::set_textures(const Vector<Variant> &textures) {
_textures.clear();
for (int i = 0; i < props.size(); i++) {
Ref<Texture> tex = Ref<Texture>(props[i]);
for (int i = 0; i < textures.size(); i++) {
Ref<Texture> tex = Ref<Texture>(textures[i]);
_textures.push_back(tex);
}
}
//flavour_textures
Ref<Texture> TiledWallData::get_flavour_texture(const int index) const {
ERR_FAIL_INDEX_V(index, _flavour_textures.size(), Ref<Texture>());
return _flavour_textures.get(index);
}
void TiledWallData::set_flavour_texture(const int index, const Ref<Texture> texture) {
ERR_FAIL_INDEX(index, _flavour_textures.size());
_flavour_textures.set(index, texture);
}
void TiledWallData::add_flavour_texture(const Ref<Texture> 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<Variant> TiledWallData::get_flavour_textures() {
Vector<Variant> 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<Variant> &textures) {
_flavour_textures.clear();
for (int i = 0; i < textures.size(); i++) {
Ref<Texture> tex = Ref<Texture>(textures[i]);
_flavour_textures.push_back(tex);
}
}
#if TEXTURE_PACKER_PRESENT
void TiledWallData::add_textures_into(Ref<TexturePacker> texture_packer) {
ERR_FAIL_COND(!texture_packer.is_valid());
for (int i = 0; i < _textures.size(); ++i) {
Ref<Texture> entry = _textures.get(i);
if (entry.is_valid()) {
texture_packer->add_texture(entry);
}
}
for (int i = 0; i < _flavour_textures.size(); ++i) {
Ref<Texture> 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<TiledWallData> &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

View File

@ -59,9 +59,10 @@ public:
Vector3 get_snap_axis() const;
void set_snap_axis(const Vector3 &value);
//textures
Ref<Texture> get_texture(const int index) const;
void set_texture(const int index, const Ref<Texture> prop);
void add_texture(const Ref<Texture> prop);
void set_texture(const int index, const Ref<Texture> texture);
void add_texture(const Ref<Texture> texture);
void remove_texture(const int index);
int get_texture_count() const;
@ -69,6 +70,17 @@ public:
Vector<Variant> get_textures();
void set_textures(const Vector<Variant> &textures);
//flavour_textures
Ref<Texture> get_flavour_texture(const int index) const;
void set_flavour_texture(const int index, const Ref<Texture> texture);
void add_flavour_texture(const Ref<Texture> texture);
void remove_flavour_texture(const int index);
int get_flavour_texture_count() const;
Vector<Variant> get_flavour_textures();
void set_flavour_textures(const Vector<Variant> &textures);
#if TEXTURE_PACKER_PRESENT
void add_textures_into(Ref<TexturePacker> texture_packer);
#endif
@ -93,6 +105,7 @@ private:
Vector3 _snap_axis;
Vector<Ref<Texture>> _textures;
Vector<Ref<Texture>> _flavour_textures;
bool _is_room;
PoolVector3Array _room_bounds;