tile_set.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. /*************************************************************************/
  2. /* tile_set.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "tile_set.h"
  31. #include "core/array.h"
  32. bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
  33. String n = p_name;
  34. int slash = n.find("/");
  35. if (slash == -1)
  36. return false;
  37. int id = String::to_int(n.c_str(), slash);
  38. if (!tile_map.has(id))
  39. create_tile(id);
  40. String what = n.substr(slash + 1, n.length());
  41. if (what == "name")
  42. tile_set_name(id, p_value);
  43. else if (what == "texture")
  44. tile_set_texture(id, p_value);
  45. else if (what == "normal_map")
  46. tile_set_normal_map(id, p_value);
  47. else if (what == "tex_offset")
  48. tile_set_texture_offset(id, p_value);
  49. else if (what == "material")
  50. tile_set_material(id, p_value);
  51. else if (what == "modulate")
  52. tile_set_modulate(id, p_value);
  53. else if (what == "region")
  54. tile_set_region(id, p_value);
  55. else if (what == "tile_mode")
  56. tile_set_tile_mode(id, (TileMode)((int)p_value));
  57. else if (what == "is_autotile") {
  58. // backward compatibility for Godot 3.0.x
  59. // autotile used to be a bool, it's now an enum
  60. bool is_autotile = p_value;
  61. if (is_autotile)
  62. tile_set_tile_mode(id, AUTO_TILE);
  63. } else if (what.left(9) == "autotile/") {
  64. what = what.right(9);
  65. if (what == "bitmask_mode")
  66. autotile_set_bitmask_mode(id, (BitmaskMode)((int)p_value));
  67. else if (what == "icon_coordinate")
  68. autotile_set_icon_coordinate(id, p_value);
  69. else if (what == "tile_size")
  70. autotile_set_size(id, p_value);
  71. else if (what == "spacing")
  72. autotile_set_spacing(id, p_value);
  73. else if (what == "bitmask_flags") {
  74. tile_map[id].autotile_data.flags.clear();
  75. if (p_value.is_array()) {
  76. Array p = p_value;
  77. Vector2 last_coord;
  78. while (p.size() > 0) {
  79. if (p[0].get_type() == Variant::VECTOR2) {
  80. last_coord = p[0];
  81. } else if (p[0].get_type() == Variant::INT) {
  82. autotile_set_bitmask(id, last_coord, p[0]);
  83. }
  84. p.pop_front();
  85. }
  86. }
  87. } else if (what == "occluder_map") {
  88. tile_map[id].autotile_data.occluder_map.clear();
  89. Array p = p_value;
  90. Vector2 last_coord;
  91. while (p.size() > 0) {
  92. if (p[0].get_type() == Variant::VECTOR2) {
  93. last_coord = p[0];
  94. } else if (p[0].get_type() == Variant::OBJECT) {
  95. autotile_set_light_occluder(id, p[0], last_coord);
  96. }
  97. p.pop_front();
  98. }
  99. } else if (what == "navpoly_map") {
  100. tile_map[id].autotile_data.navpoly_map.clear();
  101. Array p = p_value;
  102. Vector2 last_coord;
  103. while (p.size() > 0) {
  104. if (p[0].get_type() == Variant::VECTOR2) {
  105. last_coord = p[0];
  106. } else if (p[0].get_type() == Variant::OBJECT) {
  107. autotile_set_navigation_polygon(id, p[0], last_coord);
  108. }
  109. p.pop_front();
  110. }
  111. } else if (what == "priority_map") {
  112. tile_map[id].autotile_data.priority_map.clear();
  113. Array p = p_value;
  114. Vector3 val;
  115. Vector2 v;
  116. int priority;
  117. while (p.size() > 0) {
  118. val = p[0];
  119. if (val.z > 1) {
  120. v.x = val.x;
  121. v.y = val.y;
  122. priority = (int)val.z;
  123. tile_map[id].autotile_data.priority_map[v] = priority;
  124. }
  125. p.pop_front();
  126. }
  127. } else if (what == "z_index_map") {
  128. tile_map[id].autotile_data.z_index_map.clear();
  129. Array p = p_value;
  130. Vector3 val;
  131. Vector2 v;
  132. int z_index;
  133. while (p.size() > 0) {
  134. val = p[0];
  135. if (val.z != 0) {
  136. v.x = val.x;
  137. v.y = val.y;
  138. z_index = (int)val.z;
  139. tile_map[id].autotile_data.z_index_map[v] = z_index;
  140. }
  141. p.pop_front();
  142. }
  143. }
  144. } else if (what == "shape")
  145. tile_set_shape(id, 0, p_value);
  146. else if (what == "shape_offset")
  147. tile_set_shape_offset(id, 0, p_value);
  148. else if (what == "shape_transform")
  149. tile_set_shape_transform(id, 0, p_value);
  150. else if (what == "shape_one_way")
  151. tile_set_shape_one_way(id, 0, p_value);
  152. else if (what == "shapes")
  153. _tile_set_shapes(id, p_value);
  154. else if (what == "occluder")
  155. tile_set_light_occluder(id, p_value);
  156. else if (what == "occluder_offset")
  157. tile_set_occluder_offset(id, p_value);
  158. else if (what == "navigation")
  159. tile_set_navigation_polygon(id, p_value);
  160. else if (what == "navigation_offset")
  161. tile_set_navigation_polygon_offset(id, p_value);
  162. else if (what == "z_index")
  163. tile_set_z_index(id, p_value);
  164. else
  165. return false;
  166. return true;
  167. }
  168. bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
  169. String n = p_name;
  170. int slash = n.find("/");
  171. if (slash == -1)
  172. return false;
  173. int id = String::to_int(n.c_str(), slash);
  174. ERR_FAIL_COND_V(!tile_map.has(id), false);
  175. String what = n.substr(slash + 1, n.length());
  176. if (what == "name")
  177. r_ret = tile_get_name(id);
  178. else if (what == "texture")
  179. r_ret = tile_get_texture(id);
  180. else if (what == "normal_map")
  181. r_ret = tile_get_normal_map(id);
  182. else if (what == "tex_offset")
  183. r_ret = tile_get_texture_offset(id);
  184. else if (what == "material")
  185. r_ret = tile_get_material(id);
  186. else if (what == "modulate")
  187. r_ret = tile_get_modulate(id);
  188. else if (what == "region")
  189. r_ret = tile_get_region(id);
  190. else if (what == "tile_mode")
  191. r_ret = tile_get_tile_mode(id);
  192. else if (what.left(9) == "autotile/") {
  193. what = what.right(9);
  194. if (what == "bitmask_mode")
  195. r_ret = autotile_get_bitmask_mode(id);
  196. else if (what == "icon_coordinate")
  197. r_ret = autotile_get_icon_coordinate(id);
  198. else if (what == "tile_size")
  199. r_ret = autotile_get_size(id);
  200. else if (what == "spacing")
  201. r_ret = autotile_get_spacing(id);
  202. else if (what == "bitmask_flags") {
  203. Array p;
  204. for (Map<Vector2, uint16_t>::Element *E = tile_map[id].autotile_data.flags.front(); E; E = E->next()) {
  205. p.push_back(E->key());
  206. p.push_back(E->value());
  207. }
  208. r_ret = p;
  209. } else if (what == "occluder_map") {
  210. Array p;
  211. for (Map<Vector2, Ref<OccluderPolygon2D> >::Element *E = tile_map[id].autotile_data.occluder_map.front(); E; E = E->next()) {
  212. p.push_back(E->key());
  213. p.push_back(E->value());
  214. }
  215. r_ret = p;
  216. } else if (what == "navpoly_map") {
  217. Array p;
  218. for (Map<Vector2, Ref<NavigationPolygon> >::Element *E = tile_map[id].autotile_data.navpoly_map.front(); E; E = E->next()) {
  219. p.push_back(E->key());
  220. p.push_back(E->value());
  221. }
  222. r_ret = p;
  223. } else if (what == "priority_map") {
  224. Array p;
  225. Vector3 v;
  226. for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.priority_map.front(); E; E = E->next()) {
  227. if (E->value() > 1) {
  228. //Don't save default value
  229. v.x = E->key().x;
  230. v.y = E->key().y;
  231. v.z = E->value();
  232. p.push_back(v);
  233. }
  234. }
  235. r_ret = p;
  236. } else if (what == "z_index_map") {
  237. Array p;
  238. Vector3 v;
  239. for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.z_index_map.front(); E; E = E->next()) {
  240. if (E->value() != 0) {
  241. //Don't save default value
  242. v.x = E->key().x;
  243. v.y = E->key().y;
  244. v.z = E->value();
  245. p.push_back(v);
  246. }
  247. }
  248. r_ret = p;
  249. }
  250. } else if (what == "shape")
  251. r_ret = tile_get_shape(id, 0);
  252. else if (what == "shape_offset")
  253. r_ret = tile_get_shape_offset(id, 0);
  254. else if (what == "shape_transform")
  255. r_ret = tile_get_shape_transform(id, 0);
  256. else if (what == "shape_one_way")
  257. r_ret = tile_get_shape_one_way(id, 0);
  258. else if (what == "shapes")
  259. r_ret = _tile_get_shapes(id);
  260. else if (what == "occluder")
  261. r_ret = tile_get_light_occluder(id);
  262. else if (what == "occluder_offset")
  263. r_ret = tile_get_occluder_offset(id);
  264. else if (what == "navigation")
  265. r_ret = tile_get_navigation_polygon(id);
  266. else if (what == "navigation_offset")
  267. r_ret = tile_get_navigation_polygon_offset(id);
  268. else if (what == "z_index")
  269. r_ret = tile_get_z_index(id);
  270. else
  271. return false;
  272. return true;
  273. }
  274. void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
  275. for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
  276. int id = E->key();
  277. String pre = itos(id) + "/";
  278. p_list->push_back(PropertyInfo(Variant::STRING, pre + "name"));
  279. p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
  280. p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
  281. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "tex_offset"));
  282. p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial"));
  283. p_list->push_back(PropertyInfo(Variant::COLOR, pre + "modulate"));
  284. p_list->push_back(PropertyInfo(Variant::RECT2, pre + "region"));
  285. p_list->push_back(PropertyInfo(Variant::INT, pre + "tile_mode", PROPERTY_HINT_ENUM, "SINGLE_TILE,AUTO_TILE,ATLAS_TILE"));
  286. if (tile_get_tile_mode(id) == AUTO_TILE) {
  287. p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/bitmask_mode", PROPERTY_HINT_ENUM, "2X2,3X3 (minimal),3X3", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  288. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/bitmask_flags", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  289. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  290. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  291. p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/spacing", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  292. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  293. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  294. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  295. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  296. } else if (tile_get_tile_mode(id) == ATLAS_TILE) {
  297. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  298. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  299. p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/spacing", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  300. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  301. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  302. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  303. }
  304. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "occluder_offset"));
  305. p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D"));
  306. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "navigation_offset"));
  307. p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "navigation", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon"));
  308. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
  309. p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
  310. p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_EDITOR));
  311. p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
  312. p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
  313. 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"));
  314. }
  315. }
  316. void TileSet::create_tile(int p_id) {
  317. ERR_FAIL_COND(tile_map.has(p_id));
  318. tile_map[p_id] = TileData();
  319. tile_map[p_id].autotile_data = AutotileData();
  320. _change_notify("");
  321. emit_changed();
  322. }
  323. void TileSet::autotile_set_bitmask_mode(int p_id, BitmaskMode p_mode) {
  324. ERR_FAIL_COND(!tile_map.has(p_id));
  325. tile_map[p_id].autotile_data.bitmask_mode = p_mode;
  326. _change_notify("");
  327. emit_changed();
  328. }
  329. TileSet::BitmaskMode TileSet::autotile_get_bitmask_mode(int p_id) const {
  330. ERR_FAIL_COND_V(!tile_map.has(p_id), BITMASK_2X2);
  331. return tile_map[p_id].autotile_data.bitmask_mode;
  332. }
  333. void TileSet::tile_set_texture(int p_id, const Ref<Texture> &p_texture) {
  334. ERR_FAIL_COND(!tile_map.has(p_id));
  335. tile_map[p_id].texture = p_texture;
  336. emit_changed();
  337. _change_notify("texture");
  338. }
  339. Ref<Texture> TileSet::tile_get_texture(int p_id) const {
  340. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture>());
  341. return tile_map[p_id].texture;
  342. }
  343. void TileSet::tile_set_normal_map(int p_id, const Ref<Texture> &p_normal_map) {
  344. ERR_FAIL_COND(!tile_map.has(p_id));
  345. tile_map[p_id].normal_map = p_normal_map;
  346. emit_changed();
  347. }
  348. Ref<Texture> TileSet::tile_get_normal_map(int p_id) const {
  349. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture>());
  350. return tile_map[p_id].normal_map;
  351. }
  352. void TileSet::tile_set_material(int p_id, const Ref<ShaderMaterial> &p_material) {
  353. ERR_FAIL_COND(!tile_map.has(p_id));
  354. tile_map[p_id].material = p_material;
  355. emit_changed();
  356. }
  357. Ref<ShaderMaterial> TileSet::tile_get_material(int p_id) const {
  358. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<ShaderMaterial>());
  359. return tile_map[p_id].material;
  360. }
  361. void TileSet::tile_set_modulate(int p_id, const Color &p_modulate) {
  362. ERR_FAIL_COND(!tile_map.has(p_id));
  363. tile_map[p_id].modulate = p_modulate;
  364. emit_changed();
  365. _change_notify("modulate");
  366. }
  367. Color TileSet::tile_get_modulate(int p_id) const {
  368. ERR_FAIL_COND_V(!tile_map.has(p_id), Color(1, 1, 1));
  369. return tile_map[p_id].modulate;
  370. }
  371. void TileSet::tile_set_texture_offset(int p_id, const Vector2 &p_offset) {
  372. ERR_FAIL_COND(!tile_map.has(p_id));
  373. tile_map[p_id].offset = p_offset;
  374. emit_changed();
  375. }
  376. Vector2 TileSet::tile_get_texture_offset(int p_id) const {
  377. ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
  378. return tile_map[p_id].offset;
  379. }
  380. void TileSet::tile_set_region(int p_id, const Rect2 &p_region) {
  381. ERR_FAIL_COND(!tile_map.has(p_id));
  382. tile_map[p_id].region = p_region;
  383. emit_changed();
  384. _change_notify("region");
  385. }
  386. Rect2 TileSet::tile_get_region(int p_id) const {
  387. ERR_FAIL_COND_V(!tile_map.has(p_id), Rect2());
  388. return tile_map[p_id].region;
  389. }
  390. void TileSet::tile_set_tile_mode(int p_id, TileMode p_tile_mode) {
  391. ERR_FAIL_COND(!tile_map.has(p_id));
  392. tile_map[p_id].tile_mode = p_tile_mode;
  393. emit_changed();
  394. _change_notify("tile_mode");
  395. }
  396. TileSet::TileMode TileSet::tile_get_tile_mode(int p_id) const {
  397. ERR_FAIL_COND_V(!tile_map.has(p_id), SINGLE_TILE);
  398. return tile_map[p_id].tile_mode;
  399. }
  400. void TileSet::autotile_set_icon_coordinate(int p_id, Vector2 coord) {
  401. ERR_FAIL_COND(!tile_map.has(p_id));
  402. tile_map[p_id].autotile_data.icon_coord = coord;
  403. emit_changed();
  404. }
  405. Vector2 TileSet::autotile_get_icon_coordinate(int p_id) const {
  406. ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
  407. return tile_map[p_id].autotile_data.icon_coord;
  408. }
  409. void TileSet::autotile_set_spacing(int p_id, int p_spacing) {
  410. ERR_FAIL_COND(!tile_map.has(p_id));
  411. ERR_FAIL_COND(p_spacing < 0);
  412. tile_map[p_id].autotile_data.spacing = p_spacing;
  413. emit_changed();
  414. }
  415. int TileSet::autotile_get_spacing(int p_id) const {
  416. ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
  417. return tile_map[p_id].autotile_data.spacing;
  418. }
  419. void TileSet::autotile_set_size(int p_id, Size2 p_size) {
  420. ERR_FAIL_COND(!tile_map.has(p_id));
  421. ERR_FAIL_COND(p_size.x <= 0 || p_size.y <= 0);
  422. tile_map[p_id].autotile_data.size = p_size;
  423. }
  424. Size2 TileSet::autotile_get_size(int p_id) const {
  425. ERR_FAIL_COND_V(!tile_map.has(p_id), Size2());
  426. return tile_map[p_id].autotile_data.size;
  427. }
  428. void TileSet::autotile_clear_bitmask_map(int p_id) {
  429. ERR_FAIL_COND(!tile_map.has(p_id));
  430. tile_map[p_id].autotile_data.flags.clear();
  431. }
  432. void TileSet::autotile_set_subtile_priority(int p_id, const Vector2 &p_coord, int p_priority) {
  433. ERR_FAIL_COND(!tile_map.has(p_id));
  434. ERR_FAIL_COND(p_priority <= 0);
  435. tile_map[p_id].autotile_data.priority_map[p_coord] = p_priority;
  436. }
  437. int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) {
  438. ERR_FAIL_COND_V(!tile_map.has(p_id), 1);
  439. if (tile_map[p_id].autotile_data.priority_map.has(p_coord)) {
  440. return tile_map[p_id].autotile_data.priority_map[p_coord];
  441. }
  442. //When not custom priority set return the default value
  443. return 1;
  444. }
  445. const Map<Vector2, int> &TileSet::autotile_get_priority_map(int p_id) const {
  446. static Map<Vector2, int> dummy;
  447. ERR_FAIL_COND_V(!tile_map.has(p_id), dummy);
  448. return tile_map[p_id].autotile_data.priority_map;
  449. }
  450. void TileSet::autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index) {
  451. ERR_FAIL_COND(!tile_map.has(p_id));
  452. tile_map[p_id].autotile_data.z_index_map[p_coord] = p_z_index;
  453. emit_changed();
  454. }
  455. int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) {
  456. ERR_FAIL_COND_V(!tile_map.has(p_id), 1);
  457. if (tile_map[p_id].autotile_data.z_index_map.has(p_coord)) {
  458. return tile_map[p_id].autotile_data.z_index_map[p_coord];
  459. }
  460. //When not custom z index set return the default value
  461. return 0;
  462. }
  463. const Map<Vector2, int> &TileSet::autotile_get_z_index_map(int p_id) const {
  464. static Map<Vector2, int> dummy;
  465. ERR_FAIL_COND_V(!tile_map.has(p_id), dummy);
  466. return tile_map[p_id].autotile_data.z_index_map;
  467. }
  468. void TileSet::autotile_set_bitmask(int p_id, Vector2 p_coord, uint16_t p_flag) {
  469. ERR_FAIL_COND(!tile_map.has(p_id));
  470. if (p_flag == 0) {
  471. if (tile_map[p_id].autotile_data.flags.has(p_coord))
  472. tile_map[p_id].autotile_data.flags.erase(p_coord);
  473. } else {
  474. tile_map[p_id].autotile_data.flags[p_coord] = p_flag;
  475. }
  476. }
  477. uint16_t TileSet::autotile_get_bitmask(int p_id, Vector2 p_coord) {
  478. ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
  479. if (!tile_map[p_id].autotile_data.flags.has(p_coord)) {
  480. return 0;
  481. }
  482. return tile_map[p_id].autotile_data.flags[p_coord];
  483. }
  484. const Map<Vector2, uint16_t> &TileSet::autotile_get_bitmask_map(int p_id) {
  485. static Map<Vector2, uint16_t> dummy;
  486. static Map<Vector2, uint16_t> dummy_atlas;
  487. ERR_FAIL_COND_V(!tile_map.has(p_id), dummy);
  488. if (tile_get_tile_mode(p_id) == ATLAS_TILE) {
  489. dummy_atlas = Map<Vector2, uint16_t>();
  490. Rect2 region = tile_get_region(p_id);
  491. Size2 size = autotile_get_size(p_id);
  492. float spacing = autotile_get_spacing(p_id);
  493. for (int x = 0; x < (region.size.x / (size.x + spacing)); x++) {
  494. for (int y = 0; y < (region.size.y / (size.y + spacing)); y++) {
  495. dummy_atlas.insert(Vector2(x, y), 0);
  496. }
  497. }
  498. return dummy_atlas;
  499. } else
  500. return tile_map[p_id].autotile_data.flags;
  501. }
  502. Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) {
  503. ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
  504. //First try to forward selection to script
  505. if (p_tilemap_node->get_class_name() == "TileMap") {
  506. if (get_script_instance() != NULL) {
  507. if (get_script_instance()->has_method("_forward_subtile_selection")) {
  508. Variant ret = get_script_instance()->call("_forward_subtile_selection", p_id, p_bitmask, p_tilemap_node, p_tile_location);
  509. if (ret.get_type() == Variant::VECTOR2) {
  510. return ret;
  511. }
  512. }
  513. }
  514. }
  515. List<Vector2> coords;
  516. uint16_t mask;
  517. for (Map<Vector2, uint16_t>::Element *E = tile_map[p_id].autotile_data.flags.front(); E; E = E->next()) {
  518. mask = E->get();
  519. if (tile_map[p_id].autotile_data.bitmask_mode == BITMASK_2X2) {
  520. mask &= (BIND_BOTTOMLEFT | BIND_BOTTOMRIGHT | BIND_TOPLEFT | BIND_TOPRIGHT);
  521. }
  522. if (mask == p_bitmask) {
  523. for (int i = 0; i < autotile_get_subtile_priority(p_id, E->key()); i++) {
  524. coords.push_back(E->key());
  525. }
  526. }
  527. }
  528. if (coords.size() == 0) {
  529. return autotile_get_icon_coordinate(p_id);
  530. } else {
  531. return coords[Math::random(0, (int)coords.size())];
  532. }
  533. }
  534. void TileSet::tile_set_name(int p_id, const String &p_name) {
  535. ERR_FAIL_COND(!tile_map.has(p_id));
  536. tile_map[p_id].name = p_name;
  537. emit_changed();
  538. _change_notify("name");
  539. }
  540. String TileSet::tile_get_name(int p_id) const {
  541. ERR_FAIL_COND_V(!tile_map.has(p_id), String());
  542. return tile_map[p_id].name;
  543. }
  544. void TileSet::tile_clear_shapes(int p_id) {
  545. tile_map[p_id].shapes_data.clear();
  546. }
  547. void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way, const Vector2 &p_autotile_coord) {
  548. ERR_FAIL_COND(!tile_map.has(p_id));
  549. ShapeData new_data = ShapeData();
  550. new_data.shape = p_shape;
  551. new_data.shape_transform = p_transform;
  552. new_data.one_way_collision = p_one_way;
  553. new_data.autotile_coord = p_autotile_coord;
  554. tile_map[p_id].shapes_data.push_back(new_data);
  555. }
  556. int TileSet::tile_get_shape_count(int p_id) const {
  557. ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
  558. return tile_map[p_id].shapes_data.size();
  559. }
  560. void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape) {
  561. ERR_FAIL_COND(!tile_map.has(p_id));
  562. if (tile_map[p_id].shapes_data.size() <= p_shape_id)
  563. tile_map[p_id].shapes_data.resize(p_shape_id + 1);
  564. tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape;
  565. emit_changed();
  566. }
  567. Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const {
  568. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Shape2D>());
  569. if (tile_map[p_id].shapes_data.size() > p_shape_id)
  570. return tile_map[p_id].shapes_data[p_shape_id].shape;
  571. return Ref<Shape2D>();
  572. }
  573. void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset) {
  574. ERR_FAIL_COND(!tile_map.has(p_id));
  575. if (tile_map[p_id].shapes_data.size() <= p_shape_id)
  576. tile_map[p_id].shapes_data.resize(p_shape_id + 1);
  577. tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset;
  578. emit_changed();
  579. }
  580. Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const {
  581. ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D());
  582. if (tile_map[p_id].shapes_data.size() > p_shape_id)
  583. return tile_map[p_id].shapes_data[p_shape_id].shape_transform;
  584. return Transform2D();
  585. }
  586. void TileSet::tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset) {
  587. Transform2D transform = tile_get_shape_transform(p_id, p_shape_id);
  588. transform.set_origin(p_offset);
  589. tile_set_shape_transform(p_id, p_shape_id, transform);
  590. }
  591. Vector2 TileSet::tile_get_shape_offset(int p_id, int p_shape_id) const {
  592. return tile_get_shape_transform(p_id, p_shape_id).get_origin();
  593. }
  594. void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_way) {
  595. ERR_FAIL_COND(!tile_map.has(p_id));
  596. if (tile_map[p_id].shapes_data.size() <= p_shape_id)
  597. tile_map[p_id].shapes_data.resize(p_shape_id + 1);
  598. tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way;
  599. emit_changed();
  600. }
  601. bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const {
  602. ERR_FAIL_COND_V(!tile_map.has(p_id), false);
  603. if (tile_map[p_id].shapes_data.size() > p_shape_id)
  604. return tile_map[p_id].shapes_data[p_shape_id].one_way_collision;
  605. return false;
  606. }
  607. void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) {
  608. ERR_FAIL_COND(!tile_map.has(p_id));
  609. tile_map[p_id].occluder = p_light_occluder;
  610. }
  611. Ref<OccluderPolygon2D> TileSet::tile_get_light_occluder(int p_id) const {
  612. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>());
  613. return tile_map[p_id].occluder;
  614. }
  615. void TileSet::autotile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder, const Vector2 &p_coord) {
  616. ERR_FAIL_COND(!tile_map.has(p_id));
  617. if (p_light_occluder.is_null()) {
  618. if (tile_map[p_id].autotile_data.occluder_map.has(p_coord)) {
  619. tile_map[p_id].autotile_data.occluder_map.erase(p_coord);
  620. }
  621. } else {
  622. tile_map[p_id].autotile_data.occluder_map[p_coord] = p_light_occluder;
  623. }
  624. }
  625. Ref<OccluderPolygon2D> TileSet::autotile_get_light_occluder(int p_id, const Vector2 &p_coord) const {
  626. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>());
  627. if (!tile_map[p_id].autotile_data.occluder_map.has(p_coord)) {
  628. return Ref<OccluderPolygon2D>();
  629. } else {
  630. return tile_map[p_id].autotile_data.occluder_map[p_coord];
  631. }
  632. }
  633. void TileSet::tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset) {
  634. ERR_FAIL_COND(!tile_map.has(p_id));
  635. tile_map[p_id].navigation_polygon_offset = p_offset;
  636. }
  637. Vector2 TileSet::tile_get_navigation_polygon_offset(int p_id) const {
  638. ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
  639. return tile_map[p_id].navigation_polygon_offset;
  640. }
  641. void TileSet::tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon) {
  642. ERR_FAIL_COND(!tile_map.has(p_id));
  643. tile_map[p_id].navigation_polygon = p_navigation_polygon;
  644. }
  645. Ref<NavigationPolygon> TileSet::tile_get_navigation_polygon(int p_id) const {
  646. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<NavigationPolygon>());
  647. return tile_map[p_id].navigation_polygon;
  648. }
  649. const Map<Vector2, Ref<OccluderPolygon2D> > &TileSet::autotile_get_light_oclusion_map(int p_id) const {
  650. static Map<Vector2, Ref<OccluderPolygon2D> > dummy;
  651. ERR_FAIL_COND_V(!tile_map.has(p_id), dummy);
  652. return tile_map[p_id].autotile_data.occluder_map;
  653. }
  654. void TileSet::autotile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon, const Vector2 &p_coord) {
  655. ERR_FAIL_COND(!tile_map.has(p_id));
  656. if (p_navigation_polygon.is_null()) {
  657. if (tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) {
  658. tile_map[p_id].autotile_data.navpoly_map.erase(p_coord);
  659. }
  660. } else {
  661. tile_map[p_id].autotile_data.navpoly_map[p_coord] = p_navigation_polygon;
  662. }
  663. }
  664. Ref<NavigationPolygon> TileSet::autotile_get_navigation_polygon(int p_id, const Vector2 &p_coord) const {
  665. ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<NavigationPolygon>());
  666. if (!tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) {
  667. return Ref<NavigationPolygon>();
  668. } else {
  669. return tile_map[p_id].autotile_data.navpoly_map[p_coord];
  670. }
  671. }
  672. const Map<Vector2, Ref<NavigationPolygon> > &TileSet::autotile_get_navigation_map(int p_id) const {
  673. static Map<Vector2, Ref<NavigationPolygon> > dummy;
  674. ERR_FAIL_COND_V(!tile_map.has(p_id), dummy);
  675. return tile_map[p_id].autotile_data.navpoly_map;
  676. }
  677. void TileSet::tile_set_occluder_offset(int p_id, const Vector2 &p_offset) {
  678. ERR_FAIL_COND(!tile_map.has(p_id));
  679. tile_map[p_id].occluder_offset = p_offset;
  680. }
  681. Vector2 TileSet::tile_get_occluder_offset(int p_id) const {
  682. ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
  683. return tile_map[p_id].occluder_offset;
  684. }
  685. void TileSet::tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes) {
  686. ERR_FAIL_COND(!tile_map.has(p_id));
  687. tile_map[p_id].shapes_data = p_shapes;
  688. emit_changed();
  689. }
  690. Vector<TileSet::ShapeData> TileSet::tile_get_shapes(int p_id) const {
  691. ERR_FAIL_COND_V(!tile_map.has(p_id), Vector<ShapeData>());
  692. return tile_map[p_id].shapes_data;
  693. }
  694. int TileSet::tile_get_z_index(int p_id) const {
  695. ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
  696. return tile_map[p_id].z_index;
  697. }
  698. void TileSet::tile_set_z_index(int p_id, int p_z_index) {
  699. ERR_FAIL_COND(!tile_map.has(p_id));
  700. tile_map[p_id].z_index = p_z_index;
  701. emit_changed();
  702. }
  703. void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
  704. ERR_FAIL_COND(!tile_map.has(p_id));
  705. Vector<ShapeData> shapes_data;
  706. Transform2D default_transform = tile_get_shape_transform(p_id, 0);
  707. bool default_one_way = tile_get_shape_one_way(p_id, 0);
  708. Vector2 default_autotile_coord = Vector2();
  709. for (int i = 0; i < p_shapes.size(); i++) {
  710. ShapeData s = ShapeData();
  711. if (p_shapes[i].get_type() == Variant::OBJECT) {
  712. Ref<Shape2D> shape = p_shapes[i];
  713. if (shape.is_null()) continue;
  714. s.shape = shape;
  715. s.shape_transform = default_transform;
  716. s.one_way_collision = default_one_way;
  717. s.autotile_coord = default_autotile_coord;
  718. } else if (p_shapes[i].get_type() == Variant::DICTIONARY) {
  719. Dictionary d = p_shapes[i];
  720. if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT)
  721. s.shape = d["shape"];
  722. else
  723. continue;
  724. if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D)
  725. s.shape_transform = d["shape_transform"];
  726. else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2)
  727. s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]);
  728. else
  729. s.shape_transform = default_transform;
  730. if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL)
  731. s.one_way_collision = d["one_way"];
  732. else
  733. s.one_way_collision = default_one_way;
  734. if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2)
  735. s.autotile_coord = d["autotile_coord"];
  736. else
  737. s.autotile_coord = default_autotile_coord;
  738. } else {
  739. ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes");
  740. ERR_CONTINUE(true);
  741. }
  742. shapes_data.push_back(s);
  743. }
  744. tile_map[p_id].shapes_data = shapes_data;
  745. }
  746. Array TileSet::_tile_get_shapes(int p_id) const {
  747. ERR_FAIL_COND_V(!tile_map.has(p_id), Array());
  748. Array arr;
  749. Vector<ShapeData> data = tile_map[p_id].shapes_data;
  750. for (int i = 0; i < data.size(); i++) {
  751. Dictionary shape_data;
  752. shape_data["shape"] = data[i].shape;
  753. shape_data["shape_transform"] = data[i].shape_transform;
  754. shape_data["one_way"] = data[i].one_way_collision;
  755. shape_data["autotile_coord"] = data[i].autotile_coord;
  756. arr.push_back(shape_data);
  757. }
  758. return arr;
  759. }
  760. Array TileSet::_get_tiles_ids() const {
  761. Array arr;
  762. for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
  763. arr.push_back(E->key());
  764. }
  765. return arr;
  766. }
  767. void TileSet::get_tile_list(List<int> *p_tiles) const {
  768. for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
  769. p_tiles->push_back(E->key());
  770. }
  771. }
  772. bool TileSet::has_tile(int p_id) const {
  773. return tile_map.has(p_id);
  774. }
  775. bool TileSet::is_tile_bound(int p_drawn_id, int p_neighbor_id) {
  776. if (p_drawn_id == p_neighbor_id) {
  777. return true;
  778. } else if (get_script_instance() != NULL) {
  779. if (get_script_instance()->has_method("_is_tile_bound")) {
  780. Variant ret = get_script_instance()->call("_is_tile_bound", p_drawn_id, p_neighbor_id);
  781. if (ret.get_type() == Variant::BOOL) {
  782. return ret;
  783. }
  784. }
  785. }
  786. return false;
  787. }
  788. void TileSet::remove_tile(int p_id) {
  789. ERR_FAIL_COND(!tile_map.has(p_id));
  790. tile_map.erase(p_id);
  791. _change_notify("");
  792. emit_changed();
  793. }
  794. int TileSet::get_last_unused_tile_id() const {
  795. if (tile_map.size())
  796. return tile_map.back()->key() + 1;
  797. else
  798. return 0;
  799. }
  800. int TileSet::find_tile_by_name(const String &p_name) const {
  801. for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
  802. if (p_name == E->get().name)
  803. return E->key();
  804. }
  805. return -1;
  806. }
  807. void TileSet::clear() {
  808. tile_map.clear();
  809. _change_notify("");
  810. emit_changed();
  811. }
  812. void TileSet::_bind_methods() {
  813. ClassDB::bind_method(D_METHOD("create_tile", "id"), &TileSet::create_tile);
  814. ClassDB::bind_method(D_METHOD("autotile_clear_bitmask_map", "id"), &TileSet::autotile_clear_bitmask_map);
  815. ClassDB::bind_method(D_METHOD("autotile_set_icon_coordinate", "id", "coord"), &TileSet::autotile_set_icon_coordinate);
  816. ClassDB::bind_method(D_METHOD("autotile_get_icon_coordinate", "id"), &TileSet::autotile_get_icon_coordinate);
  817. ClassDB::bind_method(D_METHOD("autotile_set_subtile_priority", "id", "coord", "priority"), &TileSet::autotile_set_subtile_priority);
  818. ClassDB::bind_method(D_METHOD("autotile_get_subtile_priority", "id", "coord"), &TileSet::autotile_get_subtile_priority);
  819. ClassDB::bind_method(D_METHOD("autotile_set_z_index", "id", "coord", "z_index"), &TileSet::autotile_set_z_index);
  820. ClassDB::bind_method(D_METHOD("autotile_get_z_index", "id", "coord"), &TileSet::autotile_get_z_index);
  821. ClassDB::bind_method(D_METHOD("autotile_set_light_occluder", "id", "light_occluder", "coord"), &TileSet::autotile_set_light_occluder);
  822. ClassDB::bind_method(D_METHOD("autotile_get_light_occluder", "id", "coord"), &TileSet::autotile_get_light_occluder);
  823. ClassDB::bind_method(D_METHOD("autotile_set_navigation_polygon", "id", "navigation_polygon", "coord"), &TileSet::autotile_set_navigation_polygon);
  824. ClassDB::bind_method(D_METHOD("autotile_get_navigation_polygon", "id", "coord"), &TileSet::autotile_get_navigation_polygon);
  825. ClassDB::bind_method(D_METHOD("autotile_set_bitmask", "id", "bitmask", "flag"), &TileSet::autotile_set_bitmask);
  826. ClassDB::bind_method(D_METHOD("autotile_get_bitmask", "id", "coord"), &TileSet::autotile_get_bitmask);
  827. ClassDB::bind_method(D_METHOD("autotile_set_bitmask_mode", "id", "mode"), &TileSet::autotile_set_bitmask_mode);
  828. ClassDB::bind_method(D_METHOD("autotile_get_bitmask_mode", "id"), &TileSet::autotile_get_bitmask_mode);
  829. ClassDB::bind_method(D_METHOD("autotile_set_spacing", "id", "spacing"), &TileSet::autotile_set_spacing);
  830. ClassDB::bind_method(D_METHOD("autotile_get_spacing", "id"), &TileSet::autotile_get_spacing);
  831. ClassDB::bind_method(D_METHOD("autotile_set_size", "id", "size"), &TileSet::autotile_set_size);
  832. ClassDB::bind_method(D_METHOD("autotile_get_size", "id"), &TileSet::autotile_get_size);
  833. ClassDB::bind_method(D_METHOD("tile_set_name", "id", "name"), &TileSet::tile_set_name);
  834. ClassDB::bind_method(D_METHOD("tile_get_name", "id"), &TileSet::tile_get_name);
  835. ClassDB::bind_method(D_METHOD("tile_set_texture", "id", "texture"), &TileSet::tile_set_texture);
  836. ClassDB::bind_method(D_METHOD("tile_get_texture", "id"), &TileSet::tile_get_texture);
  837. ClassDB::bind_method(D_METHOD("tile_set_normal_map", "id", "normal_map"), &TileSet::tile_set_normal_map);
  838. ClassDB::bind_method(D_METHOD("tile_get_normal_map", "id"), &TileSet::tile_get_normal_map);
  839. ClassDB::bind_method(D_METHOD("tile_set_material", "id", "material"), &TileSet::tile_set_material);
  840. ClassDB::bind_method(D_METHOD("tile_get_material", "id"), &TileSet::tile_get_material);
  841. ClassDB::bind_method(D_METHOD("tile_set_modulate", "id", "color"), &TileSet::tile_set_modulate);
  842. ClassDB::bind_method(D_METHOD("tile_get_modulate", "id"), &TileSet::tile_get_modulate);
  843. ClassDB::bind_method(D_METHOD("tile_set_texture_offset", "id", "texture_offset"), &TileSet::tile_set_texture_offset);
  844. ClassDB::bind_method(D_METHOD("tile_get_texture_offset", "id"), &TileSet::tile_get_texture_offset);
  845. ClassDB::bind_method(D_METHOD("tile_set_region", "id", "region"), &TileSet::tile_set_region);
  846. ClassDB::bind_method(D_METHOD("tile_get_region", "id"), &TileSet::tile_get_region);
  847. ClassDB::bind_method(D_METHOD("tile_set_shape", "id", "shape_id", "shape"), &TileSet::tile_set_shape);
  848. ClassDB::bind_method(D_METHOD("tile_get_shape", "id", "shape_id"), &TileSet::tile_get_shape);
  849. ClassDB::bind_method(D_METHOD("tile_set_shape_offset", "id", "shape_id", "shape_offset"), &TileSet::tile_set_shape_offset);
  850. ClassDB::bind_method(D_METHOD("tile_get_shape_offset", "id", "shape_id"), &TileSet::tile_get_shape_offset);
  851. ClassDB::bind_method(D_METHOD("tile_set_shape_transform", "id", "shape_id", "shape_transform"), &TileSet::tile_set_shape_transform);
  852. ClassDB::bind_method(D_METHOD("tile_get_shape_transform", "id", "shape_id"), &TileSet::tile_get_shape_transform);
  853. ClassDB::bind_method(D_METHOD("tile_set_shape_one_way", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way);
  854. ClassDB::bind_method(D_METHOD("tile_get_shape_one_way", "id", "shape_id"), &TileSet::tile_get_shape_one_way);
  855. ClassDB::bind_method(D_METHOD("tile_add_shape", "id", "shape", "shape_transform", "one_way", "autotile_coord"), &TileSet::tile_add_shape, DEFVAL(false), DEFVAL(Vector2()));
  856. ClassDB::bind_method(D_METHOD("tile_get_shape_count", "id"), &TileSet::tile_get_shape_count);
  857. ClassDB::bind_method(D_METHOD("tile_set_shapes", "id", "shapes"), &TileSet::_tile_set_shapes);
  858. ClassDB::bind_method(D_METHOD("tile_get_shapes", "id"), &TileSet::_tile_get_shapes);
  859. ClassDB::bind_method(D_METHOD("tile_set_tile_mode", "id", "tilemode"), &TileSet::tile_set_tile_mode);
  860. ClassDB::bind_method(D_METHOD("tile_get_tile_mode", "id"), &TileSet::tile_get_tile_mode);
  861. ClassDB::bind_method(D_METHOD("tile_set_navigation_polygon", "id", "navigation_polygon"), &TileSet::tile_set_navigation_polygon);
  862. ClassDB::bind_method(D_METHOD("tile_get_navigation_polygon", "id"), &TileSet::tile_get_navigation_polygon);
  863. ClassDB::bind_method(D_METHOD("tile_set_navigation_polygon_offset", "id", "navigation_polygon_offset"), &TileSet::tile_set_navigation_polygon_offset);
  864. ClassDB::bind_method(D_METHOD("tile_get_navigation_polygon_offset", "id"), &TileSet::tile_get_navigation_polygon_offset);
  865. ClassDB::bind_method(D_METHOD("tile_set_light_occluder", "id", "light_occluder"), &TileSet::tile_set_light_occluder);
  866. ClassDB::bind_method(D_METHOD("tile_get_light_occluder", "id"), &TileSet::tile_get_light_occluder);
  867. ClassDB::bind_method(D_METHOD("tile_set_occluder_offset", "id", "occluder_offset"), &TileSet::tile_set_occluder_offset);
  868. ClassDB::bind_method(D_METHOD("tile_get_occluder_offset", "id"), &TileSet::tile_get_occluder_offset);
  869. ClassDB::bind_method(D_METHOD("tile_set_z_index", "id", "z_index"), &TileSet::tile_set_z_index);
  870. ClassDB::bind_method(D_METHOD("tile_get_z_index", "id"), &TileSet::tile_get_z_index);
  871. ClassDB::bind_method(D_METHOD("remove_tile", "id"), &TileSet::remove_tile);
  872. ClassDB::bind_method(D_METHOD("clear"), &TileSet::clear);
  873. ClassDB::bind_method(D_METHOD("get_last_unused_tile_id"), &TileSet::get_last_unused_tile_id);
  874. ClassDB::bind_method(D_METHOD("find_tile_by_name", "name"), &TileSet::find_tile_by_name);
  875. ClassDB::bind_method(D_METHOD("get_tiles_ids"), &TileSet::_get_tiles_ids);
  876. BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_tile_bound", PropertyInfo(Variant::INT, "drawn_id"), PropertyInfo(Variant::INT, "neighbor_id")));
  877. 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")));
  878. BIND_ENUM_CONSTANT(BITMASK_2X2);
  879. BIND_ENUM_CONSTANT(BITMASK_3X3_MINIMAL);
  880. BIND_ENUM_CONSTANT(BITMASK_3X3);
  881. BIND_ENUM_CONSTANT(BIND_TOPLEFT);
  882. BIND_ENUM_CONSTANT(BIND_TOP);
  883. BIND_ENUM_CONSTANT(BIND_TOPRIGHT);
  884. BIND_ENUM_CONSTANT(BIND_LEFT);
  885. BIND_ENUM_CONSTANT(BIND_RIGHT);
  886. BIND_ENUM_CONSTANT(BIND_BOTTOMLEFT);
  887. BIND_ENUM_CONSTANT(BIND_BOTTOM);
  888. BIND_ENUM_CONSTANT(BIND_BOTTOMRIGHT);
  889. BIND_ENUM_CONSTANT(SINGLE_TILE);
  890. BIND_ENUM_CONSTANT(AUTO_TILE);
  891. BIND_ENUM_CONSTANT(ATLAS_TILE);
  892. }
  893. TileSet::TileSet() {
  894. }