tile_set.h
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-2016 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 
32 #include "resource.h"
33 #include "scene/resources/shape_2d.h"
34 #include "scene/resources/texture.h"
35 #include "scene/2d/light_occluder_2d.h"
36 #include "scene/2d/navigation_polygon.h"
37 
38 class TileSet : public Resource {
39 
40  OBJ_TYPE( TileSet, Resource );
41 
42  struct Data {
43 
44  String name;
45  Ref<Texture> texture;
46  Vector2 offset;
47  Vector2 shape_offset;
48  Rect2i region;
49  Vector<Ref<Shape2D> > shapes;
50  Vector2 occluder_offset;
51  Ref<OccluderPolygon2D> occluder;
52  Vector2 navigation_polygon_offset;
53  Ref<NavigationPolygon> navigation_polygon;
54  Ref<CanvasItemMaterial> material;
55  };
56 
57  Map<int,Data> tile_map;
58 
59 
60 protected:
61 
62  bool _set(const StringName& p_name, const Variant& p_value);
63  bool _get(const StringName& p_name,Variant &r_ret) const;
64  void _get_property_list( List<PropertyInfo> *p_list) const;
65  void _tile_set_shapes(int p_id,const Array& p_shapes);
66  Array _tile_get_shapes(int p_id) const;
67  Array _get_tiles_ids() const;
68 
69  static void _bind_methods();
70 public:
71 
72 
73 
74  void create_tile(int p_id);
75 
76  void tile_set_name(int p_id,const String &p_name);
77  String tile_get_name(int p_id) const;
78 
79  void tile_set_texture(int p_id, const Ref<Texture> &p_texture);
80  Ref<Texture> tile_get_texture(int p_id) const;
81 
82  void tile_set_texture_offset(int p_id,const Vector2 &p_offset);
83  Vector2 tile_get_texture_offset(int p_id) const;
84 
85  void tile_set_shape_offset(int p_id,const Vector2 &p_offset);
86  Vector2 tile_get_shape_offset(int p_id) const;
87 
88  void tile_set_region(int p_id,const Rect2 &p_region);
89  Rect2 tile_get_region(int p_id) const;
90 
91  void tile_set_shape(int p_id,const Ref<Shape2D> &p_shape);
92  Ref<Shape2D> tile_get_shape(int p_id) const;
93 
94  void tile_set_material(int p_id,const Ref<CanvasItemMaterial> &p_material);
95  Ref<CanvasItemMaterial> tile_get_material(int p_id) const;
96 
97  void tile_set_occluder_offset(int p_id,const Vector2& p_offset);
98  Vector2 tile_get_occluder_offset(int p_id) const;
99 
100  void tile_set_light_occluder(int p_id,const Ref<OccluderPolygon2D> &p_light_occluder);
101  Ref<OccluderPolygon2D> tile_get_light_occluder(int p_id) const;
102 
103  void tile_set_navigation_polygon_offset(int p_id,const Vector2& p_offset);
104  Vector2 tile_get_navigation_polygon_offset(int p_id) const;
105 
106  void tile_set_navigation_polygon(int p_id,const Ref<NavigationPolygon> &p_navigation_polygon);
107  Ref<NavigationPolygon> tile_get_navigation_polygon(int p_id) const;
108 
109  void tile_set_shapes(int p_id,const Vector<Ref<Shape2D> > &p_shapes);
110  Vector<Ref<Shape2D> > tile_get_shapes(int p_id) const;
111 
112  void remove_tile(int p_id);
113 
114  bool has_tile(int p_id) const;
115 
116  int find_tile_by_name(const String& p_name) const;
117  void get_tile_list(List<int> *p_tiles) const;
118 
119  void clear();
120 
121  int get_last_unused_tile_id() const;
122 
123  TileSet();
124 };
125 
126 #endif // TILE_SET_H
Definition: array.h:38
Definition: variant.h:74
Definition: math_2d.h:422
Definition: math_2d.h:204
Definition: string_db.h:48
Definition: resource.h:89
Definition: math_2d.h:65
Definition: ustring.h:64
Definition: vector.h:43
Definition: tile_set.h:38