1 /*************************************************************************/
2 /*  tile_set.h                                                           */
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 #ifndef TILE_SET_H
31 #define TILE_SET_H
32 
33 #include "resource.h"
34 #include "scene/2d/light_occluder_2d.h"
35 #include "scene/2d/navigation_polygon.h"
36 #include "scene/resources/shape_2d.h"
37 #include "scene/resources/texture.h"
38 
39 class TileSet : public Resource {
40 
41 	OBJ_TYPE(TileSet, Resource);
42 
43 	struct Data {
44 
45 		String name;
46 		Ref<Texture> texture;
47 		Vector2 offset;
48 		Vector2 shape_offset;
49 		Rect2i region;
50 		Vector<Ref<Shape2D> > shapes;
51 		Vector2 one_way_collision_direction;
52 		float one_way_collision_max_depth;
53 		Vector2 occluder_offset;
54 		Ref<OccluderPolygon2D> occluder;
55 		Vector2 navigation_polygon_offset;
56 		Ref<NavigationPolygon> navigation_polygon;
57 		Ref<CanvasItemMaterial> material;
58 		Color modulate;
59 
DataData60 		explicit Data() :
61 				one_way_collision_max_depth(0.0f),
62 				modulate(1, 1, 1) {}
63 	};
64 
65 	Map<int, Data> tile_map;
66 
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 
75 	static void _bind_methods();
76 
77 public:
78 	void create_tile(int p_id);
79 
80 	void tile_set_name(int p_id, const String &p_name);
81 	String tile_get_name(int p_id) const;
82 
83 	void tile_set_texture(int p_id, const Ref<Texture> &p_texture);
84 	Ref<Texture> tile_get_texture(int p_id) const;
85 
86 	void tile_set_texture_offset(int p_id, const Vector2 &p_offset);
87 	Vector2 tile_get_texture_offset(int p_id) const;
88 
89 	void tile_set_shape_offset(int p_id, const Vector2 &p_offset);
90 	Vector2 tile_get_shape_offset(int p_id) const;
91 
92 	void tile_set_region(int p_id, const Rect2 &p_region);
93 	Rect2 tile_get_region(int p_id) const;
94 
95 	void tile_set_shape(int p_id, const Ref<Shape2D> &p_shape);
96 	Ref<Shape2D> tile_get_shape(int p_id) const;
97 
98 	void tile_set_material(int p_id, const Ref<CanvasItemMaterial> &p_material);
99 	Ref<CanvasItemMaterial> tile_get_material(int p_id) const;
100 
101 	void tile_set_modulate(int p_id, const Color &p_color);
102 	Color tile_get_modulate(int p_id) const;
103 
104 	void tile_set_occluder_offset(int p_id, const Vector2 &p_offset);
105 	Vector2 tile_get_occluder_offset(int p_id) const;
106 
107 	void tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder);
108 	Ref<OccluderPolygon2D> tile_get_light_occluder(int p_id) const;
109 
110 	void tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset);
111 	Vector2 tile_get_navigation_polygon_offset(int p_id) const;
112 
113 	void tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon);
114 	Ref<NavigationPolygon> tile_get_navigation_polygon(int p_id) const;
115 
116 	void tile_set_shapes(int p_id, const Vector<Ref<Shape2D> > &p_shapes);
117 	Vector<Ref<Shape2D> > tile_get_shapes(int p_id) const;
118 
119 	void tile_set_one_way_collision_direction(int p_id, Vector2 p_direction);
120 	Vector2 tile_get_one_way_collision_direction(int p_id) const;
121 
122 	void tile_set_one_way_collision_max_depth(int p_id, float p_max_depth);
123 	float tile_get_one_way_collision_max_depth(int p_id) const;
124 
125 	void remove_tile(int p_id);
126 
127 	bool has_tile(int p_id) const;
128 
129 	int find_tile_by_name(const String &p_name) const;
130 	void get_tile_list(List<int> *p_tiles) const;
131 
132 	void clear();
133 
134 	int get_last_unused_tile_id() const;
135 
136 	TileSet();
137 };
138 
139 #endif // TILE_SET_H
140