Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions scene/resources/tile_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
tile_set_navigation_polygon_offset(id, p_value);
else if (what == "z_index")
tile_set_z_index(id, p_value);
else if (what == "meta")
tile_set_meta(id, p_value);
else
return false;

Expand Down Expand Up @@ -249,6 +251,8 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = tile_get_navigation_polygon_offset(id);
else if (what == "z_index")
r_ret = tile_get_z_index(id);
else if (what == "meta")
r_ret = tile_get_meta(id);
else
return false;

Expand Down Expand Up @@ -295,6 +299,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"));
p_list->push_back(PropertyInfo(Variant::DICTIONARY, pre + "meta", PROPERTY_HINT_NONE, ""));
}
}

Expand Down Expand Up @@ -791,6 +796,30 @@ void TileSet::tile_set_z_index(int p_id, int p_z_index) {
emit_changed();
}

void TileSet::tile_set_meta(int p_id, const Dictionary &p_meta) {
ERR_FAIL_COND(!tile_map.has(p_id));
tile_map[p_id].meta = p_meta;
emit_changed();
_change_notify("");
}

Dictionary TileSet::tile_get_meta(int p_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), Dictionary());
return tile_map[p_id].meta;
}

void TileSet::_tile_set_meta(int p_id, const Variant &key, const Variant &value) {
ERR_FAIL_COND(!tile_map.has(p_id));
tile_map[p_id].meta[key] = value;
emit_changed();
_change_notify("");
}

Variant TileSet::_tile_get_meta(int p_id, const Variant &key) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), Dictionary());
return tile_map[p_id].meta[key];
}

void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {

ERR_FAIL_COND(!tile_map.has(p_id));
Expand Down Expand Up @@ -980,6 +1009,9 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("tile_get_occluder_offset", "id"), &TileSet::tile_get_occluder_offset);
ClassDB::bind_method(D_METHOD("tile_set_z_index", "id", "z_index"), &TileSet::tile_set_z_index);
ClassDB::bind_method(D_METHOD("tile_get_z_index", "id"), &TileSet::tile_get_z_index);
ClassDB::bind_method(D_METHOD("tile_get_meta_properties", "id"), &TileSet::tile_get_meta);
ClassDB::bind_method(D_METHOD("tile_get_meta_property", "id", "key"), &TileSet::_tile_get_meta);
ClassDB::bind_method(D_METHOD("tile_set_meta_property", "id", "key", "value"), &TileSet::_tile_set_meta);

ClassDB::bind_method(D_METHOD("remove_tile", "id"), &TileSet::remove_tile);
ClassDB::bind_method(D_METHOD("clear"), &TileSet::clear);
Expand Down
6 changes: 6 additions & 0 deletions scene/resources/tile_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class TileSet : public Resource {
Color modulate;
AutotileData autotile_data;
int z_index;
Dictionary meta;

// Default modulate for back-compat
explicit TileData() :
Expand Down Expand Up @@ -225,6 +226,11 @@ class TileSet : public Resource {
void tile_set_z_index(int p_id, int p_z_index);
int tile_get_z_index(int p_id) const;

void tile_set_meta(int p_id, const Dictionary &p_meta);
Dictionary tile_get_meta(int p_id) const;
void _tile_set_meta(int p_id, const Variant &key, const Variant &value);
Variant _tile_get_meta(int p_id, const Variant &key) const;

void remove_tile(int p_id);

bool has_tile(int p_id) const;
Expand Down