diff --git a/tile_map.cpp b/tile_map.cpp index 4616566..90bfd3d 100644 --- a/tile_map.cpp +++ b/tile_map.cpp @@ -185,6 +185,7 @@ void RTileMap::set_tileset(const Ref &p_tileset) { if (tile_set.is_valid()) { tile_set->connect("changed", this, "_recreate_quadrants"); tile_set->add_change_receptor(this); + tile_set->setup_noise(noise); } else { clear(); } @@ -1900,8 +1901,6 @@ void RTileMap::_changed_callback(Object *p_changed, const char *p_prop) { RTileMap::RTileMap() { noise.instance(); - //noise->set_seed(Math::rand()); - noise->set_noise_type(FastNoise::TYPE_PERLIN); rect_cache_dirty = true; used_size_cache_dirty = true; diff --git a/tile_set.cpp b/tile_set.cpp index 38a63bd..4eea652 100644 --- a/tile_set.cpp +++ b/tile_set.cpp @@ -1087,6 +1087,18 @@ int RTileSet::get_last_unused_tile_id() const { } } +void RTileSet::set_noise_params(const Ref &noise) { + _noise_params = noise; +} +Ref RTileSet::get_noise_params() { + return _noise_params; +} +void RTileSet::setup_noise(Ref noise) { + if (_noise_params.is_valid()) { + _noise_params->setup_noise(noise); + } +} + int RTileSet::find_tile_by_name(const String &p_name) const { for (Map::Element *E = tile_map.front(); E; E = E->next()) { if (p_name == E->get().name) { @@ -1170,6 +1182,12 @@ void RTileSet::_bind_methods() { ClassDB::bind_method(D_METHOD("find_tile_by_name", "name"), &RTileSet::find_tile_by_name); ClassDB::bind_method(D_METHOD("get_tiles_ids"), &RTileSet::_get_tiles_ids); + ClassDB::bind_method(D_METHOD("set_noise_params", "noise"), &RTileSet::set_noise_params); + ClassDB::bind_method(D_METHOD("get_noise_params"), &RTileSet::get_noise_params); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, "FastnoiseNoiseParams"), "set_noise_params", "get_noise_params"); + + ClassDB::bind_method(D_METHOD("setup_noise", "noise"), &RTileSet::setup_noise); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_tile_bound", PropertyInfo(Variant::INT, "drawn_id"), PropertyInfo(Variant::INT, "neighbor_id"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_forward_subtile_selection", PropertyInfo(Variant::INT, "autotile_id"), PropertyInfo(Variant::INT, "bitmask"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "RTileMap"), PropertyInfo(Variant::VECTOR2, "tile_location"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_forward_atlas_subtile_selection", PropertyInfo(Variant::INT, "atlastile_id"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "RTileMap"), PropertyInfo(Variant::VECTOR2, "tile_location"))); diff --git a/tile_set.h b/tile_set.h index e0fa02f..34425c8 100644 --- a/tile_set.h +++ b/tile_set.h @@ -38,6 +38,8 @@ #include "scene/resources/convex_polygon_shape_2d.h" #include "scene/resources/shape_2d.h" #include "scene/resources/texture.h" +#include "../fastnoise/noise.h" +#include "../fastnoise/fastnoise_noise_params.h" class RTileSet : public Resource { GDCLASS(RTileSet, Resource); @@ -136,6 +138,8 @@ private: Map tile_map; + Ref _noise_params; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -259,6 +263,10 @@ public: int get_last_unused_tile_id() const; + void set_noise_params(const Ref &noise); + Ref get_noise_params(); + void setup_noise(Ref noise); + RTileSet(); };