|
34 | 34 | #include "core/engine.h" |
35 | 35 | #include "core/math/geometry_2d.h" |
36 | 36 |
|
| 37 | +void TileProperties::_bind_methods() {} |
| 38 | + |
| 39 | +TileProperties::TileProperties() {} |
| 40 | + |
37 | 41 | bool TileSet::_set(const StringName &p_name, const Variant &p_value) { |
38 | 42 | String n = p_name; |
39 | 43 | int slash = n.find("/"); |
@@ -203,6 +207,14 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { |
203 | 207 | tile_set_navigation_polygon_offset(id, p_value); |
204 | 208 | } else if (what == "z_index") { |
205 | 209 | tile_set_z_index(id, p_value); |
| 210 | + } else if (what == "properties") { |
| 211 | + tile_set_properties(id, p_value); |
| 212 | + } else if (what == "properties_script") { |
| 213 | + Ref<TileProperties> properties = tile_get_properties(id); |
| 214 | + if (properties.is_valid()) { |
| 215 | + Ref<Script> script = p_value; |
| 216 | + properties->set_script(script.ptr()); |
| 217 | + } |
206 | 218 | } else { |
207 | 219 | return false; |
208 | 220 | } |
@@ -318,6 +330,13 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { |
318 | 330 | r_ret = tile_get_navigation_polygon_offset(id); |
319 | 331 | } else if (what == "z_index") { |
320 | 332 | r_ret = tile_get_z_index(id); |
| 333 | + } else if (what == "properties") { |
| 334 | + r_ret = tile_get_properties(id); |
| 335 | + } else if (what == "properties_script") { |
| 336 | + RES properties = tile_get_properties(id); |
| 337 | + if (properties.is_valid()) { |
| 338 | + r_ret = properties->get_script(); |
| 339 | + } |
321 | 340 | } else { |
322 | 341 | return false; |
323 | 342 | } |
@@ -367,17 +386,48 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { |
367 | 386 | p_list->push_back(PropertyInfo(Variant::FLOAT, pre + "shape_one_way_margin", PROPERTY_HINT_RANGE, "0,128,0.01", PROPERTY_USAGE_NOEDITOR)); |
368 | 387 | p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); |
369 | 388 | p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1", PROPERTY_USAGE_NOEDITOR)); |
| 389 | + p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "properties", PROPERTY_HINT_RESOURCE_TYPE, "TileProperties")); |
| 390 | + p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "properties_script", PROPERTY_HINT_RESOURCE_TYPE, "Script")); |
370 | 391 | } |
371 | 392 | } |
372 | 393 |
|
373 | 394 | void TileSet::create_tile(int p_id) { |
374 | 395 | ERR_FAIL_COND(tile_map.has(p_id)); |
375 | 396 | tile_map[p_id] = TileData(); |
376 | 397 | tile_map[p_id].autotile_data = AutotileData(); |
| 398 | + if (tile_properties_script.is_valid()) { |
| 399 | + tile_map[p_id].properties = Ref<TileProperties>(memnew(TileProperties)); |
| 400 | + tile_map[p_id].properties->set_script(tile_properties_script.ptr()); |
| 401 | + } |
377 | 402 | _change_notify(""); |
378 | 403 | emit_changed(); |
379 | 404 | } |
380 | 405 |
|
| 406 | +void TileSet::set_tile_properties_script(const Ref<Script> &p_script) { |
| 407 | + if (tile_properties_script == p_script) |
| 408 | + return; |
| 409 | + if (tile_properties_script.is_null()) { |
| 410 | + for (Map<int, TileSet::TileData>::Element *E = tile_map.front(); E; E = E->next()) { |
| 411 | + Ref<TileProperties> tp = memnew(TileProperties()); |
| 412 | + tp->set_script(p_script.ptr()); |
| 413 | + E->value().properties = tp; |
| 414 | + } |
| 415 | + } else { |
| 416 | + for (Map<int, TileSet::TileData>::Element *E = tile_map.front(); E; E = E->next()) { |
| 417 | + Ref<TileProperties> p = E->value().properties; |
| 418 | + ERR_CONTINUE(p.is_valid()); |
| 419 | + Ref<Script> s = p->get_script(); |
| 420 | + if (s != p_script) |
| 421 | + E->value().properties->set_script(p_script.ptr()); |
| 422 | + } |
| 423 | + } |
| 424 | + tile_properties_script = p_script; |
| 425 | +} |
| 426 | + |
| 427 | +Ref<Script> TileSet::get_tile_properties_script() const { |
| 428 | + return tile_properties_script; |
| 429 | +} |
| 430 | + |
381 | 431 | void TileSet::autotile_set_bitmask_mode(int p_id, BitmaskMode p_mode) { |
382 | 432 | ERR_FAIL_COND(!tile_map.has(p_id)); |
383 | 433 | tile_map[p_id].autotile_data.bitmask_mode = p_mode; |
@@ -907,6 +957,17 @@ Vector2 TileSet::tile_get_occluder_offset(int p_id) const { |
907 | 957 | return tile_map[p_id].occluder_offset; |
908 | 958 | } |
909 | 959 |
|
| 960 | +Ref<TileProperties> TileSet::tile_get_properties(int p_id) const { |
| 961 | + ERR_FAIL_COND_V(!tile_map.has(p_id), 0); |
| 962 | + return tile_map[p_id].properties; |
| 963 | +} |
| 964 | + |
| 965 | +void TileSet::tile_set_properties(int p_id, const Ref<TileProperties> &p_properties) { |
| 966 | + ERR_FAIL_COND(!tile_map.has(p_id)); |
| 967 | + tile_map[p_id].properties = p_properties; |
| 968 | + emit_changed(); |
| 969 | +} |
| 970 | + |
910 | 971 | void TileSet::tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes) { |
911 | 972 | ERR_FAIL_COND(!tile_map.has(p_id)); |
912 | 973 | tile_map[p_id].shapes_data = p_shapes; |
@@ -1049,6 +1110,14 @@ void TileSet::_decompose_convex_shape(Ref<Shape2D> p_shape) { |
1049 | 1110 | } |
1050 | 1111 | } |
1051 | 1112 |
|
| 1113 | +void TileSet::set_meta_properties(Dictionary p_dict) { |
| 1114 | + meta_properties = p_dict; |
| 1115 | +} |
| 1116 | + |
| 1117 | +Dictionary TileSet::get_meta_properties() const { |
| 1118 | + return meta_properties; |
| 1119 | +} |
| 1120 | + |
1052 | 1121 | void TileSet::get_tile_list(List<int> *p_tiles) const { |
1053 | 1122 | for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) { |
1054 | 1123 | p_tiles->push_back(E->key()); |
@@ -1164,12 +1233,24 @@ void TileSet::_bind_methods() { |
1164 | 1233 | ClassDB::bind_method(D_METHOD("tile_get_occluder_offset", "id"), &TileSet::tile_get_occluder_offset); |
1165 | 1234 | ClassDB::bind_method(D_METHOD("tile_set_z_index", "id", "z_index"), &TileSet::tile_set_z_index); |
1166 | 1235 | ClassDB::bind_method(D_METHOD("tile_get_z_index", "id"), &TileSet::tile_get_z_index); |
| 1236 | + ClassDB::bind_method(D_METHOD("tile_set_properties", "id", "properties"), &TileSet::tile_set_properties); |
| 1237 | + ClassDB::bind_method(D_METHOD("tile_get_properties", "id"), &TileSet::tile_get_properties); |
1167 | 1238 |
|
1168 | 1239 | ClassDB::bind_method(D_METHOD("remove_tile", "id"), &TileSet::remove_tile); |
1169 | 1240 | ClassDB::bind_method(D_METHOD("clear"), &TileSet::clear); |
1170 | 1241 | ClassDB::bind_method(D_METHOD("get_last_unused_tile_id"), &TileSet::get_last_unused_tile_id); |
1171 | 1242 | ClassDB::bind_method(D_METHOD("find_tile_by_name", "name"), &TileSet::find_tile_by_name); |
1172 | 1243 | ClassDB::bind_method(D_METHOD("get_tiles_ids"), &TileSet::_get_tiles_ids); |
| 1244 | + ClassDB::bind_method(D_METHOD("set_tile_properties_script", "script"), &TileSet::set_tile_properties_script); |
| 1245 | + ClassDB::bind_method(D_METHOD("get_tile_properties_script"), &TileSet::get_tile_properties_script); |
| 1246 | + |
| 1247 | + ClassDB::bind_method(D_METHOD("set_meta_properties", "dict"), &TileSet::set_meta_properties); |
| 1248 | + ClassDB::bind_method(D_METHOD("get_meta_properties"), &TileSet::get_meta_properties); |
| 1249 | + |
| 1250 | + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "meta_properties", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Script"), "set_meta_properties", "get_meta_properties"); |
| 1251 | + |
| 1252 | + ADD_GROUP("Tiles", "tiles_"); |
| 1253 | + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tiles_default_script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT, "Script"), "set_tile_properties_script", "get_tile_properties_script"); |
1173 | 1254 |
|
1174 | 1255 | BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_tile_bound", PropertyInfo(Variant::INT, "drawn_id"), PropertyInfo(Variant::INT, "neighbor_id"))); |
1175 | 1256 | BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_forward_subtile_selection", PropertyInfo(Variant::INT, "autotile_id"), PropertyInfo(Variant::INT, "bitmask"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "TileMap"), PropertyInfo(Variant::VECTOR2, "tile_location"))); |
|
0 commit comments