tile_set.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* tile_set.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef TILE_SET_H
  30. #define TILE_SET_H
  31. #include "resource.h"
  32. #include "scene/resources/shape_2d.h"
  33. #include "scene/resources/texture.h"
  34. class TileSet : public Resource {
  35. OBJ_TYPE( TileSet, Resource );
  36. struct Data {
  37. String name;
  38. Ref<Texture> texture;
  39. Vector2 offset;
  40. Vector2 shape_offset;
  41. Rect2i region;
  42. Vector<Ref<Shape2D> > shapes;
  43. };
  44. Map<int,Data> tile_map;
  45. protected:
  46. bool _set(const StringName& p_name, const Variant& p_value);
  47. bool _get(const StringName& p_name,Variant &r_ret) const;
  48. void _get_property_list( List<PropertyInfo> *p_list) const;
  49. void _tile_set_shapes(int p_id,const Array& p_shapes);
  50. Array _tile_get_shapes(int p_id) const;
  51. Array _get_tiles_ids() const;
  52. static void _bind_methods();
  53. public:
  54. void create_tile(int p_id);
  55. void tile_set_name(int p_id,const String &p_name);
  56. String tile_get_name(int p_id) const;
  57. void tile_set_texture(int p_id, const Ref<Texture> &p_texture);
  58. Ref<Texture> tile_get_texture(int p_id) const;
  59. void tile_set_texture_offset(int p_id,const Vector2 &p_offset);
  60. Vector2 tile_get_texture_offset(int p_id) const;
  61. void tile_set_shape_offset(int p_id,const Vector2 &p_offset);
  62. Vector2 tile_get_shape_offset(int p_id) const;
  63. void tile_set_region(int p_id,const Rect2 &p_region);
  64. Rect2 tile_get_region(int p_id) const;
  65. void tile_set_shape(int p_id,const Ref<Shape2D> &p_shape);
  66. Ref<Shape2D> tile_get_shape(int p_id) const;
  67. void tile_set_shapes(int p_id,const Vector<Ref<Shape2D> > &p_shapes);
  68. Vector<Ref<Shape2D> > tile_get_shapes(int p_id) const;
  69. void remove_tile(int p_id);
  70. bool has_tile(int p_id) const;
  71. int find_tile_by_name(const String& p_name) const;
  72. void get_tile_list(List<int> *p_tiles) const;
  73. void clear();
  74. int get_last_unused_tile_id() const;
  75. TileSet();
  76. };
  77. #endif // TILE_SET_H