Added a tiling type enum to TiledWallData. Also removed the now unused members and renamed a parameter.

This commit is contained in:
Relintai 2021-08-17 02:24:32 +02:00
parent 362f8f803b
commit b057e8d9af
2 changed files with 42 additions and 21 deletions

View File

@ -30,6 +30,15 @@ SOFTWARE.
#define Shape Shape3D #define Shape Shape3D
#endif #endif
const String TiledWallData::BINDING_STRING_TILED_WALL_TILING_TYPE = "None,Horizontal,Vertical,Both";
TiledWallData::TiledWallTilingType TiledWallData::get_tiling_type() const {
return _tiling_type;
}
void TiledWallData::set_tiling_type(const TiledWallData::TiledWallTilingType value) {
_tiling_type = value;
}
Ref<Texture> TiledWallData::get_texture(const int index) const { Ref<Texture> TiledWallData::get_texture(const int index) const {
ERR_FAIL_INDEX_V(index, _textures.size(), Ref<Texture>()); ERR_FAIL_INDEX_V(index, _textures.size(), Ref<Texture>());
@ -139,31 +148,24 @@ void TiledWallData::add_textures_into(Ref<TexturePacker> texture_packer) {
} }
#endif #endif
void TiledWallData::copy_from(const Ref<TiledWallData> &prop_data) { void TiledWallData::copy_from(const Ref<TiledWallData> &tiled_wall_data) {
_id = prop_data->_id;
_snap_to_mesh = prop_data->_snap_to_mesh;
_snap_axis = prop_data->_snap_axis;
_textures.clear(); _textures.clear();
for (int i = 0; i < prop_data->_textures.size(); ++i) { for (int i = 0; i < tiled_wall_data->_textures.size(); ++i) {
_textures.push_back(prop_data->_textures[i]); _textures.push_back(tiled_wall_data->_textures[i]);
} }
_flavour_textures.clear(); _flavour_textures.clear();
for (int i = 0; i < prop_data->_flavour_textures.size(); ++i) { for (int i = 0; i < tiled_wall_data->_flavour_textures.size(); ++i) {
_flavour_textures.push_back(prop_data->_flavour_textures[i]); _flavour_textures.push_back(tiled_wall_data->_flavour_textures[i]);
} }
emit_changed(); emit_changed();
} }
TiledWallData::TiledWallData() { TiledWallData::TiledWallData() {
_id = 0; _tiling_type = TILED_WALL_TILING_TYPE_NONE;
_snap_to_mesh = false;
_is_room = false;
_snap_axis = Vector3(0, -1, 0);
} }
TiledWallData::~TiledWallData() { TiledWallData::~TiledWallData() {
_textures.clear(); _textures.clear();
@ -171,6 +173,10 @@ TiledWallData::~TiledWallData() {
} }
void TiledWallData::_bind_methods() { void TiledWallData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tiling_type"), &TiledWallData::get_tiling_type);
ClassDB::bind_method(D_METHOD("set_tiling_type", "texture"), &TiledWallData::set_tiling_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "tiling_type", PROPERTY_HINT_ENUM, "17/17:Texture"), "set_tiling_type", "get_tiling_type");
//textures //textures
ClassDB::bind_method(D_METHOD("get_texture", "index"), &TiledWallData::get_texture); 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("set_texture", "index", "texture"), &TiledWallData::set_texture);
@ -193,11 +199,16 @@ void TiledWallData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_flavour_textures"), &TiledWallData::get_flavour_textures); 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); 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"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "flavour_textures", PROPERTY_HINT_NONE, "17/17:Texture", PROPERTY_USAGE_DEFAULT, "Texture"), "set_flavour_textures", "get_flavour_textures");
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &TiledWallData::add_textures_into); ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &TiledWallData::add_textures_into);
#endif #endif
ClassDB::bind_method(D_METHOD("copy_from", "prop_data"), &TiledWallData::copy_from); ClassDB::bind_method(D_METHOD("copy_from", "prop_data"), &TiledWallData::copy_from);
BIND_ENUM_CONSTANT(TILED_WALL_TILING_TYPE_NONE);
BIND_ENUM_CONSTANT(TILED_WALL_TILING_TYPE_HORIZONTAL);
BIND_ENUM_CONSTANT(TILED_WALL_TILING_TYPE_VERTICAL);
BIND_ENUM_CONSTANT(TILED_WALL_TILING_TYPE_BOTH);
} }

View File

@ -50,6 +50,19 @@ class TiledWallData : public Resource {
GDCLASS(TiledWallData, Resource); GDCLASS(TiledWallData, Resource);
public: public:
enum TiledWallTilingType {
TILED_WALL_TILING_TYPE_NONE = 0,
TILED_WALL_TILING_TYPE_HORIZONTAL,
TILED_WALL_TILING_TYPE_VERTICAL,
TILED_WALL_TILING_TYPE_BOTH
};
static const String BINDING_STRING_TILED_WALL_TILING_TYPE;
public:
TiledWallTilingType get_tiling_type() const;
void set_tiling_type(const TiledWallTilingType value);
//textures //textures
Ref<Texture> get_texture(const int index) const; Ref<Texture> get_texture(const int index) const;
void set_texture(const int index, const Ref<Texture> &texture); void set_texture(const int index, const Ref<Texture> &texture);
@ -76,7 +89,7 @@ public:
void add_textures_into(Ref<TexturePacker> texture_packer); void add_textures_into(Ref<TexturePacker> texture_packer);
#endif #endif
void copy_from(const Ref<TiledWallData> &prop_data); void copy_from(const Ref<TiledWallData> &tiled_wall_data);
TiledWallData(); TiledWallData();
~TiledWallData(); ~TiledWallData();
@ -85,15 +98,12 @@ protected:
static void _bind_methods(); static void _bind_methods();
private: private:
int _id; TiledWallTilingType _tiling_type;
bool _snap_to_mesh;
Vector3 _snap_axis;
Vector<Ref<Texture>> _textures; Vector<Ref<Texture>> _textures;
Vector<Ref<Texture>> _flavour_textures; Vector<Ref<Texture>> _flavour_textures;
bool _is_room;
PoolVector3Array _room_bounds;
}; };
VARIANT_ENUM_CAST(TiledWallData::TiledWallTilingType);
#endif #endif