summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/tile_set.cpp47
-rw-r--r--scene/resources/tile_set.h4
2 files changed, 51 insertions, 0 deletions
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index f852ecd7eb..88dbc67e01 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -129,6 +129,22 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
}
p.pop_front();
}
+ } else if (what == "z_index_map") {
+ tile_map[id].autotile_data.z_index_map.clear();
+ Array p = p_value;
+ Vector3 val;
+ Vector2 v;
+ int z_index;
+ while (p.size() > 0) {
+ val = p[0];
+ if (val.z > 1) {
+ v.x = val.x;
+ v.y = val.y;
+ z_index = (int)val.z;
+ tile_map[id].autotile_data.z_index_map[v] = z_index;
+ }
+ p.pop_front();
+ }
}
} else if (what == "shape")
tile_set_shape(id, 0, p_value);
@@ -228,6 +244,19 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
}
}
r_ret = p;
+ } else if (what == "z_index_map") {
+ Array p;
+ Vector3 v;
+ for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.z_index_map.front(); E; E = E->next()) {
+ if (E->value() != 0) {
+ //Don't save default value
+ v.x = E->key().x;
+ v.y = E->key().y;
+ v.z = E->value();
+ p.push_back(v);
+ }
+ }
+ r_ret = p;
}
} else if (what == "shape")
r_ret = tile_get_shape(id, 0);
@@ -278,6 +307,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
+ p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
} else if (tile_get_tile_mode(id) == ATLAS_TILE) {
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
@@ -476,6 +506,23 @@ int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) {
return 1;
}
+void TileSet::autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index) {
+
+ ERR_FAIL_COND(!tile_map.has(p_id));
+ tile_map[p_id].autotile_data.z_index_map[p_coord] = p_z_index;
+ emit_changed();
+}
+
+int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) {
+
+ ERR_FAIL_COND_V(!tile_map.has(p_id), 1);
+ if (tile_map[p_id].autotile_data.z_index_map.has(p_coord)) {
+ return tile_map[p_id].autotile_data.z_index_map[p_coord];
+ }
+ //When not custom z index set return the default value
+ return 0;
+}
+
const Map<Vector2, int> &TileSet::autotile_get_priority_map(int p_id) const {
static Map<Vector2, int> dummy;
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index 1802bf12b6..2ab771b1b0 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -87,6 +87,7 @@ public:
Map<Vector2, Ref<OccluderPolygon2D> > occluder_map;
Map<Vector2, Ref<NavigationPolygon> > navpoly_map;
Map<Vector2, int> priority_map;
+ Map<Vector2, int> z_index_map;
// Default size to prevent invalid value
explicit AutotileData() :
@@ -172,6 +173,9 @@ public:
int autotile_get_subtile_priority(int p_id, const Vector2 &p_coord);
const Map<Vector2, int> &autotile_get_priority_map(int p_id) const;
+ void autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index);
+ int autotile_get_z_index(int p_id, const Vector2 &p_coord);
+
void autotile_set_bitmask(int p_id, Vector2 p_coord, uint16_t p_flag);
uint16_t autotile_get_bitmask(int p_id, Vector2 p_coord);
const Map<Vector2, uint16_t> &autotile_get_bitmask_map(int p_id);