summaryrefslogtreecommitdiff
path: root/scene/resources/tile_set.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/tile_set.cpp')
-rw-r--r--scene/resources/tile_set.cpp51
1 files changed, 42 insertions, 9 deletions
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index e3c27b0c0c..208ba5bb66 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -44,8 +44,10 @@ bool TileSet::_set(const StringName& p_name, const Variant& p_value) {
tile_set_name(id,p_value);
else if (what=="texture")
tile_set_texture(id,p_value);
- else if (what=="offset")
- tile_set_offset(id,p_value);
+ else if (what=="tex_offset")
+ tile_set_texture_offset(id,p_value);
+ else if (what=="shape_offset")
+ tile_set_shape_offset(id,p_value);
else if (what=="region")
tile_set_region(id,p_value);
else if (what=="shape")
@@ -75,8 +77,10 @@ bool TileSet::_get(const StringName& p_name,Variant &r_ret) const{
r_ret=tile_get_name(id);
else if (what=="texture")
r_ret=tile_get_texture(id);
- else if (what=="offset")
- r_ret=tile_get_offset(id);
+ else if (what=="tex_offset")
+ r_ret=tile_get_texture_offset(id);
+ else if (what=="shape_offset")
+ r_ret=tile_get_shape_offset(id);
else if (what=="region")
r_ret=tile_get_region(id);
else if (what=="shape")
@@ -98,7 +102,8 @@ void TileSet::_get_property_list( List<PropertyInfo> *p_list) const{
String pre = itos(id)+"/";
p_list->push_back(PropertyInfo(Variant::STRING,pre+"name"));
p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"offset"));
+ p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"tex_offset"));
+ p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"shape_offset"));
p_list->push_back(PropertyInfo(Variant::RECT2,pre+"region"));
p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D",PROPERTY_USAGE_EDITOR));
p_list->push_back(PropertyInfo(Variant::ARRAY,pre+"shapes",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR));
@@ -129,20 +134,34 @@ Ref<Texture> TileSet::tile_get_texture(int p_id) const {
}
-void TileSet::tile_set_offset(int p_id,const Vector2 &p_offset) {
+void TileSet::tile_set_texture_offset(int p_id,const Vector2 &p_offset) {
ERR_FAIL_COND(!tile_map.has(p_id));
tile_map[p_id].offset=p_offset;
emit_changed();
}
-Vector2 TileSet::tile_get_offset(int p_id) const {
+Vector2 TileSet::tile_get_texture_offset(int p_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id),Vector2());
return tile_map[p_id].offset;
}
+void TileSet::tile_set_shape_offset(int p_id,const Vector2 &p_offset) {
+
+ ERR_FAIL_COND(!tile_map.has(p_id));
+ tile_map[p_id].shape_offset=p_offset;
+ emit_changed();
+}
+
+Vector2 TileSet::tile_get_shape_offset(int p_id) const {
+
+ ERR_FAIL_COND_V(!tile_map.has(p_id),Vector2());
+ return tile_map[p_id].shape_offset;
+
+}
+
void TileSet::tile_set_region(int p_id,const Rect2 &p_region) {
ERR_FAIL_COND(!tile_map.has(p_id));
@@ -231,6 +250,17 @@ Array TileSet::_tile_get_shapes(int p_id) const{
return arr;
}
+Array TileSet::_get_tiles_ids() const{
+
+ Array arr;
+
+ for (Map<int, Data>::Element *E = tile_map.front(); E; E = E->next()) {
+ arr.push_back(E->key());
+ }
+
+ return arr;
+}
+
void TileSet::get_tile_list(List<int> *p_tiles) const {
for(Map<int,Data>::Element *E=tile_map.front();E;E=E->next()) {
@@ -289,8 +319,10 @@ void TileSet::_bind_methods() {
ObjectTypeDB::bind_method(_MD("tile_get_name","id"),&TileSet::tile_get_name);
ObjectTypeDB::bind_method(_MD("tile_set_texture","id","texture:Texture"),&TileSet::tile_set_texture);
ObjectTypeDB::bind_method(_MD("tile_get_texture:Texture","id"),&TileSet::tile_get_texture);
- ObjectTypeDB::bind_method(_MD("tile_set_offset","id","offset"),&TileSet::tile_set_offset);
- ObjectTypeDB::bind_method(_MD("tile_get_offset","id"),&TileSet::tile_get_offset);
+ ObjectTypeDB::bind_method(_MD("tile_set_texture_offset","id","texture_offset"),&TileSet::tile_set_texture_offset);
+ ObjectTypeDB::bind_method(_MD("tile_get_texture_offset","id"),&TileSet::tile_get_texture_offset);
+ ObjectTypeDB::bind_method(_MD("tile_set_shape_offset","id","shape_offset"),&TileSet::tile_set_shape_offset);
+ ObjectTypeDB::bind_method(_MD("tile_get_shape_offset","id"),&TileSet::tile_get_shape_offset);
ObjectTypeDB::bind_method(_MD("tile_set_region","id","region"),&TileSet::tile_set_region);
ObjectTypeDB::bind_method(_MD("tile_get_region","id"),&TileSet::tile_get_region);
ObjectTypeDB::bind_method(_MD("tile_set_shape","id","shape:Shape2D"),&TileSet::tile_set_shape);
@@ -301,6 +333,7 @@ void TileSet::_bind_methods() {
ObjectTypeDB::bind_method(_MD("clear"),&TileSet::clear);
ObjectTypeDB::bind_method(_MD("get_last_unused_tile_id"),&TileSet::get_last_unused_tile_id);
ObjectTypeDB::bind_method(_MD("find_tile_by_name","name"),&TileSet::find_tile_by_name);
+ ObjectTypeDB::bind_method(_MD("get_tiles_ids", "name"), &TileSet::_get_tiles_ids);
}