1 /** 2 Tile library for tilemaps. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.tileset; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.resource; 24 import godot.texture; 25 import godot.shadermaterial; 26 import godot.shape2d; 27 import godot.navigationpolygon; 28 import godot.occluderpolygon2d; 29 import godot.reference; 30 /** 31 Tile library for tilemaps. 32 33 A TileSet is a library of tiles for a $(D TileMap). It contains a list of tiles, each consisting of a sprite and optional collision shapes. 34 Tiles are referenced by a unique integer ID. 35 */ 36 @GodotBaseClass struct TileSet 37 { 38 enum string _GODOT_internal_name = "TileSet"; 39 public: 40 @nogc nothrow: 41 union { godot_object _godot_object; Resource _GODOT_base; } 42 alias _GODOT_base this; 43 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 44 package(godot) __gshared bool _classBindingInitialized = false; 45 package(godot) static struct _classBinding 46 { 47 __gshared: 48 @GodotName("_is_tile_bound") GodotMethod!(bool, long, long) _isTileBound; 49 @GodotName("_forward_subtile_selection") GodotMethod!(Vector2, long, long, GodotObject, Vector2) _forwardSubtileSelection; 50 @GodotName("create_tile") GodotMethod!(void, long) createTile; 51 @GodotName("autotile_set_bitmask_mode") GodotMethod!(void, long, long) autotileSetBitmaskMode; 52 @GodotName("autotile_get_bitmask_mode") GodotMethod!(TileSet.BitmaskMode, long) autotileGetBitmaskMode; 53 @GodotName("autotile_set_size") GodotMethod!(void, long, Vector2) autotileSetSize; 54 @GodotName("autotile_get_size") GodotMethod!(Vector2, long) autotileGetSize; 55 @GodotName("tile_set_name") GodotMethod!(void, long, String) tileSetName; 56 @GodotName("tile_get_name") GodotMethod!(String, long) tileGetName; 57 @GodotName("tile_set_texture") GodotMethod!(void, long, Texture) tileSetTexture; 58 @GodotName("tile_get_texture") GodotMethod!(Texture, long) tileGetTexture; 59 @GodotName("tile_set_normal_map") GodotMethod!(void, long, Texture) tileSetNormalMap; 60 @GodotName("tile_get_normal_map") GodotMethod!(Texture, long) tileGetNormalMap; 61 @GodotName("tile_set_material") GodotMethod!(void, long, ShaderMaterial) tileSetMaterial; 62 @GodotName("tile_get_material") GodotMethod!(ShaderMaterial, long) tileGetMaterial; 63 @GodotName("tile_set_modulate") GodotMethod!(void, long, Color) tileSetModulate; 64 @GodotName("tile_get_modulate") GodotMethod!(Color, long) tileGetModulate; 65 @GodotName("tile_set_texture_offset") GodotMethod!(void, long, Vector2) tileSetTextureOffset; 66 @GodotName("tile_get_texture_offset") GodotMethod!(Vector2, long) tileGetTextureOffset; 67 @GodotName("tile_set_region") GodotMethod!(void, long, Rect2) tileSetRegion; 68 @GodotName("tile_get_region") GodotMethod!(Rect2, long) tileGetRegion; 69 @GodotName("tile_set_shape") GodotMethod!(void, long, long, Shape2D) tileSetShape; 70 @GodotName("tile_get_shape") GodotMethod!(Shape2D, long, long) tileGetShape; 71 @GodotName("tile_set_shape_offset") GodotMethod!(void, long, long, Vector2) tileSetShapeOffset; 72 @GodotName("tile_get_shape_offset") GodotMethod!(Vector2, long, long) tileGetShapeOffset; 73 @GodotName("tile_set_shape_transform") GodotMethod!(void, long, long, Transform2D) tileSetShapeTransform; 74 @GodotName("tile_get_shape_transform") GodotMethod!(Transform2D, long, long) tileGetShapeTransform; 75 @GodotName("tile_set_shape_one_way") GodotMethod!(void, long, long, bool) tileSetShapeOneWay; 76 @GodotName("tile_get_shape_one_way") GodotMethod!(bool, long, long) tileGetShapeOneWay; 77 @GodotName("tile_add_shape") GodotMethod!(void, long, Shape2D, Transform2D, bool, Vector2) tileAddShape; 78 @GodotName("tile_get_shape_count") GodotMethod!(long, long) tileGetShapeCount; 79 @GodotName("tile_set_shapes") GodotMethod!(void, long, Array) tileSetShapes; 80 @GodotName("tile_get_shapes") GodotMethod!(Array, long) tileGetShapes; 81 @GodotName("tile_set_tile_mode") GodotMethod!(void, long, long) tileSetTileMode; 82 @GodotName("tile_get_tile_mode") GodotMethod!(TileSet.TileMode, long) tileGetTileMode; 83 @GodotName("tile_set_navigation_polygon") GodotMethod!(void, long, NavigationPolygon) tileSetNavigationPolygon; 84 @GodotName("tile_get_navigation_polygon") GodotMethod!(NavigationPolygon, long) tileGetNavigationPolygon; 85 @GodotName("tile_set_navigation_polygon_offset") GodotMethod!(void, long, Vector2) tileSetNavigationPolygonOffset; 86 @GodotName("tile_get_navigation_polygon_offset") GodotMethod!(Vector2, long) tileGetNavigationPolygonOffset; 87 @GodotName("tile_set_light_occluder") GodotMethod!(void, long, OccluderPolygon2D) tileSetLightOccluder; 88 @GodotName("tile_get_light_occluder") GodotMethod!(OccluderPolygon2D, long) tileGetLightOccluder; 89 @GodotName("tile_set_occluder_offset") GodotMethod!(void, long, Vector2) tileSetOccluderOffset; 90 @GodotName("tile_get_occluder_offset") GodotMethod!(Vector2, long) tileGetOccluderOffset; 91 @GodotName("tile_set_z_index") GodotMethod!(void, long, long) tileSetZIndex; 92 @GodotName("tile_get_z_index") GodotMethod!(long, long) tileGetZIndex; 93 @GodotName("remove_tile") GodotMethod!(void, long) removeTile; 94 @GodotName("clear") GodotMethod!(void) clear; 95 @GodotName("get_last_unused_tile_id") GodotMethod!(long) getLastUnusedTileId; 96 @GodotName("find_tile_by_name") GodotMethod!(long, String) findTileByName; 97 @GodotName("get_tiles_ids") GodotMethod!(Array) getTilesIds; 98 } 99 bool opEquals(in TileSet other) const { return _godot_object.ptr is other._godot_object.ptr; } 100 TileSet opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 101 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 102 mixin baseCasts; 103 static TileSet _new() 104 { 105 static godot_class_constructor constructor; 106 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TileSet"); 107 if(constructor is null) return typeof(this).init; 108 return cast(TileSet)(constructor()); 109 } 110 @disable new(size_t s); 111 /// 112 enum TileMode : int 113 { 114 /** 115 116 */ 117 singleTile = 0, 118 /** 119 120 */ 121 autoTile = 1, 122 /** 123 124 */ 125 atlasTile = 2, 126 } 127 /// 128 enum AutotileBindings : int 129 { 130 /** 131 132 */ 133 bindTopleft = 1, 134 /** 135 136 */ 137 bindTop = 2, 138 /** 139 140 */ 141 bindTopright = 4, 142 /** 143 144 */ 145 bindLeft = 8, 146 /** 147 148 */ 149 bindRight = 32, 150 /** 151 152 */ 153 bindBottomleft = 64, 154 /** 155 156 */ 157 bindBottom = 128, 158 /** 159 160 */ 161 bindBottomright = 256, 162 } 163 /// 164 enum BitmaskMode : int 165 { 166 /** 167 168 */ 169 bitmask2x2 = 0, 170 /** 171 172 */ 173 bitmask3x3Minimal = 1, 174 /** 175 176 */ 177 bitmask3x3 = 2, 178 } 179 /// 180 enum Constants : int 181 { 182 singleTile = 0, 183 bitmask2x2 = 0, 184 bitmask3x3Minimal = 1, 185 bindTopleft = 1, 186 autoTile = 1, 187 bindTop = 2, 188 bitmask3x3 = 2, 189 atlasTile = 2, 190 bindTopright = 4, 191 bindLeft = 8, 192 bindRight = 32, 193 bindBottomleft = 64, 194 bindBottom = 128, 195 bindBottomright = 256, 196 } 197 /** 198 199 */ 200 bool _isTileBound(in long drawn_id, in long neighbor_id) 201 { 202 Array _GODOT_args = Array.empty_array; 203 _GODOT_args.append(drawn_id); 204 _GODOT_args.append(neighbor_id); 205 String _GODOT_method_name = String("_is_tile_bound"); 206 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 207 } 208 /** 209 210 */ 211 Vector2 _forwardSubtileSelection(in long autotile_id, in long bitmask, GodotObject tilemap, in Vector2 tile_location) 212 { 213 Array _GODOT_args = Array.empty_array; 214 _GODOT_args.append(autotile_id); 215 _GODOT_args.append(bitmask); 216 _GODOT_args.append(tilemap); 217 _GODOT_args.append(tile_location); 218 String _GODOT_method_name = String("_forward_subtile_selection"); 219 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Vector2); 220 } 221 /** 222 Creates a new tile with the given ID. 223 */ 224 void createTile(in long id) 225 { 226 checkClassBinding!(typeof(this))(); 227 ptrcall!(void)(_classBinding.createTile, _godot_object, id); 228 } 229 /** 230 231 */ 232 void autotileSetBitmaskMode(in long id, in long mode) 233 { 234 checkClassBinding!(typeof(this))(); 235 ptrcall!(void)(_classBinding.autotileSetBitmaskMode, _godot_object, id, mode); 236 } 237 /** 238 239 */ 240 TileSet.BitmaskMode autotileGetBitmaskMode(in long id) const 241 { 242 checkClassBinding!(typeof(this))(); 243 return ptrcall!(TileSet.BitmaskMode)(_classBinding.autotileGetBitmaskMode, _godot_object, id); 244 } 245 /** 246 247 */ 248 void autotileSetSize(in long id, in Vector2 size) 249 { 250 checkClassBinding!(typeof(this))(); 251 ptrcall!(void)(_classBinding.autotileSetSize, _godot_object, id, size); 252 } 253 /** 254 255 */ 256 Vector2 autotileGetSize(in long id) const 257 { 258 checkClassBinding!(typeof(this))(); 259 return ptrcall!(Vector2)(_classBinding.autotileGetSize, _godot_object, id); 260 } 261 /** 262 Sets the tile's name. 263 */ 264 void tileSetName(StringArg1)(in long id, in StringArg1 name) 265 { 266 checkClassBinding!(typeof(this))(); 267 ptrcall!(void)(_classBinding.tileSetName, _godot_object, id, name); 268 } 269 /** 270 Returns the tile's name. 271 */ 272 String tileGetName(in long id) const 273 { 274 checkClassBinding!(typeof(this))(); 275 return ptrcall!(String)(_classBinding.tileGetName, _godot_object, id); 276 } 277 /** 278 Sets the tile's texture. 279 */ 280 void tileSetTexture(in long id, Texture texture) 281 { 282 checkClassBinding!(typeof(this))(); 283 ptrcall!(void)(_classBinding.tileSetTexture, _godot_object, id, texture); 284 } 285 /** 286 Returns the tile's texture. 287 */ 288 Ref!Texture tileGetTexture(in long id) const 289 { 290 checkClassBinding!(typeof(this))(); 291 return ptrcall!(Texture)(_classBinding.tileGetTexture, _godot_object, id); 292 } 293 /** 294 Sets the tile's normal map texture. 295 */ 296 void tileSetNormalMap(in long id, Texture normal_map) 297 { 298 checkClassBinding!(typeof(this))(); 299 ptrcall!(void)(_classBinding.tileSetNormalMap, _godot_object, id, normal_map); 300 } 301 /** 302 Returns the tile's normal map texture. 303 */ 304 Ref!Texture tileGetNormalMap(in long id) const 305 { 306 checkClassBinding!(typeof(this))(); 307 return ptrcall!(Texture)(_classBinding.tileGetNormalMap, _godot_object, id); 308 } 309 /** 310 Sets the tile's material. 311 */ 312 void tileSetMaterial(in long id, ShaderMaterial material) 313 { 314 checkClassBinding!(typeof(this))(); 315 ptrcall!(void)(_classBinding.tileSetMaterial, _godot_object, id, material); 316 } 317 /** 318 Returns the tile's material. 319 */ 320 Ref!ShaderMaterial tileGetMaterial(in long id) const 321 { 322 checkClassBinding!(typeof(this))(); 323 return ptrcall!(ShaderMaterial)(_classBinding.tileGetMaterial, _godot_object, id); 324 } 325 /** 326 Sets the tile's modulation color. 327 */ 328 void tileSetModulate(in long id, in Color color) 329 { 330 checkClassBinding!(typeof(this))(); 331 ptrcall!(void)(_classBinding.tileSetModulate, _godot_object, id, color); 332 } 333 /** 334 Returns the tile's modulation color. 335 */ 336 Color tileGetModulate(in long id) const 337 { 338 checkClassBinding!(typeof(this))(); 339 return ptrcall!(Color)(_classBinding.tileGetModulate, _godot_object, id); 340 } 341 /** 342 Sets the tile's texture offset. 343 */ 344 void tileSetTextureOffset(in long id, in Vector2 texture_offset) 345 { 346 checkClassBinding!(typeof(this))(); 347 ptrcall!(void)(_classBinding.tileSetTextureOffset, _godot_object, id, texture_offset); 348 } 349 /** 350 Returns the texture offset of the tile. 351 */ 352 Vector2 tileGetTextureOffset(in long id) const 353 { 354 checkClassBinding!(typeof(this))(); 355 return ptrcall!(Vector2)(_classBinding.tileGetTextureOffset, _godot_object, id); 356 } 357 /** 358 Sets the tile's sub-region in the texture. This is common in texture atlases. 359 */ 360 void tileSetRegion(in long id, in Rect2 region) 361 { 362 checkClassBinding!(typeof(this))(); 363 ptrcall!(void)(_classBinding.tileSetRegion, _godot_object, id, region); 364 } 365 /** 366 Returns the tile sub-region in the texture. 367 */ 368 Rect2 tileGetRegion(in long id) const 369 { 370 checkClassBinding!(typeof(this))(); 371 return ptrcall!(Rect2)(_classBinding.tileGetRegion, _godot_object, id); 372 } 373 /** 374 Sets a shape for the tile, enabling collision. 375 */ 376 void tileSetShape(in long id, in long shape_id, Shape2D shape) 377 { 378 checkClassBinding!(typeof(this))(); 379 ptrcall!(void)(_classBinding.tileSetShape, _godot_object, id, shape_id, shape); 380 } 381 /** 382 Returns a tile's given shape. 383 */ 384 Ref!Shape2D tileGetShape(in long id, in long shape_id) const 385 { 386 checkClassBinding!(typeof(this))(); 387 return ptrcall!(Shape2D)(_classBinding.tileGetShape, _godot_object, id, shape_id); 388 } 389 /** 390 Sets the offset of a tile's shape. 391 */ 392 void tileSetShapeOffset(in long id, in long shape_id, in Vector2 shape_offset) 393 { 394 checkClassBinding!(typeof(this))(); 395 ptrcall!(void)(_classBinding.tileSetShapeOffset, _godot_object, id, shape_id, shape_offset); 396 } 397 /** 398 Returns the offset of a tile's shape. 399 */ 400 Vector2 tileGetShapeOffset(in long id, in long shape_id) const 401 { 402 checkClassBinding!(typeof(this))(); 403 return ptrcall!(Vector2)(_classBinding.tileGetShapeOffset, _godot_object, id, shape_id); 404 } 405 /** 406 Sets a $(D Transform2D) on a tile's shape. 407 */ 408 void tileSetShapeTransform(in long id, in long shape_id, in Transform2D shape_transform) 409 { 410 checkClassBinding!(typeof(this))(); 411 ptrcall!(void)(_classBinding.tileSetShapeTransform, _godot_object, id, shape_id, shape_transform); 412 } 413 /** 414 Returns the $(D Transform2D) of a tile's shape. 415 */ 416 Transform2D tileGetShapeTransform(in long id, in long shape_id) const 417 { 418 checkClassBinding!(typeof(this))(); 419 return ptrcall!(Transform2D)(_classBinding.tileGetShapeTransform, _godot_object, id, shape_id); 420 } 421 /** 422 Enables one-way collision on a tile's shape. 423 */ 424 void tileSetShapeOneWay(in long id, in long shape_id, in bool one_way) 425 { 426 checkClassBinding!(typeof(this))(); 427 ptrcall!(void)(_classBinding.tileSetShapeOneWay, _godot_object, id, shape_id, one_way); 428 } 429 /** 430 Returns the one-way collision value of a tile's shape. 431 */ 432 bool tileGetShapeOneWay(in long id, in long shape_id) const 433 { 434 checkClassBinding!(typeof(this))(); 435 return ptrcall!(bool)(_classBinding.tileGetShapeOneWay, _godot_object, id, shape_id); 436 } 437 /** 438 Adds a shape to the tile. 439 */ 440 void tileAddShape(in long id, Shape2D shape, in Transform2D shape_transform, in bool one_way = false, in Vector2 autotile_coord = Vector2(0, 0)) 441 { 442 checkClassBinding!(typeof(this))(); 443 ptrcall!(void)(_classBinding.tileAddShape, _godot_object, id, shape, shape_transform, one_way, autotile_coord); 444 } 445 /** 446 Returns the number of shapes assigned to a tile. 447 */ 448 long tileGetShapeCount(in long id) const 449 { 450 checkClassBinding!(typeof(this))(); 451 return ptrcall!(long)(_classBinding.tileGetShapeCount, _godot_object, id); 452 } 453 /** 454 Sets an array of shapes for the tile, enabling collision. 455 */ 456 void tileSetShapes(in long id, in Array shapes) 457 { 458 checkClassBinding!(typeof(this))(); 459 ptrcall!(void)(_classBinding.tileSetShapes, _godot_object, id, shapes); 460 } 461 /** 462 Returns an array of the tile's shapes. 463 */ 464 Array tileGetShapes(in long id) const 465 { 466 checkClassBinding!(typeof(this))(); 467 return ptrcall!(Array)(_classBinding.tileGetShapes, _godot_object, id); 468 } 469 /** 470 Sets the tile's $(D tilemode). 471 */ 472 void tileSetTileMode(in long id, in long tilemode) 473 { 474 checkClassBinding!(typeof(this))(); 475 ptrcall!(void)(_classBinding.tileSetTileMode, _godot_object, id, tilemode); 476 } 477 /** 478 Returns the tile's $(D tilemode). 479 */ 480 TileSet.TileMode tileGetTileMode(in long id) const 481 { 482 checkClassBinding!(typeof(this))(); 483 return ptrcall!(TileSet.TileMode)(_classBinding.tileGetTileMode, _godot_object, id); 484 } 485 /** 486 Sets the tile's navigation polygon. 487 */ 488 void tileSetNavigationPolygon(in long id, NavigationPolygon navigation_polygon) 489 { 490 checkClassBinding!(typeof(this))(); 491 ptrcall!(void)(_classBinding.tileSetNavigationPolygon, _godot_object, id, navigation_polygon); 492 } 493 /** 494 Returns the navigation polygon of the tile. 495 */ 496 Ref!NavigationPolygon tileGetNavigationPolygon(in long id) const 497 { 498 checkClassBinding!(typeof(this))(); 499 return ptrcall!(NavigationPolygon)(_classBinding.tileGetNavigationPolygon, _godot_object, id); 500 } 501 /** 502 Sets an offset for the tile's navigation polygon. 503 */ 504 void tileSetNavigationPolygonOffset(in long id, in Vector2 navigation_polygon_offset) 505 { 506 checkClassBinding!(typeof(this))(); 507 ptrcall!(void)(_classBinding.tileSetNavigationPolygonOffset, _godot_object, id, navigation_polygon_offset); 508 } 509 /** 510 Returns the offset of the tile's navigation polygon. 511 */ 512 Vector2 tileGetNavigationPolygonOffset(in long id) const 513 { 514 checkClassBinding!(typeof(this))(); 515 return ptrcall!(Vector2)(_classBinding.tileGetNavigationPolygonOffset, _godot_object, id); 516 } 517 /** 518 Sets a light occluder for the tile. 519 */ 520 void tileSetLightOccluder(in long id, OccluderPolygon2D light_occluder) 521 { 522 checkClassBinding!(typeof(this))(); 523 ptrcall!(void)(_classBinding.tileSetLightOccluder, _godot_object, id, light_occluder); 524 } 525 /** 526 Returns the tile's light occluder. 527 */ 528 Ref!OccluderPolygon2D tileGetLightOccluder(in long id) const 529 { 530 checkClassBinding!(typeof(this))(); 531 return ptrcall!(OccluderPolygon2D)(_classBinding.tileGetLightOccluder, _godot_object, id); 532 } 533 /** 534 Sets an offset for the tile's light occluder. 535 */ 536 void tileSetOccluderOffset(in long id, in Vector2 occluder_offset) 537 { 538 checkClassBinding!(typeof(this))(); 539 ptrcall!(void)(_classBinding.tileSetOccluderOffset, _godot_object, id, occluder_offset); 540 } 541 /** 542 Returns the offset of the tile's light occluder. 543 */ 544 Vector2 tileGetOccluderOffset(in long id) const 545 { 546 checkClassBinding!(typeof(this))(); 547 return ptrcall!(Vector2)(_classBinding.tileGetOccluderOffset, _godot_object, id); 548 } 549 /** 550 Sets the tile's drawing index. 551 */ 552 void tileSetZIndex(in long id, in long z_index) 553 { 554 checkClassBinding!(typeof(this))(); 555 ptrcall!(void)(_classBinding.tileSetZIndex, _godot_object, id, z_index); 556 } 557 /** 558 Returns the tile's z-index (drawing layer). 559 */ 560 long tileGetZIndex(in long id) const 561 { 562 checkClassBinding!(typeof(this))(); 563 return ptrcall!(long)(_classBinding.tileGetZIndex, _godot_object, id); 564 } 565 /** 566 Removes the given tile ID. 567 */ 568 void removeTile(in long id) 569 { 570 checkClassBinding!(typeof(this))(); 571 ptrcall!(void)(_classBinding.removeTile, _godot_object, id); 572 } 573 /** 574 Clears all tiles. 575 */ 576 void clear() 577 { 578 checkClassBinding!(typeof(this))(); 579 ptrcall!(void)(_classBinding.clear, _godot_object); 580 } 581 /** 582 Returns the ID following the last currently used ID, useful when creating a new tile. 583 */ 584 long getLastUnusedTileId() const 585 { 586 checkClassBinding!(typeof(this))(); 587 return ptrcall!(long)(_classBinding.getLastUnusedTileId, _godot_object); 588 } 589 /** 590 Returns the first tile matching the given name. 591 */ 592 long findTileByName(StringArg0)(in StringArg0 name) const 593 { 594 checkClassBinding!(typeof(this))(); 595 return ptrcall!(long)(_classBinding.findTileByName, _godot_object, name); 596 } 597 /** 598 Returns an array of all currently used tile IDs. 599 */ 600 Array getTilesIds() const 601 { 602 checkClassBinding!(typeof(this))(); 603 return ptrcall!(Array)(_classBinding.getTilesIds, _godot_object); 604 } 605 }