tile_set.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*************************************************************************/
  2. /* tile_set.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. #ifndef TILE_SET_H
  31. #define TILE_SET_H
  32. #include "resource.h"
  33. #include "scene/2d/light_occluder_2d.h"
  34. #include "scene/2d/navigation_polygon.h"
  35. #include "scene/resources/shape_2d.h"
  36. #include "scene/resources/texture.h"
  37. class TileSet : public Resource {
  38. GDCLASS(TileSet, Resource);
  39. public:
  40. struct ShapeData {
  41. Ref<Shape2D> shape;
  42. Transform2D shape_transform;
  43. bool one_way_collision;
  44. ShapeData() {
  45. one_way_collision = false;
  46. }
  47. };
  48. private:
  49. struct TileData {
  50. String name;
  51. Ref<Texture> texture;
  52. Ref<Texture> normal_map;
  53. Vector2 offset;
  54. Rect2i region;
  55. Vector<ShapeData> shapes_data;
  56. Vector2 occluder_offset;
  57. Ref<OccluderPolygon2D> occluder;
  58. Vector2 navigation_polygon_offset;
  59. Ref<NavigationPolygon> navigation_polygon;
  60. Ref<ShaderMaterial> material;
  61. Color modulate;
  62. // Default modulate for back-compat
  63. explicit TileData()
  64. : modulate(1, 1, 1) {}
  65. };
  66. Map<int, TileData> tile_map;
  67. protected:
  68. bool _set(const StringName &p_name, const Variant &p_value);
  69. bool _get(const StringName &p_name, Variant &r_ret) const;
  70. void _get_property_list(List<PropertyInfo> *p_list) const;
  71. void _tile_set_shapes(int p_id, const Array &p_shapes);
  72. Array _tile_get_shapes(int p_id) const;
  73. Array _get_tiles_ids() const;
  74. static void _bind_methods();
  75. public:
  76. void create_tile(int p_id);
  77. void tile_set_name(int p_id, const String &p_name);
  78. String tile_get_name(int p_id) const;
  79. void tile_set_texture(int p_id, const Ref<Texture> &p_texture);
  80. Ref<Texture> tile_get_texture(int p_id) const;
  81. void tile_set_normal_map(int p_id, const Ref<Texture> &p_normal_map);
  82. Ref<Texture> tile_get_normal_map(int p_id) const;
  83. void tile_set_texture_offset(int p_id, const Vector2 &p_offset);
  84. Vector2 tile_get_texture_offset(int p_id) const;
  85. void tile_set_region(int p_id, const Rect2 &p_region);
  86. Rect2 tile_get_region(int p_id) const;
  87. void tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape);
  88. Ref<Shape2D> tile_get_shape(int p_id, int p_shape_id) const;
  89. void tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset);
  90. Transform2D tile_get_shape_transform(int p_id, int p_shape_id) const;
  91. void tile_set_shape_one_way(int p_id, int p_shape_id, bool p_one_way);
  92. bool tile_get_shape_one_way(int p_id, int p_shape_id) const;
  93. void tile_clear_shapes(int p_id);
  94. void tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way = false);
  95. int tile_get_shape_count(int p_id) const;
  96. void tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes);
  97. Vector<ShapeData> tile_get_shapes(int p_id) const;
  98. void tile_set_material(int p_id, const Ref<ShaderMaterial> &p_material);
  99. Ref<ShaderMaterial> tile_get_material(int p_id) const;
  100. void tile_set_modulate(int p_id, const Color &p_modulate);
  101. Color tile_get_modulate(int p_id) const;
  102. void tile_set_occluder_offset(int p_id, const Vector2 &p_offset);
  103. Vector2 tile_get_occluder_offset(int p_id) const;
  104. void tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder);
  105. Ref<OccluderPolygon2D> tile_get_light_occluder(int p_id) const;
  106. void tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset);
  107. Vector2 tile_get_navigation_polygon_offset(int p_id) const;
  108. void tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon);
  109. Ref<NavigationPolygon> tile_get_navigation_polygon(int p_id) const;
  110. void remove_tile(int p_id);
  111. bool has_tile(int p_id) const;
  112. int find_tile_by_name(const String &p_name) const;
  113. void get_tile_list(List<int> *p_tiles) const;
  114. void clear();
  115. int get_last_unused_tile_id() const;
  116. TileSet();
  117. };
  118. #endif // TILE_SET_H