Added collider z offset, and texture scale parameters to TiledWallData. Also smaller fixes and codestyle improvements.

This commit is contained in:
Relintai 2022-07-31 11:29:03 +02:00
parent 6c35a83d9f
commit 71f9dd4cd2
3 changed files with 84 additions and 9 deletions

View File

@ -232,8 +232,9 @@ void TiledWall::clear_mesh() {
_mesh_array.clear(); _mesh_array.clear();
if (_mesh_rid != RID()) { if (_mesh_rid != RID()) {
if (VS::get_singleton()->mesh_get_surface_count(_mesh_rid) > 0) if (VS::get_singleton()->mesh_get_surface_count(_mesh_rid) > 0) {
VS::get_singleton()->mesh_remove_surface(_mesh_rid, 0); VS::get_singleton()->mesh_remove_surface(_mesh_rid, 0);
}
} }
} }

View File

@ -61,6 +61,13 @@ void TiledWallData::set_collider_type(const TiledWallData::TiledWallColliderType
emit_changed(); emit_changed();
} }
float TiledWallData::get_colldier_z_offset() {
return _colldier_z_offset;
}
void TiledWallData::set_colldier_z_offset(const float val) {
_colldier_z_offset = val;
}
void TiledWallData::add_tile(const Ref<Texture> &texture, const Vector2 &val, const float z_offset) { void TiledWallData::add_tile(const Ref<Texture> &texture, const Vector2 &val, const float z_offset) {
_tiles.push_back(texture); _tiles.push_back(texture);
} }
@ -86,7 +93,7 @@ void TiledWallData::set_tile_texture(const int index, const Ref<Texture> &textur
} }
float TiledWallData::get_tile_y_size(const int index) const { float TiledWallData::get_tile_y_size(const int index) const {
ERR_FAIL_INDEX_V(index, _tiles.size(),1); ERR_FAIL_INDEX_V(index, _tiles.size(), 1);
return _tiles.get(index).y_size; return _tiles.get(index).y_size;
} }
@ -111,6 +118,19 @@ void TiledWallData::set_tile_z_offset(const int index, const float val) {
emit_changed(); emit_changed();
} }
int TiledWallData::get_tile_texture_scale(const int index) const {
ERR_FAIL_INDEX_V(index, _tiles.size(), 0);
return _tiles.get(index).texture_scale;
}
void TiledWallData::set_tile_texture_scale(const int index, const int val) {
ERR_FAIL_INDEX(index, _tiles.size());
_tiles.write[index].texture_scale = val;
emit_changed();
}
int TiledWallData::get_tile_count() const { int TiledWallData::get_tile_count() const {
return _tiles.size(); return _tiles.size();
} }
@ -170,6 +190,19 @@ void TiledWallData::set_flavour_tile_z_offset(const int index, const float val)
emit_changed(); emit_changed();
} }
int TiledWallData::get_flavour_tile_texture_scale(const int index) const {
ERR_FAIL_INDEX_V(index, _flavour_tiles.size(), 0);
return _flavour_tiles.get(index).texture_scale;
}
void TiledWallData::set_flavour_tile_texture_scale(const int index, const int val) {
ERR_FAIL_INDEX(index, _flavour_tiles.size());
_flavour_tiles.write[index].texture_scale = val;
emit_changed();
}
int TiledWallData::get_flavour_tile_count() const { int TiledWallData::get_flavour_tile_count() const {
return _flavour_tiles.size(); return _flavour_tiles.size();
} }
@ -341,10 +374,14 @@ bool TiledWallData::_set(const StringName &p_name, const Variant &p_value) {
} else if (p == "z_offset") { } else if (p == "z_offset") {
_tiles.write[index].z_offset = p_value; _tiles.write[index].z_offset = p_value;
return true;
} else if (p == "texture_scale") {
_tiles.write[index].texture_scale = p_value;
return true; return true;
} }
} else if (name.begins_with("flavour_tile_")) { } else if (name.begins_with("flavour_tile_")) {
int index = name.get_slicec('_', 1).to_int(); int index = name.get_slicec('_', 2).to_int();
if (index >= _flavour_tiles.size()) { if (index >= _flavour_tiles.size()) {
_flavour_tiles.resize(index + 1); _flavour_tiles.resize(index + 1);
@ -363,6 +400,10 @@ bool TiledWallData::_set(const StringName &p_name, const Variant &p_value) {
} else if (p == "z_offset") { } else if (p == "z_offset") {
_flavour_tiles.write[index].z_offset = p_value; _flavour_tiles.write[index].z_offset = p_value;
return true;
} else if (p == "texture_scale") {
_flavour_tiles.write[index].texture_scale = p_value;
return true; return true;
} }
} }
@ -393,10 +434,14 @@ bool TiledWallData::_get(const StringName &p_name, Variant &r_ret) const {
} else if (p == "z_offset") { } else if (p == "z_offset") {
r_ret = _tiles[index].z_offset; r_ret = _tiles[index].z_offset;
return true;
} else if (p == "texture_scale") {
r_ret = _tiles[index].texture_scale;
return true; return true;
} }
} else if (name.begins_with("flavour_tile_")) { } else if (name.begins_with("flavour_tile_")) {
int index = name.get_slicec('_', 1).to_int(); int index = name.get_slicec('_', 2).to_int();
if (index >= _flavour_tiles.size()) { if (index >= _flavour_tiles.size()) {
return false; return false;
@ -415,6 +460,10 @@ bool TiledWallData::_get(const StringName &p_name, Variant &r_ret) const {
} else if (p == "z_offset") { } else if (p == "z_offset") {
r_ret = _flavour_tiles[index].z_offset; r_ret = _flavour_tiles[index].z_offset;
return true;
} else if (p == "texture_scale") {
r_ret = _flavour_tiles[index].texture_scale;
return true; return true;
} }
} }
@ -425,14 +474,16 @@ bool TiledWallData::_get(const StringName &p_name, Variant &r_ret) const {
void TiledWallData::_get_property_list(List<PropertyInfo> *p_list) const { void TiledWallData::_get_property_list(List<PropertyInfo> *p_list) const {
for (int i = 0; i < _tiles.size(); ++i) { for (int i = 0; i < _tiles.size(); ++i) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT)); p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT));
p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/y_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/y_size"));
p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/z_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); p_list->push_back(PropertyInfo(Variant::REAL, "tile_" + itos(i) + "/z_offset"));
p_list->push_back(PropertyInfo(Variant::INT, "tile_" + itos(i) + "/texture_scale"));
} }
for (int i = 0; i < _flavour_tiles.size(); ++i) { for (int i = 0; i < _flavour_tiles.size(); ++i) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "flavour_tile_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT)); p_list->push_back(PropertyInfo(Variant::OBJECT, "flavour_tile_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT));
p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/y_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/y_size"));
p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/z_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT)); p_list->push_back(PropertyInfo(Variant::REAL, "flavour_tile_" + itos(i) + "/z_offset"));
p_list->push_back(PropertyInfo(Variant::INT, "flavour_tile_" + itos(i) + "/texture_scale"));
} }
} }
@ -445,6 +496,10 @@ void TiledWallData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collider_type", "texture"), &TiledWallData::set_collider_type); ClassDB::bind_method(D_METHOD("set_collider_type", "texture"), &TiledWallData::set_collider_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_type", PROPERTY_HINT_ENUM, TiledWallData::BINDING_STRING_TILED_WALL_COLLIDER_TYPE), "set_collider_type", "get_collider_type"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_type", PROPERTY_HINT_ENUM, TiledWallData::BINDING_STRING_TILED_WALL_COLLIDER_TYPE), "set_collider_type", "get_collider_type");
ClassDB::bind_method(D_METHOD("get_colldier_z_offset"), &TiledWallData::get_colldier_z_offset);
ClassDB::bind_method(D_METHOD("set_colldier_z_offset", "val"), &TiledWallData::set_colldier_z_offset);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "colldier_z_offset"), "set_colldier_z_offset", "get_colldier_z_offset");
//textures //textures
ClassDB::bind_method(D_METHOD("add_tile", "texture", "size", "z_offset"), &TiledWallData::add_tile, Vector2(1, 1), 0); ClassDB::bind_method(D_METHOD("add_tile", "texture", "size", "z_offset"), &TiledWallData::add_tile, Vector2(1, 1), 0);
ClassDB::bind_method(D_METHOD("remove_tile", "index"), &TiledWallData::remove_tile); ClassDB::bind_method(D_METHOD("remove_tile", "index"), &TiledWallData::remove_tile);
@ -458,6 +513,9 @@ void TiledWallData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tile_z_offset", "index"), &TiledWallData::get_tile_z_offset); ClassDB::bind_method(D_METHOD("get_tile_z_offset", "index"), &TiledWallData::get_tile_z_offset);
ClassDB::bind_method(D_METHOD("set_tile_z_offset", "index", "val"), &TiledWallData::set_tile_z_offset); ClassDB::bind_method(D_METHOD("set_tile_z_offset", "index", "val"), &TiledWallData::set_tile_z_offset);
ClassDB::bind_method(D_METHOD("get_tile_texture_scale", "index"), &TiledWallData::get_tile_texture_scale);
ClassDB::bind_method(D_METHOD("set_tile_texture_scale", "index", "val"), &TiledWallData::set_tile_texture_scale);
ClassDB::bind_method(D_METHOD("get_tile_count"), &TiledWallData::get_tile_count); ClassDB::bind_method(D_METHOD("get_tile_count"), &TiledWallData::get_tile_count);
ClassDB::bind_method(D_METHOD("set_tile_count", "count"), &TiledWallData::set_tile_count); ClassDB::bind_method(D_METHOD("set_tile_count", "count"), &TiledWallData::set_tile_count);
ADD_PROPERTY(PropertyInfo(Variant::INT, "set_tile_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_tile_count", "get_tile_count"); ADD_PROPERTY(PropertyInfo(Variant::INT, "set_tile_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_tile_count", "get_tile_count");
@ -475,6 +533,9 @@ void TiledWallData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_flavour_tile_z_offset", "index"), &TiledWallData::get_flavour_tile_z_offset); ClassDB::bind_method(D_METHOD("get_flavour_tile_z_offset", "index"), &TiledWallData::get_flavour_tile_z_offset);
ClassDB::bind_method(D_METHOD("set_flavour_tile_z_offset", "index", "val"), &TiledWallData::set_flavour_tile_z_offset); ClassDB::bind_method(D_METHOD("set_flavour_tile_z_offset", "index", "val"), &TiledWallData::set_flavour_tile_z_offset);
ClassDB::bind_method(D_METHOD("get_flavour_tile_texture_scale", "index"), &TiledWallData::get_flavour_tile_texture_scale);
ClassDB::bind_method(D_METHOD("set_flavour_tile_texture_scale", "index", "val"), &TiledWallData::set_flavour_tile_texture_scale);
ClassDB::bind_method(D_METHOD("get_flavour_tile_count"), &TiledWallData::get_flavour_tile_count); ClassDB::bind_method(D_METHOD("get_flavour_tile_count"), &TiledWallData::get_flavour_tile_count);
ClassDB::bind_method(D_METHOD("set_flavour_tile_count", "count"), &TiledWallData::set_flavour_tile_count); ClassDB::bind_method(D_METHOD("set_flavour_tile_count", "count"), &TiledWallData::set_flavour_tile_count);
ADD_PROPERTY(PropertyInfo(Variant::INT, "flavour_tile_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_flavour_tile_count", "get_flavour_tile_count"); ADD_PROPERTY(PropertyInfo(Variant::INT, "flavour_tile_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_flavour_tile_count", "get_flavour_tile_count");

View File

@ -69,6 +69,9 @@ public:
TiledWallColliderType get_collider_type() const; TiledWallColliderType get_collider_type() const;
void set_collider_type(const TiledWallColliderType value); void set_collider_type(const TiledWallColliderType value);
float get_colldier_z_offset();
void set_colldier_z_offset(const float val);
//textures //textures
void add_tile(const Ref<Texture> &texture, const Vector2 &val = Vector2(1, 1), const float z_offset = 0); void add_tile(const Ref<Texture> &texture, const Vector2 &val = Vector2(1, 1), const float z_offset = 0);
void remove_tile(const int index); void remove_tile(const int index);
@ -82,6 +85,9 @@ public:
float get_tile_z_offset(const int index) const; float get_tile_z_offset(const int index) const;
void set_tile_z_offset(const int index, const float val); void set_tile_z_offset(const int index, const float val);
int get_tile_texture_scale(const int index) const;
void set_tile_texture_scale(const int index, const int val);
int get_tile_count() const; int get_tile_count() const;
void set_tile_count(const int count); void set_tile_count(const int count);
@ -98,6 +104,9 @@ public:
float get_flavour_tile_z_offset(const int index) const; float get_flavour_tile_z_offset(const int index) const;
void set_flavour_tile_z_offset(const int index, const float val); void set_flavour_tile_z_offset(const int index, const float val);
int get_flavour_tile_texture_scale(const int index) const;
void set_flavour_tile_texture_scale(const int index, const int val);
int get_flavour_tile_count() const; int get_flavour_tile_count() const;
void set_flavour_tile_count(const int count); void set_flavour_tile_count(const int count);
@ -140,21 +149,25 @@ private:
Ref<Texture> texture; Ref<Texture> texture;
float y_size; float y_size;
float z_offset; float z_offset;
int texture_scale;
TextureEntry() { TextureEntry() {
y_size = 1; y_size = 1;
z_offset = 0; z_offset = 0;
texture_scale = 1;
} }
TextureEntry(const Ref<Texture> &p_texture, const float p_y_size = 1, const float p_z_offset = 0) { TextureEntry(const Ref<Texture> &p_texture, const float p_y_size = 1, const float p_z_offset = 0, const float p_texture_scale = 0) {
texture = p_texture; texture = p_texture;
y_size = p_y_size; y_size = p_y_size;
z_offset = p_z_offset; z_offset = p_z_offset;
texture_scale = p_texture_scale;
} }
}; };
TiledWallTilingType _tiling_type; TiledWallTilingType _tiling_type;
TiledWallColliderType _collider_type; TiledWallColliderType _collider_type;
float _colldier_z_offset;
Vector<TextureEntry> _tiles; Vector<TextureEntry> _tiles;
Vector<TextureEntry> _flavour_tiles; Vector<TextureEntry> _flavour_tiles;